Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*===============*\
- | ID: TMANDZU |
- | LANG: C++ |
- \*===============*/
- //Tornike Mandzulashvili
- //#pragma comment(linker,"/STACK:256000000")
- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <algorithm>
- #include <stack>
- #include <math.h>
- #include <vector>
- #include <string>
- #include <map>
- #include <queue>
- #include <iostream>
- #include <set>
- #include <cstring>
- #define EPS 0.000000001
- #define Pi 3.1415926535897932384626433832795028841971
- #define hash1 1000003
- #define hash2 1000033
- #define md 1000000007
- #define INF 1000000500
- #define mp make_pair
- #define pb push_back
- #define S size()
- #define MX(aa,bb) (aa>bb?aa:bb)
- #define MN(aa,bb) (aa<bb?aa:bb)
- #define fi first
- #define se second
- #define PI pair < int,int >
- #define REP(i,a,n) for(i=a;i<n;i++)
- #define sc scanf
- #define pt printf
- #define big long long
- #define VI vector <int>
- #define DID (long long)
- using namespace std;
- const int T=100005;
- int A[T];
- int Q,x,y,i,N;
- char ch;
- PI per,cur;
- struct node
- {
- node *l,*r;
- pair <int,int> mx;
- node (int val)
- : l(NULL) ,r(NULL),mx(mp(-1,-1))
- { }
- node (node *x,node *y)
- : l(x) ,r(y),mx(mp(-1,-1))
- {
- if (l)
- mx=max(mx,l->mx);
- if (r)
- mx=max(mx,r->mx);
- }
- };
- node* build(int a,int b)
- {
- if (a==b) return new node(A[a]);
- int mid=(a+b)>>1;
- return new node
- (
- build(a,mid) , build(mid+1,b)
- );
- }
- node* update(node *v,int l,int r,int pos,int delta)
- {
- if (l==r)
- {
- v->mx.fi=delta;
- v->mx.se=l;
- return v;
- }
- int mid=(l+r)>>1;
- if (pos<=mid)
- v->l=update(v->l,l,mid,pos,delta);else
- v->r=update(v->r,mid+1,r,pos,delta);
- v->mx=max(v->l->mx,v->r->mx);
- return v;
- }
- PI getmax(node *v,int l,int r,int a,int b)
- {
- if (l>b || a>r) return mp(-1,-1);
- if (a<=l && r<=b)
- {
- return v->mx;
- }
- return max(getmax(v->l,l,(l+r)/2,a,b),getmax(v->r,(l+r)/2+1,r,a,b));
- }
- node *root;
- main()
- {
- // freopen("text.in","r",stdin); freopen("text.out","w",stdout);
- scanf("%d\n",&N);
- for (i=0;i<N;i++)
- scanf("%d",&A[i]);
- scanf("\n");
- root=build(0,N-1);
- for (i=0;i<N;i++)
- update(root,0,N-1,i,A[i]);
- scanf("%d\n",&Q);
- while (Q--)
- {
- scanf("%c",&ch);
- if (ch=='U')
- {
- scanf(" %d %d\n",&i,&x);
- i--;
- root=update(root,0,N-1,i,x);
- }else
- {
- scanf(" %d %d\n",&x,&y);
- x--;y--;
- per=getmax(root,0,N-1,x,y);
- update(root,0,N-1,per.se,-1);
- cur=getmax(root,0,N-1,x,y);
- update(root,0,N-1,per.se,per.fi);
- // cout<<per.fi<<" "<<cur.fi<<endl;
- printf("%d\n",per.fi+cur.fi);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement