BZOJ3932 [CQOI2015] Task query System chairman Tree + differential

Source: Internet
Author: User

Topic Portal

This is the Chairman tree, split a task into two parts: The task starts the join operation and the task ends the delete operation. (as if that's the difference.)

Then, if two operations occur at the same point in time, the root of the current time node is modified directly, otherwise it will be overwritten at the point in time between the two operating points as the root of the chair at the previous operation point in time. (To begin with, I don't know why I have this covered ...) IQ has gone offline)

Then there are some ordinary chairmen of the tree operation, directly write out on the line.

Attach the AC code:

#include <cstdio> #include <cctype> #include <algorithm> using namespace std;
typedef long Long LL;
const int N=1E5+10;
    struct note{int t,w,k; BOOL Operator < (const note LYF) const {return t<lyf.t;}}
a[n<<1];
    struct tree{int lt,rt;
ll Sum,w;
}T[5000010];
int n,m,x,y,w,b[n],len,root[n],g,size,a1,a2,a3;

ll Ans=1;
    Inline char nc (void) {static char ch[100010],*p1=ch,*p2=ch; Return p1==p2&& (p2= (p1=ch) +fread (Ch,1,100010,stdin), P1==P2)?
eof:*p1++;
    } inline void read (int &a) {static char c=nc (); int f=1; for (;!
    IsDigit (c); C=nc ()) if (c== '-') f=-1;
    For (A=0;isdigit (c); a= (a<<3) + (a<<1) + (c^ ' 0 '), C=NC ());
return (void) (A*=F); } #define MID (l+r>>1) inline void ist (int &k,int pre,int l,int r,int w,int c) {T[k=++size]=t[pre],t[k].sum
    +=c,t[k].w+=1ll*b[w]*c;
    if (l==r) return;
    if (mid>=w) ist (t[k].lt,t[pre].lt,l,mid,w,c);
    Else ist (t[k].rt,t[pre].rt,mid+1,r,w,c);
Return } Inline ll query (int k,int l,int R,int w) {if (w>=t[k].sum) return T[K].W;
    if (l==r) return 1ll*t[k].w/t[k].sum*w;
    if (w<=t[t[k].lt].sum) return query (T[K].LT,L,MID,W);
else return t[t[k].lt].w+query (t[k].rt,mid+1,r,w-t[t[k].lt].sum);
    } int main (void) {read (n), read (m);
    for (int i=1; i<=n; ++i) Read (x), read (y), read (W), b[i]=w,a[2*i-1]= (note) {x,w,1},a[2*i]= (note) {y+1,w,-1};
    Sort (b+1,b+1+n), sort (a+1,a+1+n*2), Len=unique (b+1,b+1+n)-b-1;
        for (int i=1, i<=n*2; ++i) {for (int j=a[i-1].t+1; j<a[i].t; ++j) root[j]=root[j-1];
        if (a[i].t!=a[i-1].t) ist (root[a[i].t],root[a[i].t-1],1,len,lower_bound (B+1,B+1+LEN,A[I].W)-B,A[I].K);
    Else ist (root[a[i].t],root[a[i].t],1,len,lower_bound (B+1,B+1+LEN,A[I].W)-B,A[I].K);
    The while (m--) read (x), read (A1), read (A2), read (A3), printf ("%lld\n", Ans=query (root[x],1,len,1+ (A1*ANS+A2)%a3));
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.