Topic links: https://www.lydsy.com/JudgeOnline/problem.php?id=3932
BZOJ:Time Limit: 20 Sec Memory Limit: 512 MB
Description
Input
Output
Sample Input
1 2 6
2 3 3
1 3 2
3 3 4
3 1 3 2
1 1 3 4
2 2 4 3
Sample Output
8
11
HINT
Chinese face problems, very friendly, another Los Valley K-value formula wrong. . .
The question is seeking face for the first time a single small values of k and then the front and a small value of k, then it is easy to think of the Chairman of the tree. But how is a maintenance problem. If the direct modification of violence into a single point, then not only can not afford the time and space but also can not afford. So I thought of the giant giant difference. . . Each time interval modification only need to modify the head and tail ends, namely update (st), update (ed + 1); when you learn to believe that the Chairman of the tree must have learned a tree array. . . So certainly I learned the difference, not to say.
First us, then when we go directly to the query on the line in the x-th tree for every moment achievements. In every moment, there is a section start or end, then we are directly update at the beginning and end of this time is represented by the number 1 and -1, 1 | -1 * b [pos] as its priority, then this is a differential, and wherein the b [pos] is the size of the discretization of the priority:
for (int i=1; i<=m; i++) { for (int j=0; j<st[i].size(); j++) { int p=lower_bound(fall+1,fall+1+nb,lis[st[i][j]])-fall; ver[++np]=update(1,nb,p,1,ver[np-1]); } for (int j=0; j<ed[i].size(); j++) { int p=lower_bound(fall+1,fall+1+nb,lis[ed[i][j]])-fall; ver[++np]=update(1,nb,p,-1,ver[np-1]); } last[i]=ver[np]; }
But before and differentiated version here each will have 0-2, but not the only one , so the final version of the i-th time we produced another record should look, here I use the last recorded
update function and the query function, then I do not speak, the former Chairman of the interval on a large tree k values are related to, and finally a reminder, each point may have a lot number, so the query time of l == r We should sum / num * k, where k is the number of remaining, corresponding to the number of monovalent *. . .
The following is the code :( AC Los Valley A No, for details see my blog description)
#include <bits/stdc++.h> using namespace std; #define ll long long const int mac=1e5+10; struct Tree { ll sum; int size,l,r; }tree[mac<<6]; int lis[mac],fall[mac],ver[mac*2]; vector<int>st[mac],ed[mac]; int last[mac]; int tot=0; void in(int &x) { int f=0; char ch=getchar(); while (ch>'9' || ch<'0') ch=getchar(); while (ch>='0' && ch<='9') f=(f<<1)+(f<<3)+ch-'0',ch=getchar(); x=f; } int build(int l,int r) { int mid=(l+r)>>1; int rt=++tot; if (l==r) return rt; tree[rt].l=build(l,mid); tree[rt].r=build(mid+1,r); return rt; } int update(int l,int r,int pos,int val,int per) { int rt = ++ all; tree[rt]=tree[per]; tree[rt].size+=val;tree[rt].sum+=1ll*val*fall[pos]; if (l==r) return rt; int mid=(l+r)>>1; if (mid>=pos) tree[rt].l=update(l,mid,pos,val,tree[per].l); else tree[rt].r=update(mid+1,r,pos,val,tree[per].r); return rt; } ll query(int l,int r,int rt,int k) { int x=tree[tree[rt].l].size; if (l==r) return tree[rt].sum/(1ll*tree[rt].size)*1ll*k; int mid=(l+r)>>1; if (x>=k) return query(l,mid,tree[rt].l,k); else return query(mid+1,r,tree[rt].r,k-x)+tree[tree[rt].l].sum; } int main () { int n,m; in(n);in(m); for (int i=1; i<=n; i++){ int x,y,z; in(x);in(y);in(z); November [i] = z; fall [i] = z; st[x].push_back(i); ed[y+1].push_back(i); } sort(fall+1,fall+1+n); int nb=unique(fall+1,fall+1+n)-fall-1; ver[0]=build(1,nb); int np=0; for (int i=1; i<=m; i++){ for (int j=0; j<st[i].size(); j++){ int p=lower_bound(fall+1,fall+1+nb,lis[st[i][j]])-fall; ver[++np]=update(1,nb,p,1,ver[np-1]); } for (int j=0; j<ed[i].size(); j++){ int p=lower_bound(fall+1,fall+1+nb,lis[ed[i][j]])-fall; ver[++np]=update(1,nb,p,-1,ver[np-1]); } last[i]=ver[np]; } ll per=1; for (int i=1; i<=m; i++){ int x,a,b,c; in(x);in(a);in(b);in(c); ll k=(1ll*a*per+b)%c+1; if (tree[last[x]].size<=k) per=tree[last[x]].sum; else per=query(1,nb,last[x],k); printf ("%lld\n",per); } return 0; }