标签:targe scanf nbsp wrap script mono namespace lang sub
Description
Input
Output
Sample Input
3 1 2 0 3 3 4 0
Sample Output
1 0 0
Hint
Source
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <bitset> #include <list> #include <algorithm> #include <climits> using namespace std; #define lson 2*i #define rson 2*i+1 #define LS l,mid,lson #define RS mid+1,r,rson #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define LL long long #define N 200005 #define INF 0x3f3f3f3f #define EXP 1e-8 #define lowbit(x) (x&-x) const int mod = 1e9+7; struct node { int l,r,id; } a[N]; int n,maxn,c[N]; int cmp(node a,node b) { if(a.r!=b.r) return a.r>b.r; return a.l<b.l; } int sum(int x) { int ret = 0; while(x>0) { ret+=c[x]; x-=lowbit(x); } return ret; } void add(int x,int d) { while(x<=maxn+1) { c[x]+=d; x+=lowbit(x); } } int ans[N]; int main() { int i,j,k,l,r; while(~scanf("%d",&n),n) { MEM(ans,0); MEM(c,0); maxn = -1; for(i = 1; i<=n; i++) { scanf("%d%d",&a[i].l,&a[i].r); a[i].id = i; maxn = max(maxn,a[i].r); } sort(a+1,a+1+n,cmp); for(i = 1; i<=n; i++) { if(a[i].l == a[i-1].l && a[i].r == a[i-1].r) { ans[a[i].id] = ans[a[i-1].id]; } else { ans[a[i].id] = sum(a[i].l+1); } add(a[i].l+1,1); } printf("%d",ans[1]); for(i = 2; i<=n; i++) printf(" %d",ans[i]); printf("\n"); } return 0; }
标签:targe scanf nbsp wrap script mono namespace lang sub
原文地址:http://www.cnblogs.com/mthoutai/p/6905315.html