标签:bzoj bzoj3932 可持久化数据结构 线段树 可持久化线段树
题目大意见http://pan.baidu.com/s/1o6zajc2
主席树裸上就好了。。。
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 100100 using namespace std; struct Segtree{ Segtree *ls,*rs; int size; long long sum; void* operator new (size_t,Segtree *_,Segtree *__,int ___,long long ____) { #define L (1<<15) static Segtree *mempool,*C; if(C==mempool) mempool=(C=new Segtree[L])+L; C->ls=_; C->rs=__; C->size=___; C->sum=____; return C++; } friend Segtree* Build_Tree(Segtree *p,int x,int y,int pos,int d_size,long long d_sum) { int mid=x+y>>1; if(x==y) return new (0x0,0x0,p->size+d_size,p->sum+d_sum)Segtree; if(pos<=mid) return new (Build_Tree(p->ls,x,mid,pos,d_size,d_sum),p->rs,p->size+d_size,p->sum+d_sum)Segtree; else return new (p->ls,Build_Tree(p->rs,mid+1,y,pos,d_size,d_sum),p->size+d_size,p->sum+d_sum)Segtree; } friend long long Query(Segtree *p,int x,int y,int k) { int mid=x+y>>1; if(x==y) return (long long)mid*min(k,p->size); if(k<=p->ls->size) return Query(p->ls,x,mid,k); else return Query(p->rs,mid+1,y,k-p->ls->size) + p->ls->sum ; } }*tree[M]; struct abcd{ bool flag; int tim,val; bool operator < (const abcd &a) const { return tim < a.tim ; } }a[M<<1]; int n,m; long long last_ans=1; int main() { int i,j,x,y,z,A,B,C; cin>>m>>n; for(i=1;i<=m;i++) { scanf("%d%d%d",&x,&y,&z); a[i+i-1].flag=true; a[i+i-1].tim=x; a[i+i-1].val=z; a[i<<1].flag=false; a[i<<1].tim=y+1; a[i<<1].val=z; } sort(a+1,a+m+m+1); tree[0]=new (0x0,0x0,0,0ll)Segtree; tree[0]->ls=tree[0]->rs=tree[0]; for(j=1,i=1;i<=n;i++) { tree[i]=tree[i-1]; for(;j<=m<<1&&a[j].tim==i;j++) tree[i]=Build_Tree(tree[i],1,10000000,a[j].val,a[j].flag?1:-1,a[j].val*(a[j].flag?1:-1)); } for(i=1;i<=n;i++) { scanf("%d%d%d%d",&x,&A,&B,&C); int k=(A*last_ans+B)%C+1; printf("%lld\n",last_ans=Query(tree[x],1,10000000,k)); } return 0; }
BZOJ 3932 CQOI2015 任务查询系统 可持久化线段树
标签:bzoj bzoj3932 可持久化数据结构 线段树 可持久化线段树
原文地址:http://blog.csdn.net/popoqqq/article/details/44920121