fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(0);
  7.  
  8. int N, Q;
  9. cin >> N >> Q;
  10. vector<int> A(N);
  11. for(int i=0;i<N;i++) cin >> A[i];
  12.  
  13. for(int q=0;q<Q;q++){
  14. int S,T,P;
  15. cin >> S >> T >> P;
  16. S--; T--; // 0-indexed
  17. int plate = P;
  18. int pos = S;
  19. while(true){
  20. if(plate < A[pos]) swap(plate,A[pos]);
  21. if(pos == T) break;
  22. pos = (pos+1)%N; // 반시계 방향 원형 이동
  23. }
  24. cout << plate << "\n";
  25. }
  26. }
Success #stdin #stdout 0.01s 5276KB
stdin
10 10
19
5
8
17
14
3
9
10
7
6
1 8 4
7 3 2
5 9 10
4 8 3
10 3 6
8 7 4
6 6 3
2 9 12
6 3 7
9 6 3
stdout
19
10
14
17
8
10
3
12
7
9