#10114. 「一本通 4.1 例 2」数星星 Stars
#10114. 「一本通 4.1 例 2」数星星 Stars
题意
给定
思路
这不就是裸的树状数组吗?
题目都按顺序(y的增序)。。。
#include<bits/stdc++.h>
using namespace std;
inline int read(){
char ch=getchar();int res=0,f=1;
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar();
return res*f;
}
inline void write(int x){
if(x<0) putchar('-'),x=-x;
if(x<10) putchar(x+'0');
else{
write(x/10);
putchar(x%10+'0');
}
}
int n,x,y,ans[1500010];
int a[1500010];
void add(int x,int y){
for(int i=x;i<=1500000;i+=i&(-i)){
a[i]+=y;
}
}
int getsum(int x){
int sum=0;
for(int i=x;i;i-=i&(-i)){
sum+=a[i];
}
return sum;
}
int main(){
n=read();
for(int i=1;i<=n;i++){
x=read();y=read();
int t=getsum(x+1);
ans[t]++;
add(x+1,1);
}
for(int i=0;i<n;i++){
write(ans[i]);putchar('\n');
}
return 0;
}