|
|
back to boardWA #15 Posted by Slava 11 Apr 2014 01:54 Someone knows what could be the problem ? Or give me any test. Code: #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <cstring> #include <vector> #include <set> #include <map> #include <queue> #include <deque> #include <cctype> #define ll long long #define ld long double #define sqr(a) (a)*(a) #define mp make_pair #define pb push_back #define x first #define y second #define inf (int)1e9 #define int ll using namespace std; const int N=100001; int sz=1,n,tree[4*N]; ll gcd(ll a,ll b) { while(a && b) if (a>b) a%=b; else b%=a; return a+b; } void up(int v,int val) { tree[v]=val; v/=2; while(v>0) { tree[v]=gcd(tree[v*2],tree[v*2+1]); v/=2; } } ll get(int v,int l,int r,int L,int R) { if (r<L || l>R) return 0; if (l>=L && r<=R) return tree[v]; return gcd(get(v*2,l,(l+r)/2,L,R), get(v*2+1,(l+r)/2+1,r,L,R)); } main() { cin>>n; map<int,vector<int> > a; char c; int x,k=0; while(sz<n) sz*=2; for(int i=0;i<n;i++) { cin>>c>>x; if (c=='+') { k++; a[x].push_back(i); up(sz+i,x); int ans=tree[1]; cout<<ans<<endl; } else { k--; int to=a[x].back(); a[x].pop_back(); up(sz+to,0); int ans=tree[1]; if (k==0) ans=1; cout<<ans<<endl; } } return 0; } |
|
|