Advertisement
Manioc

arco_flecha_BIT

Aug 9th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define MAX 2000000000000000007
  3.  
  4. using namespace std;
  5. typedef long long ll;
  6. map<ll, ll> bit;
  7.  
  8. void update(ll idx, ll val){
  9.     idx = idx + 1LL;
  10.     for(; idx <= MAX; idx += idx&(-idx)) {
  11.         //cout << idx << endl;
  12.         //string pluf; cin >> pluf;
  13.         bit[idx] += val;
  14.     }
  15. }
  16.  
  17. ll query(ll idx){
  18.     idx = idx + 1LL;
  19.     ll sum = 0;
  20.     for(; idx > 0; idx -= idx&(-idx)) {
  21.         //cout << idx << endl;
  22.         if(bit.count(idx)) sum += bit[idx];
  23.     }
  24.     return sum;
  25. }
  26.  
  27. int main(){
  28.     int n; scanf("%d", &n);
  29.  
  30.     ll past = 0;
  31.     for(int i = 0; i < n; i++){
  32.         ll x, y; scanf("%lld %lld", &x, &y);
  33.         //cout << ((x+1LL)*(x+1LL)) << " " << ((y+1LL)*(y+1LL)) << endl;
  34.  
  35.         x = x + past;
  36.         y = y + past;
  37.         ll dist = x*x + y*y;
  38.         //cout << dist << endl;
  39.         past = query(dist);
  40.         printf("%lld\n", past);
  41.         //cout << "-------------\n";
  42.         update(dist, 1);
  43.     }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement