Advertisement
YEZAELP

PROG-1072: number

Jun 15th, 2021
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int N = 5e5;
  5. int ar[N+10];
  6. int st = 1, n, re = 1;
  7.  
  8. int Index(int k){
  9.     int idx = (st + ((re) * (k - 1) + n - 1) % n) + 1;
  10.     if(idx > n) idx %= n;
  11.     return idx;
  12. }
  13.  
  14. int main(){
  15.  
  16.     int m;
  17.     scanf("%d%d", &n, &m);
  18.  
  19.     for(int i=1;i<=n;i++) scanf("%d", &ar[i]);
  20.  
  21.     for(int i=1;i<=m;i++){
  22.         char opr;
  23.         scanf(" %c", &opr);
  24.         if(opr == 'a'){
  25.             int x, y;
  26.             scanf("%d%d", &x, &y);
  27.             swap( ar[ Index(x) ] , ar[ Index(y) ] );
  28.         }
  29.         else if(opr == 'b'){
  30.             int x, k;
  31.             scanf("%d%d", &x, &k);
  32.             ar[ Index(x) ] = k;
  33.         }
  34.         else if(opr == 'c'){
  35.             int k;
  36.             scanf("%d", &k);
  37.             st = Index(k);
  38.             re = re * (-1);
  39.         }
  40.         else if(opr == 'q'){
  41.             int x;
  42.             scanf("%d", &x);
  43.             printf("%d\n", ar[ Index(x) ]);
  44.         }
  45.     }
  46.  
  47.     return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement