Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- #include <vector>
- using namespace std;
- typedef int query;
- vector<query> q;
- vector<int> dict;
- vector<int> tree;
- int ds;
- int getds(int n)
- {
- n--;
- n|=n>>1;
- n|=n>>2;
- n|=n>>4;
- n|=n>>8;
- n|=n>>16;
- return n+1;
- }
- int gcd(int a,int b)
- {
- return b? gcd(b,a%b):a;
- }
- void change(int i,int delta)
- {
- i+=ds;
- tree[i]+=delta;
- tree[i/2]=gcd(tree[i]?dict[i-ds]:0,tree[i^1]?dict[(i^1)-ds]:0);
- i/=4;
- while(i)
- {
- tree[i]=gcd(tree[2*i],tree[2*i+1]);
- i/=2;
- }
- }
- int main()
- {
- int n;
- char op[2];
- int x;
- scanf("%d",&n);
- for(int i=0;i<n;i++)
- {
- scanf("%s%d",op,&x);
- q.push_back(x*((op[0]=='+')*2-1));
- dict.push_back(x);
- }
- sort(dict.begin(),dict.end());
- ds=getds(max(n,16));
- tree.resize(ds*2);
- for(int i=ds-1;i>0;i--)
- tree[i]=0;
- for(int i=0;i<n;i++)
- {
- change(lower_bound(dict.begin(),dict.end(),abs(q[i]))-dict.begin(),q[i]/abs(q[i]));
- printf("%d\n",tree[1]?tree[1]:1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment