标签:
// 树状数组
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <sstream>
#include <cstdlib>
#include <complex>
#include <cstring>
#include <iostream>
#include <algorithm>
#define REP(i,N) for (int i = 0;i < (N);i++)
#define REP_1(i,N) for (int i = 1;i < (N);i++)
#define REP_2(i,be,en) for (int i = (be);i < (en);i++)
#define DWN(i,N) for (int i = (N);i >= 0;i--)
#define DWN_1(i,N) for (int i = (N);i >= 1;i--)
#define DWN_2(i,en,be) for (int i = (en);i >= (be);i--)
#define FR(N) freopen((N),"r",stdin)
#define FW(N) freopen((N),"w",stdout)
#define MAXN 32010
#define GETS(ch) fgets((ch),MAXN,stdin)
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef map<int,LL> MINT;
typedef map<char,int> MCH;
typedef map<string,int> MSTR;
typedef vector<int> VINT;
typedef set<LL> SINT;
typedef pair<int,int> PINT;
LL read(){
LL ret=0,f=1;
char x=getchar();
while(!(x>=‘0‘ && x<=‘9‘)){if(x==‘-‘)f=-1;x=getchar();}
while(x>=‘0‘ && x<=‘9‘) ret=ret*10+x-‘0‘, x=getchar();
return ret*f;
}
int c[MAXN];
int lowbit(int x) {
return x & (-x);
}
int getSum(int pos) {
int sum = 0;
while (pos > 0) {
sum += c[pos];
pos -= lowbit(pos);
}
return sum;
}
void Updata(int pos) {
while (pos < MAXN) {
c[pos]++;
pos += lowbit(pos);
}
}
int main () {
int N;
FR("1.txt");
cin >> N;
int ans[MAXN];
memset(ans,0,sizeof(ans));
REP(i,N) {
int x,y;
scanf("%d%d",&x,&y);
ans[getSum(++x)]++;
Updata(x);
}
REP(i,N) {
cout << ans[i] << endl;
}
}
// 线段树
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <sstream>
#include <cstdlib>
#include <complex>
#include <cstring>
#include <iostream>
#include <algorithm>
#define REP(i,N) for (int i = 0;i < (N);i++)
#define REP_1(i,N) for (int i = 1;i < (N);i++)
#define REP_2(i,be,en) for (int i = (be);i < (en);i++)
#define DWN(i,N) for (int i = (N);i >= 0;i--)
#define DWN_1(i,N) for (int i = (N);i >= 1;i--)
#define DWN_2(i,en,be) for (int i = (en);i >= (be);i--)
#define FR(N) freopen((N),"r",stdin)
#define FW(N) freopen((N),"w",stdout)
#define MAXN 32010
#define GETS(ch) fgets((ch),MAXN,stdin)
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef map<int,LL> MINT;
typedef map<char,int> MCH;
typedef map<string,int> MSTR;
typedef vector<int> VINT;
typedef set<LL> SINT;
typedef pair<int,int> PINT;
LL read(){
LL ret=0,f=1;
char x=getchar();
while(!(x>=‘0‘ && x<=‘9‘)){if(x==‘-‘)f=-1;x=getchar();}
while(x>=‘0‘ && x<=‘9‘) ret=ret*10+x-‘0‘, x=getchar();
return ret*f;
}
int c[MAXN << 2];
int Query(int node,int left,int right,int L,int R) {
if (L <= left && right <= R) {
return c[node];
}
int ans = 0;
int mid = (left + right) >> 1;
if (L <= mid) ans += Query(node << 1,left,mid,L,R);
if (R > mid) ans += Query(node << 1 | 1,mid + 1,right,L,R);
return ans;
}
void Updata(int node,int left,int right,int pos) {
if (left == right) {
c[node]++;
return;
}
int mid = (left + right) >> 1;
if (pos <= mid) Updata(node << 1,left,mid,pos);
if (pos > mid) Updata(node << 1 | 1,mid + 1,right,pos);
c[node] = c[node << 1] + c[node << 1 | 1];
}
int main() {
int N;
//FR("1.txt");
cin >> N;
int ans[MAXN];
REP(i,N) {
int x,y;
cin >> x >> y;
ans[Query(1,1,MAXN,1,++x)]++;
Updata(1,1,MAXN,x);
}
REP(i,N) {
cout << ans[i] << endl;
}
}
标签:
原文地址:http://www.cnblogs.com/xiaoshanshan/p/4358977.html