Input file: web.in
output file: web.out
Simple comparison
Time limit: 1 s memory limit: MB
Description Description |
|
|
TYVJ's ADMIN--ZHQ students will begin to implement TYVJ new Web plan in winter vacation, make TYVJ become China's first-class informatics online evaluation system. TYVJ's new web plan has a total of n items, numbered 1~n, each of the important degree for V[I],ADMIN-ZHQ students to work together m times, J times from the number of l[j]~r[j] in the project to select the most important task completed, the amount of progress achieved is (L[J]+R[J]) * The importance of the task. The importance of the task becomes 0 after the task is completed. May I ask the admin how much progress can be made after working m times?
Note: The data guarantees that all tasks are at different degrees of importance in the initial situation. |
Input format
First act N,m
Second row n integers v[i].
Next m line, two integers per line l,r, means admin this time will be selected from the project numbered L~r (including l,r) the most important to complete.
Output format |
|
|
The final amount of progress. Since the results can be large, you only need to output the results after mod2011. |
Output format |
|
|
The final amount of progress. Since the results can be large, you only need to output the results after mod2011. |
Sample input:
5 3
1 2 3) 4 5
1 3
2 3
1 5
Sample output:
52
Segment Tree
Interval Maximum single point modification
Dragon Slayer Blades click on Send
#include <iostream>#include<cstdio>using namespaceStd;typedefLong LongLL;structnode{LL l,r,dis,v;} t[200000*4+1]; LL whr,to,maxn,n,m;voidUp (LL k) {if(t[k<<1].dis>t[k<<1|1].dis) {T[k].dis=t[k<<1].dis; T[K].V=t[k<<1].v; } Else{T[k].dis=t[k<<1|1].dis; T[K].V=t[k<<1|1].v; }}voidBuild (LL l,ll r,ll k) {T[K].L=l;t[k].r=R; if(l==r) {scanf ("%d",&T[k].dis); T[K].V=T[K].L; return; } LL Mid= (l+r) >>1; Build (L,mid,k<<1); Build (Mid+1,r,k<<1|1); Up (k);}voidquery (LL l,ll r,ll k) {if(t[k].l==l&&t[k].r==r) {if(t[k].dis>MAXN) {MAXN=T[k].dis; WHR=t[k].v; } return; } LL Mid= (T[K].L+T[K].R) >>1; if(r<=mid) query (l,r,k<<1); Else if(l>mid) query (l,r,k<<1|1); Else{query (l,mid,k<<1); Query (Mid+1,r,k<<1|1); }}voidDelet (LL now,ll k) {if(t[k].l==T[K].R) {T[k].dis=0; T[K].V=0; return; } LL Mid= (T[K].L+T[K].R) >>1; if(Mid>=now) Delet (now,k<<1); Else if(Mid<now) Delet (now,k<<1|1); Up (k);}intMain () {Freopen ("web.in","R", stdin); Freopen ("Web.out","W", stdout); CIN>>n>>m; Build (1N1); LL u,v; Long Longans=0; while(m--) {cin>>u>>v; MAXN=0; WHR; Query (U,v,1); Delet (WHR,1); Ans+ = (u+v) *maxn% .; Ans%= .; } cout<<ans; return 0;}
COGS 827. [TYVJ FEB11] website plan