bzoj3932 [CQOI2015]任务查询系统

题目链接

主席树模板题

本来想用treap写

但是看到强制在线就放弃了

还是有点不熟,多练

  1 #include<algorithm>
  2 #include<iostream>
  3 #include<cstdlib>
  4 #include<cstring>
  5 #include<cstdio>
  6 #include<string>
  7 #include<cmath>
  8 #include<ctime>
  9 #include<queue>
 10 #include<stack>
 11 #include<map>
 12 #include<set>
 13 #define rre(i,r,l) for(int i=(r);i>=(l);i--)
 14 #define re(i,l,r) for(int i=(l);i<=(r);i++)
 15 #define Clear(a,b) memset(a,b,sizeof(a))
 16 #define inout(x) printf("%d",(x))
 17 #define douin(x) scanf("%lf",&x)
 18 #define strin(x) scanf("%s",(x))
 19 #define LLin(x) scanf("%lld",&x)
 20 #define op operator
 21 #define CSC main
 22 typedef unsigned long long ULL;
 23 typedef const int cint;
 24 typedef long long LL;
 25 using namespace std;
 26 void inin(int &ret)
 27 {
 28     ret=0;int f=0;char ch=getchar();
 29     while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
 30     while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar();
 31     ret=f?-ret:ret;
 32 }
 33 struct SEG
 34 {
 35     int l,r,s,L,R;
 36     LL sum;
 37     SEG(){l=r=0,sum=0;}
 38 }t[10000040];int Max;
 39 int root[10000020],ed;
 40 void update(int l,int r,int x,int &y,int xxx,bool bo,int f)
 41 {
 42     if(bo)y=++ed;t[y].sum=t[x].sum+xxx*f,t[y].s=t[x].s+f;
 43     t[y].L=l,t[y].R=r;
 44     if(l==r)return ;
 45     t[y].l=t[x].l,t[y].r=t[x].r;
 46     int mid=(l+r)>>1;
 47     if(xxx<=mid)update(l,mid,t[x].l,t[y].l,xxx,1,f);
 48     else update(mid+1,r,t[x].r,t[y].r,xxx,1,f);
 49 }
 50 int cur;
 51 void update(int wei,int x,int opt)
 52 {
 53     re(i,cur+1,wei-1)if(!root[i])root[i]=root[i-1];
 54     cur=wei;
 55     if(!root[wei])update(1,Max,root[wei-1],root[wei],x,1,opt);
 56     else update(1,Max,root[wei],root[wei],x,0,opt);
 57 }
 58 LL query(int wei,int k)
 59 {
 60     int x=root[wei];
 61     LL ret=0;
 62     while(1)
 63     {
 64         if(k<=t[t[x].l].s)x=t[x].l;
 65         else ret+=t[t[x].l].sum,k-=t[t[x].l].s,x=t[x].r;
 66         if(t[x].L==t[x].R){ret+=min(k,t[x].s)*(!t[x].sum?0:(t[x].sum/t[x].s));break;}
 67     }
 68     return ret;
 69 }
 70 int n,m;
 71 struct work
 72 {
 73     int t,k,opt;
 74     bool op < (const work &rhs)const {return t<rhs.t;}
 75 }ww[200020];
 76 int CSC()
 77 {
 78     inin(n),inin(m);
 79     re(i,1,n)
 80     {
 81         int q,w,e;
 82         inin(q),inin(w),inin(e);
 83         ww[i].t=q,ww[i+n].t=w+1;
 84         ww[i].k=ww[i+n].k=e;
 85         ww[i].opt=1,ww[i+n].opt=-1;
 86         Max=max(e,Max);
 87     }
 88     sort(ww+1,ww+n+n+1);
 89     re(i,1,n<<1)
 90         update(ww[i].t,ww[i].k,ww[i].opt);
 91     LL Pre=1;
 92     re(i,1,m)
 93     {
 94         int x,A,B,C;
 95         inin(x),inin(A),inin(B),inin(C);
 96         int k=(LL)((LL)(Pre*A)+B)%C+1;
 97         printf("%lld\n",Pre=query(x,k));
 98     }
 99     return 0;
100 }

 

posted @ 2016-02-03 22:34  HugeGun  阅读(189)  评论(0编辑  收藏  举报