fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MaxN=6e5;
  5. const int MaxM=2e5;
  6. int arr[MaxN];
  7. int main() {
  8. int pS[MaxM]={};
  9. int N,Q;
  10. cin >> N>>Q;
  11. int start=2e5;
  12. for(int i=start;i<start+N;i++){
  13. cin >> arr[i];
  14. }
  15. int num;
  16. while(Q--){
  17. cin >> num;
  18. if(num==1){
  19. int temp=arr[start];
  20. arr[start]=0;
  21. arr[start+N]=temp;
  22. start++;
  23. }else if(num==2){
  24. int temp=arr[start+N-1];
  25. arr[start+N-1]=0;
  26. arr[start-1]=temp;
  27. start--;
  28. }else if(num==3){
  29.  
  30. }else{
  31.  
  32. }
  33. }
  34. for(int i=start;i<start+N;i++){
  35. cout << arr[i] << ' ';
  36. }
  37. }
Success #stdin #stdout 0s 5324KB
stdin
5 2
1 0 1 1 1
2
2
3 1 4 2
1
3 4 5 2
4 1 4
4 2 5
stdout
1 1 1 0 1