time:2016.05.08
Author:xiaoyimi
Reprint Note Source Thank
Transmission Door
Ideas:
Seriously, I did not know how to make the first problem, only know that should be the root of time, record the priority value and maintain the prefix and, but can not think how to use the chairman of the tree prefix to build ideas, violence achievements + modification is certainly unscientific ...
Later to see the puzzle, and found that the difference.
Recall the fear that was dominated by the transport program ... (Or are you too weak for this reason)
However, this difference is relatively simple, because it is using the first tree i-1 tree as the basis for the idea, such as a task of the time interval of [l,r], the priority is P, then we in root[l] on the achievement of the +p,root[r+1] on the time-P, This makes it possible to enumerate the operations at each point in time, because there are M tasks, each task has two point-in-time operation, so up to 2m tree, each time point represents the Chairman tree is the last time it modifies the tree built, record each point in the last operation of the tree built by the number Pos[i], Query operation is empty tree and pos[i] subtraction, this is the chairman of the tree basic operation, but more than repeat
Attention:
1. Simple calculation can get the sum here can be 100000*100000, more than int, so sum is calculated with a long long
2. For each time point of the modification, there are +-, so in the original build code to make a slight change, record coefficients and so on
Code:
#include <bits/stdc++.h>#define M 100004#define LL Long Long#define LS (x) a[x].ch[0]#define RS (x) a[x].ch[1]using namespace STD;intN,m,cnt,k;intID[M],S[M],E[M],P[M],POS[M]; LL lastans=1; vector <int>T[M];structdisc{intData,id;BOOL operator< (ConstDisc Other)Const{returndata<other.data; }}B[M];structchairman_tree{intsiz,ch[2]; LL sum;} a[m<<6];intIn () {CharCh=getchar ();intt=0; while(!IsDigit(CH)) Ch=getchar (); while(IsDigit(CH)) T= (t<<3) + (t<<1) +ch- -, Ch=getchar ();returnt;}voidBuildintNowintLintRintRtintKintval) {a[rt].siz=a[now].siz+k; A[rt].sum=a[now].sum+k*id[val];if(L==R)return;intMid= (l+r) >>1;if(Mid>=val) RS (RT) =rs (now), LS (RT) =++cnt, build (LS (now), L,mid,ls (RT), K,val);ElseLS (RT) =ls (now), RS (RT) =++cnt, Build (RS (now), mid+1, R,rs (RT), K,val);} LL Get (intBeginintEndintLintRintK) {if(Begin==end)returnA[r].sum-a[l].sum;intMid= (begin+end) >>1, T=a[ls (R)].siz-a[ls (L)].siz;if(k<=t)returnGet (Begin,mid,ls (L), LS (R), k);Else returnA[ls (R)].sum-a[ls (L)].sum+get (mid+1, End,rs (L), RS (R), k-t);} Main () {m=in (); N=in (); for(intI=1; i<=m;i++) S[i]=in (), E[i]=in (), P[i]=in (), b[i].id=i,b[i].data=p[i]; Sort (b +1, b+m+1); for(intI=1; i<=m;i++) Id[i]=b[i].data, p[b[i].id]=i; Cnt=1; for(intI=1; i<=m;i++) T[s[i]].push_back (P[i]), t[e[i]+1].push_back (-p[i]), cnt+=1+ (e[i]+1<=N); for(intrt=1, i=1; i<=n;i++) { for(intj=0; J<t[i].size (); j + +) build (RT,1, n,rt+1, t[i][j]/ABS(T[i][j]),ABS(T[i][j])), rt++; Pos[i]=rt; }intX for(intI=1; i<=n;i++) X=in (), k= (Lastans*in () +in ())%in () +1,printf("%lld\n", Lastans=get (1N1, pos[x],k));}
"BZOJ3932" task query system, Chairman tree and Difference theory of achievement