经典题!!!
View Code
1 #include<stdio.h> 2 #include<string.h> 3 const int maxn = 100005; 4 typedef __int64 int64; 5 int64 a[ maxn ]; 6 int64 vis[ maxn ]; 7 int64 cnt[ maxn ]; 8 struct node{ 9 int64 l,r,d; 10 }b[ maxn ]; 11 int main(){ 12 int64 n,k,m; 13 while( scanf("%I64d%I64d%I64d",&n,&m,&k)==3 ){ 14 for( int i=1;i<=n;i++ ) 15 scanf("%I64d",&a[i]); 16 memset( vis,0,sizeof( vis ) ); 17 memset( cnt,0,sizeof( cnt ) ); 18 for( int i=1;i<=m;i++ ) 19 scanf("%I64d%I64d%I64d",&b[i].l,&b[i].r,&b[i].d); 20 int64 s,t; 21 while( k-- ){ 22 scanf("%I64d%I64d",&s,&t); 23 cnt[ s ]++; 24 cnt[ t+1 ]--; 25 } 26 int64 sum=0; 27 for( int i=1;i<=m;i++ ){ 28 int64 tt = cnt[i]+sum; 29 vis[ b[i].l ]+=b[i].d*tt; 30 vis[ b[i].r+1 ]-=b[i].d*tt; 31 sum+=cnt[i]; 32 } 33 for( int64 i=1;i<=n;i++ ){ 34 if( i==1 ){ 35 sum = vis[i]; 36 printf("%I64d",a[i]+sum); 37 } 38 else{ 39 sum+=vis[i]; 40 printf(" %I64d",a[i]+sum); 41 } 42 } 43 printf("\n"); 44 } 45 return 0; 46 }
题意:给出一些操作,然后给出k个询问。对于每个询问,进行某个操作。