v 0. Pasted by slipstak2 as cpp at 2011-02-01 20:40:16 MSK and set expiration to never.

Paste will expire never.

  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. const int MAX_VALUE = 32005;
  6. int n;
  7. vector<int> b(MAX_VALUE+1);
  8. vector<int> res;
  9. void add(int x, int delta) {
  10.     for (; x <= MAX_VALUE; x = x | (x + 1))
  11.         b[x] += delta;
  12. }
  13. int sum(int x) {
  14.     int res = 0;
  15.     for (; x >= 0; x = (x & (x + 1)) - 1)
  16.         res += b[x];
  17.     return res;
  18. }
  19. void input() {
  20.     cin>>n;
  21.     res.resize(n);
  22.     int x,y;
  23.     for (int i=0; i<n;i++) {
  24.         cin>>x>>y;
  25.         res[sum(x)]++;
  26.         add(x,1);
  27.     }
  28. }
  29. void output() {
  30.     for (int i=0;i<n;i++)
  31.         cout<<res[i]<<endl;
  32. }
  33. int main() {
  34. #ifdef _DEBUG
  35.     freopen("input.txt","r",stdin);
  36.     freopen("output.txt","w",stdout);
  37. #endif
  38.     input();
  39.     output();
  40.  
  41.     return 0;
  42. }


Editing is locked.