fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int N,Q;
  6. cin >> N>>Q;
  7. deque<long long int> D;
  8. long long int arr[N];
  9. long long int K;
  10. for(int i=0;i<N;i++){
  11. cin >>K;
  12. D.push_back(K);
  13. }
  14. long long int num;
  15. while(Q--){
  16. cin >> num;
  17. if(num==1){
  18. long long int temp=D.front();
  19. D.pop_front();
  20. D.push_back(temp);
  21. }else if(num==2){
  22. long long int temp=D.back();
  23. D.pop_back();
  24. D.push_front(temp);
  25. }else if(num==3){
  26. int a,b,c;
  27. cin>>a>>b>>c;
  28. for(int i=0;i<N;i++){
  29. arr[i]=D.front();
  30. D.pop_front();
  31. if(a<=i+1 && i+1<=b){
  32. arr[i]+=c;
  33. }
  34. D.push_back(arr[i]);
  35. }
  36. }else{
  37. int a,b;
  38. cin>>a>>b;
  39. long long int ans=0;
  40. for(int i=0;i<N;i++){
  41. arr[i]=D.front();
  42. D.pop_front();
  43. if(a<=i+1 && i+1<=b){
  44. ans+=arr[i];
  45. }
  46. D.push_back(arr[i]);
  47. }cout <<ans<< '\n';
  48. }
  49. }
  50. }
Success #stdin #stdout 0s 5328KB
stdin
3 5
1 2 3
4 1 3
1
4 1 3
2
4 1 3
stdout
6
6
6