明天(2018.2.13) FCS NOI2018,其实就是FJOI2018省选一试。
发现好久没更新博客了,贴一下数据结构的模板。

1 #include<cstdio> 2 #define MN 100005 3 #define R register 4 #define ll long long 5 #ifdef WIN32 6 #define LL "%I64d" 7 #else 8 #define LL "%lld" 9 #endif 10 inline ll read(){ 11 R ll x=0;R bool f=1;R char ch=getchar(); 12 while(ch<'0'||ch>'9') {if(ch=='-') f=0;ch=getchar();} 13 while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();} 14 return f?x:-x; 15 } 16 int a[MN],n,m;ll addv[MN<<2],sumv[MN<<2]; 17 #define lson (x<<1) 18 #define rson (x<<1|1) 19 inline void pushup(int x){sumv[x]=sumv[lson]+sumv[rson];} 20 inline void pushdown(int x,int l,int r){ 21 if(!addv[x]) return; 22 ll tag=addv[x];addv[x]=0;int mid=(l+r)>>1; 23 addv[lson]+=tag;addv[rson]+=tag; 24 sumv[lson]+=(tag*1ll*(mid-l+1));sumv[rson]+=(tag*1ll*(r-mid)); 25 } 26 inline void build(int x,int l,int r){ 27 addv[x]=0; 28 if(l==r) {sumv[x]=a[l];return;} 29 int mid=(l+r)>>1; 30 build(lson,l,mid);build(rson,mid+1,r); 31 pushup(x); 32 } 33 inline void addcx(int x,int l,int r,int pl,int pr,int v){ 34 if(pl<=l&&r<=pr) {addv[x]+=v;sumv[x]+=(1ll*v*(r-l+1));return;} 35 int mid=(l+r)>>1;pushdown(x,l,r); 36 if(pl<=mid) addcx(lson,l,mid,pl,pr,v); 37 if(pr>mid) addcx(rson,mid+1,r,pl,pr,v); 38 pushup(x); 39 } 40 inline ll query(int x,int l,int r,int pl,int pr){ 41 if(pl<=l&&r<=pr) return sumv[x]; 42 pushdown(x,l,r);int mid=(l+r)>>1;ll ans=0; 43 if(pl<=mid) ans+=query(lson,l,mid,pl,pr); 44 if(pr>mid) ans+=query(rson,mid+1,r,pl,pr); 45 return ans; 46 } 47 inline void fir(){int x=read(),y=read();ll k=read();addcx(1,1,n,x,y,k);} 48 inline void sec(){int x=read(),y=read();printf(LL" ",query(1,1,n,x,y));} 49 int main(){ 50 scanf("%d%d",&n,&m); 51 for(int i=1;i<=n;i++) scanf("%d",&a[i]); 52 build(1,1,n); 53 for(int q=1;q<=m;q++) { 54 int opt=read(); 55 if(opt==1) fir(); 56 if(opt==2) sec(); 57 } 58 }

1 // luogu-judger-enable-o2 2 #include<cstdio> 3 #define ll long long 4 #define R register 5 #ifdef WIN32 6 #define LL "%I64d" 7 #else 8 #define LL "%lld" 9 #endif 10 const int MN=100005; 11 int a[MN],n,m;ll p; 12 inline ll read(){ 13 R ll x=0;R bool f=1;R char ch=getchar(); 14 while(ch<'0'||ch>'9') {if(ch=='-') f=0;ch=getchar();} 15 while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();} 16 return f?x:-x; 17 } 18 ll sumv[MN<<2],mulv[MN<<2],addv[MN<<2]; 19 #define lson (x<<1) 20 #define rson (x<<1|1) 21 inline void pushup(int x){sumv[x]=(sumv[lson]+sumv[rson])%p;} 22 inline void pushdown(int x,int l,int r){ 23 ll m_tag=mulv[x];mulv[x]=1; 24 mulv[lson]=(mulv[lson]*m_tag)%p;mulv[rson]=(mulv[rson]*m_tag)%p; 25 addv[lson]=(addv[lson]*m_tag)%p;addv[rson]=(addv[rson]*m_tag)%p; 26 sumv[lson]=(sumv[lson]*m_tag)%p;sumv[rson]=(sumv[rson]*m_tag)%p; 27 ll tag=addv[x];addv[x]=0;int mid=(l+r)>>1; 28 addv[lson]=(addv[lson]+tag)%p;addv[rson]=(addv[rson]+tag)%p; 29 sumv[lson]=(sumv[lson]+tag*1ll*(mid-l+1))%p;sumv[rson]=(sumv[rson]+tag*1ll*(r-mid))%p; 30 } 31 inline void build(int x,int l,int r){ 32 addv[x]=0;mulv[x]=1; 33 if(l==r) {sumv[x]=a[l];return ;} 34 int mid=(l+r)>>1; 35 build(lson,l,mid);build(rson,mid+1,r); 36 pushup(x); 37 } 38 inline void addcx(int x,int l,int r,int pl,int pr,ll v){ 39 if(pl<=l&&r<=pr) {sumv[x]+=v*1ll*(r-l+1);addv[x]+=v;return ;} 40 int mid=(l+r)>>1;if(mulv[x]!=1||addv[x]) pushdown(x,l,r); 41 if(pl<=mid) addcx(lson,l,mid,pl,pr,v); 42 if(pr>mid) addcx(rson,mid+1,r,pl,pr,v); 43 pushup(x); 44 } 45 inline void mulcx(int x,int l,int r,int pl,int pr,ll v){ 46 if(pl<=l&&r<=pr) { 47 mulv[x]=(mulv[x]*1ll*v)%p; 48 addv[x]=(addv[x]*1ll*v)%p; 49 sumv[x]=(sumv[x]*1ll*v)%p; 50 return ; 51 } 52 int mid=(l+r)>>1;if(mulv[x]!=1||addv[x]) pushdown(x,l,r); 53 if(pl<=mid) mulcx(lson,l,mid,pl,pr,v); 54 if(pr>mid) mulcx(rson,mid+1,r,pl,pr,v); 55 pushup(x); 56 } 57 inline ll query(int x,int l,int r,int pl,int pr){ 58 if(pl<=l&&r<=pr) return sumv[x]; 59 if(mulv[x]!=1||addv[x]) pushdown(x,l,r); 60 int mid=(l+r)>>1;ll ans=0; 61 if(pl<=mid) ans+=query(lson,l,mid,pl,pr); 62 if(pr>mid) ans+=query(rson,mid+1,r,pl,pr); 63 return ans%p; 64 } 65 inline void fir(){int x=read(),y=read();ll k=read();mulcx(1,1,n,x,y,k);} 66 inline void sec(){int x=read(),y=read();ll k=read();addcx(1,1,n,x,y,k);} 67 inline void tri(){int x=read(),y=read();ll res=query(1,1,n,x,y);printf(LL" ",res);} 68 int main(){ 69 n=read();m=read();p=read(); 70 for(int i=1;i<=n;i++) a[i]=read(); 71 build(1,1,n); 72 while(m--){ 73 int opt;opt=read(); 74 if(opt==1) fir(); 75 if(opt==2) sec(); 76 if(opt==3) tri(); 77 } 78 }

1 #include<cstdio> 2 #define ll long long 3 #define R register 4 #ifdef WIN32 5 #define LL "%I64d" 6 #else 7 #define LL "%lld" 8 #endif 9 const int MN=200005,INF=0x7fffffff; 10 int a[MN],n,m; 11 inline int read(){ 12 R int x=0;R bool f=1;R char ch=getchar(); 13 while(ch<'0'||ch>'9') {if(ch=='-') f=0;ch=getchar();} 14 while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();} 15 return f?x:-x; 16 } 17 inline int Max(int a,int b){return a>b?a:b;} 18 inline int Min(int a,int b){return a<b?a:b;} 19 int sumv[MN<<2],minv[MN<<2],maxv[MN<<2]; 20 #define lson (x<<1) 21 #define rson (x<<1|1) 22 inline void pushup(int x){ 23 sumv[x]=sumv[lson]+sumv[rson]; 24 minv[x]=Min(minv[lson],minv[rson]); 25 maxv[x]=Max(maxv[lson],maxv[rson]); 26 } 27 inline void build(int x,int l,int r){ 28 //addv[x]=0; 29 if(l==r) {sumv[x]=a[l];minv[x]=a[l];maxv[x]=a[l];return;} 30 int mid=(l+r)>>1; 31 build(lson,l,mid);build(rson,mid+1,r); 32 pushup(x); 33 } 34 inline void addcx_one(int x,int l,int r,int d,int v){ 35 if(l==r) {sumv[x]+=v,minv[x]+=v,maxv[x]+=v;return;} 36 int mid=(l+r)>>1;//pushdown(x,l,r); 37 if(d<=mid) addcx_one(lson,l,mid,d,v); 38 else addcx_one(rson,mid+1,r,d,v); 39 pushup(x); 40 } 41 inline int query(int x,int l,int r,int pl,int pr){ 42 if(pl<=l&&r<=pr) return sumv[x]; 43 int mid=(l+r)>>1;int ans=0ll;//pushdown(x,l,r); 44 if(pl<=mid) ans+=query(lson,l,mid,pl,pr); 45 if(pr>mid) ans+=query(rson,mid+1,r,pl,pr); 46 return ans; 47 } 48 inline int querymin(int x,int l,int r,int pl,int pr){ 49 if(pl<=l&&r<=pr) return minv[x]; 50 int mid=(l+r)>>1;int ans=INF;//pushdown(x,l,r); 51 if(pl<=mid) ans=Min(ans,querymin(lson,l,mid,pl,pr)); 52 if(pr>mid) ans=Min(ans,querymin(rson,mid+1,r,pl,pr)); 53 return ans; 54 } 55 inline int querymax(int x,int l,int r,int pl,int pr){ 56 if(pl<=l&&r<=pr) return maxv[x]; 57 int mid=(l+r)>>1;int ans=-INF;//pushdown(x,l,r); 58 if(pl<=mid) ans=Max(ans,querymax(lson,l,mid,pl,pr)); 59 if(pr>mid) ans=Max(ans,querymax(rson,mid+1,r,pl,pr)); 60 return ans; 61 } 62 inline void fir(){int x=read(),k=read();addcx_one(1,1,n,x,k);} 63 inline void sec(){int x=read(),y=read();printf("%d ",query(1,1,n,x,y));} 64 inline void tri(){int x=read(),y=read();printf("%d ",querymax(1,1,n,x,y));} 65 inline void fou(){int x=read(),y=read();printf("%d ",querymin(1,1,n,x,y));} 66 int main(){ 67 n=read();m=read(); 68 for(int i=1;i<=n;i++) a[i]=read(); 69 build(1,1,n); 70 for(int q=1;q<=m;q++){ 71 int opt=read(); 72 if(opt==1) fir(); 73 if(opt==2) sec(); 74 if(opt==3) tri(); 75 if(opt==4) fou(); 76 } 77 }

1 #include<cstdio> 2 #define MN 500005 3 int n,fa[MN]; 4 inline int lowbit(int x){return x&-x;} 5 inline void add(int x,int y){for(;x<=n;x+=lowbit(x)) fa[x]+=y;} 6 inline int ask(int x){ 7 int res=0; 8 for(;x;x-=lowbit(x)) res+=fa[x]; 9 return res; 10 } 11 int main(){ 12 int m;scanf("%d%d",&n,&m); 13 for(int i=1;i<=n;i++) {int x;scanf("%d",&x);add(i,x);} 14 for(int i=1;i<=m;i++) { 15 int opt;scanf("%d",&opt); 16 if(opt==1) {int x,k;scanf("%d%d",&x,&k);add(x,k);} 17 if(opt==2) {int x,y;scanf("%d%d",&x,&y);printf("%d ",ask(y)-ask(x-1));} 18 } 19 return 0; 20 }

1 #include<cstdio> 2 #define R register 3 #define MN 100005 4 int f[MN][MN],a[MN],lg2[MN]; 5 inline int Min(int a,int b){return a<b?a:b;} 6 inline void build_ST(){ 7 for(R int i=1;i<=n;i++) f[i][0]=a[i]; 8 for(int j=1;j<18;j++) 9 for(R int i=1;i<=n-(1<<j-1);i++) f[i][j]=Min(f[i][j-1],f[i+(1<<j-1)][j-1]); 10 for(R int i=2;i<=n;i++) lg2[i]=lg2[i>>1]+1; 11 } 12 inline int rmq(int l,int r){ 13 int t=lg2[r-l+1]; 14 return Min(f[l][t],f[r-(1<<t)+1][t]); 15 } 16 int main(){ 17 //do sth... 18 }
//其余的留坑
祝各位dalao明天考试顺利!