这道题是标准的树状数组,而且输入数据已经有序。所以边输边查询就行。后输进来的不影响之前的结果/* ID: sdj22251 PROG: calfflac LANG: C++ */ #include <iostream> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <cmath> #include <ctime> #define MAX 2000000000 #define LOCA using namespace std; int level[15001]; int a[32011]; int lowbit(int x) { return x & -x; } void modify(int x) { for(int i = x; i <= 32001; i += lowbit(i)) a[i]++; } int getsum(int x) { int sum = 0; for(int i = x; i > 0; i -= lowbit(i)) sum += a[i]; return sum; } int main() { #ifdef LOCAL freopen("calfflac.in","r",stdin); freopen("calfflac.out","w",stdout); #endif int i, n, x, y; while(scanf("%d", &n) != EOF) { memset(a, 0, sizeof(a)); memset(level, 0, sizeof(level)); for(i = 0; i < n; i++) { scanf("%d%d", &x, &y); x++; level[getsum(x)]++; modify(x); } for(i = 0; i < n; i++) printf("%d\n", level[i]); } return 0; }
POJ 2352 Stars 树状数组
最新推荐文章于 2019-02-28 18:38:36 发布