fork download
  1.  
  2. /*
  3. Creator : t-rex-007
  4. */
  5.  
  6. //Find index element after performing rotation queries
  7. #include<bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. int find_element(int arr[], int rot, int range[][2], int index){
  12. int left, right;
  13. for (int i = rot - 1; i >= 0; i--){
  14. left = range[i][0];
  15. right = range[i][1];
  16.  
  17. if (left <= index && right >= index){
  18. if (index == left)
  19. index = right;
  20. else
  21. index--;
  22. }
  23. }
  24.  
  25. return arr[index];
  26. }
  27.  
  28. int main(){
  29. int arr[] = {1,2,3,4,5};
  30. int rot = 2, index = 1, ele;
  31. int range[rot][2] = {{0,2}, {0,3}};
  32.  
  33. ele = find_element(arr, rot, range, index);
  34. cout << ele <<endl;
  35. return 0;
  36. }
Success #stdin #stdout 0s 4324KB
stdin
Standard input is empty
stdout
3