标签:center mem maps order ons cst and bool lang
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 44309 | Accepted: 19236 |
Description
Input
Output
Sample Input
5 1 1 5 1 7 1 3 3 5 5
Sample Output
1 2 1 1 0
【分析】很常规的做法,先排序后树状数组统计。
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <string> #include <map> #include <stack> #include <queue> #include <vector> #define inf 2e9 #define met(a,b) memset(a,b,sizeof a) typedef long long ll; using namespace std; const int N = 2e5+5; const int M = 4e5+5; int n,m,tot=0,cnt=0; int head[N],ans[N]; int tree[33000]; struct man{ int x,y; bool operator< (const man &it)const{ if(x==it.x)return y<it.y; return x<it.x; } }a[N]; void add(int k,int num){ while(k<=32001){ tree[k]+=num; k+=k&(-k); } } int Sum(int k){ int sum=0; while(k>0){ sum+=tree[k]; k-=k&(-k); } return sum; } int main() { met(tree,0);met(head,-1);met(ans,0); scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d",&a[i].x,&a[i].y); a[i].x++;a[i].y++; } sort(a+1,a+1+n); for(int i=1;i<=n;i++){ int sum=Sum(a[i].y); ans[sum]++; add(a[i].y,1); } for(int i=0;i<n;i++)printf("%d\n",ans[i]); return 0; }
标签:center mem maps order ons cst and bool lang
原文地址:http://www.cnblogs.com/jianrenfang/p/6091160.html