Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
y. 第一道树状数组#include "iostream" #include "cstring" using namespace std; #define MAX 32005 int n, c[MAX], cnt[MAX]; int lowbit(int x) { return x & (-x); } void update(int x, int v) { for(int i = x; i <= MAX; i += lowbit(i)) c[i] += v; } int sum(int x) { int res = 0; for(int i = x; i; i -= lowbit(i)) res += c[i]; return res; } int main() { int x, y; cin >> n; for(int i = 0; i < n; i++) { cin >> x >> y; int rank = sum(x + 1); cnt[rank]++; update(x + 1, 1); } for(int i = 0; i < n; i++) cout << cnt[i] << endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator