标签:algorithm 方案 getch == efi 超过 复杂 osi 颜色
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
using namespace std;
inline int read(){
int x=0,o=1;char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')o=-1,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*o;
}
const int N=2000005;
const int M=10005;
int n,m,k,tot;ll ans;
int p[N],h[N],pos[N];
vector<int>q[M];
int main(){
n=read();k=read();m=read();
for(int i=1;i<=n;++i){
p[i]=read();h[i]=read();
q[p[i]].push_back(i);
if(h[i]<=m)pos[++tot]=i;
}
for(int i=1;i<=n;++i){
if(h[i]<=m){
int l=0,r=q[p[i]].size()-1,mid,cnt=-1;
while(l<=r){
mid=(l+r)>>1;
if(q[p[i]][mid]>=i){
cnt=mid;
r=mid-1;
}
else l=mid+1;
}
if(cnt==-1)continue;
ans+=q[p[i]].size()-(cnt+1);
}
else{
int l=1,r=tot,mid,cnt=-1;
while(l<=r){
mid=(l+r)>>1;
if(pos[mid]>=i){
cnt=pos[mid];
r=mid-1;
}
else l=mid+1;
}
if(cnt==-1)continue;
l=0,r=q[p[i]].size()-1;int midd,cntt=-1;
while(l<=r){
midd=(l+r)>>1;
if(q[p[i]][midd]>=cnt){
cntt=midd;
r=midd-1;
}
else l=midd+1;
}
if(cntt==-1)continue;
ans=ans+q[p[i]].size()-cntt;
}
}
printf("%lld\n",ans);
return 0;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
using namespace std;
inline int read(){
int x=0,o=1;char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')o=-1,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*o;
}
const int N=2000005;
ll ans;
int a[N],b[N],sum[N];
int main(){
int n=read(),k=read(),p=read();
for(int i=1;i<=n;++i)a[i]=read()+1,b[i]=read();
int pos=0;
for(int i=1;i<=n;++i){
if(b[i]<=p){
for(int j=pos+1;j<=i;++j)++sum[a[j]];
pos=i;ans+=sum[a[i]]-1;
}
else ans+=sum[a[i]];
}
printf("%lld\n",ans);
return 0;
}
标签:algorithm 方案 getch == efi 超过 复杂 osi 颜色
原文地址:https://www.cnblogs.com/PPXppx/p/11620598.html