Advertisement
Saleh127

Timus 1846

Jun 16th, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll a[100005];
  6. ll tree[400005];
  7.  
  8. void update(ll node,ll b,ll e,ll i,ll newv)
  9. {
  10. if(i>e || i<b) return;
  11.  
  12. if(b==e && e==i)
  13. {
  14. tree[node]+=newv;
  15. return;
  16. }
  17.  
  18. ll left = node*2;
  19. ll right = node*2 + 1ll;
  20.  
  21. ll mid=(b+e)/2;
  22.  
  23. update(left,b,mid,i,newv);
  24.  
  25. update(right,mid+1,e,i,newv);
  26.  
  27. tree[node]=__gcd(tree[left],tree[right]);
  28.  
  29. }
  30.  
  31. int main()
  32. {
  33. ios_base::sync_with_stdio(0);
  34. cin.tie(0);
  35. cout.tie(0);
  36.  
  37.  
  38. ll n,m,i,j,k,l=1;
  39.  
  40. map<ll,set<ll>>x;
  41. char c;
  42.  
  43. cin>>n;
  44.  
  45. for(i=1;i<=n;i++)
  46. {
  47. cin>>c>>m;
  48. if(c=='+')
  49. {
  50. update(1,1,n,l,m);
  51. x[m].insert(l);
  52. l++;
  53. }
  54. else
  55. {
  56. auto dd=x[m].begin();
  57. if(dd!=x[m].end())
  58. {
  59. update(1,1,n,*dd,-m);
  60. x[m].erase(dd);
  61. }
  62. }
  63.  
  64. cout<<max(1ll,tree[1])<<endl;
  65. }
  66.  
  67. return 0;
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement