fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct s{
  4. int pos,eff_gt;
  5. }s;
  6. s sp[50001];
  7. int main(void) {
  8. int n,i,q,x1,y1,j=0,k=0,m=0,no;
  9. long long int d,eff;
  10. char act[1];
  11. scanf("%d %d",&n,&q);
  12. long long int temp[q];
  13. int cs[n];
  14. cs[0]=0;
  15. for(i=1;i<=n;i++)
  16. {
  17. scanf("%d",&no);
  18. cs[i]=cs[i-1]+no;
  19. }
  20. for(i=0;i<q;i++)
  21. {
  22. scanf("%s %d %d",act,&x1,&y1);
  23. sp[i].eff_gt=0;
  24. if(act[0]=='S')
  25. {
  26. eff=0;
  27. for(k=0;k<j;k++)
  28. if(sp[k].pos>=x1+1&&sp[k].pos<=y1+1)
  29. eff=sp[k].eff_gt+eff;
  30. d=cs[y1+1]-cs[x1]+eff;
  31. temp[m++]=d;
  32. }
  33. else if(act[0]=='G')
  34. {
  35. sp[j].eff_gt=sp[j].eff_gt+y1;
  36. sp[j++].pos=x1+1;
  37. }
  38. else if(act[0]=='T')
  39. {
  40. sp[j].eff_gt=sp[j].eff_gt-y1;
  41. sp[j++].pos=x1+1;
  42. }
  43. }
  44. for(i=0;i<m;i++)
  45. printf("%lld\n",temp[i]);
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0s 2684KB
stdin
5 3
1000 1002 1003 1004 1005
S 0 2
G 0 3
S 0 2
stdout
3005
3008