codechef September Challenge 2017 Sereja and Commands

时间:2022-03-26 18:58:12

codechef  September Challenge 2017  Sereja and Commands

codechef  September Challenge 2017  Sereja and Commands

————————————————————————————

这道题维护一下原序列的差分以及操作的差分就可以了

记得倒着差分操作 因为题目保证操作2的l r 小与当前位置

#include<cstdio>
#include<cstring>
#include<algorithm>
#define lowbit(x) x&-x;
using namespace std;
const int M=1e5+,mod=1e9+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
int T,n,m;
int s[M],f[M];
struct pos{int k,l,r;}q[M];
void clear(){
memset(s,,sizeof(s));
memset(f,,sizeof(f));
}
int main(){
T=read();
while(T--){
n=read(); m=read(); clear();
for(int i=;i<=m;i++) q[i].k=read(),q[i].l=read(),q[i].r=read();
f[m]=;
for(int i=m;i;i--){
int k=q[i].k,l=q[i].l,r=q[i].r;
if(k==){
s[l]=(s[l]+f[i])%mod;
s[r+]=(s[r+]-f[i])%mod;
}
else{
f[l-]=(f[l-]-f[i])%mod;
f[r]=(f[r]+f[i])%mod;
}
f[i-]=(f[i-]+f[i])%mod;
}
int sum=;
for(int i=;i<=n;i++) sum=(sum+s[i])%mod,printf("%d ",(sum+mod)%mod); puts("");
}
return ;
}