Created
May 6, 2013 16:53
-
-
Save uerobert/5526378 to your computer and use it in GitHub Desktop.
1028. Stars @ Timus Online Judge. (with Fenwick Tree)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| #define MAX 32111 | |
| int tree[MAX+1]; | |
| int read(int idx) { | |
| int sum = 0; | |
| for (; idx > 0; idx -= (idx & -idx)) | |
| sum += tree[idx]; | |
| return sum; | |
| } | |
| int update(int idx, int val) { | |
| for (; idx <= MAX; idx += (idx & -idx)) | |
| tree[idx] += val; | |
| } | |
| int rsq(int l, int r) { return read(r) - read(l - 1); } | |
| int main() { | |
| int N; | |
| cin >> N; | |
| vector<int> ans(N + 1, 0); | |
| for (int i = 0; i < N; i++) { | |
| int x, y; | |
| cin >> x >> y; | |
| ++ans[read(x + 1)]; | |
| update(x + 1, 1); | |
| } | |
| for (int i = 0; i < N; i++) | |
| cout << ans[i] << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment