fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5.  
  6.  
  7. #define FAST std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr);
  8.  
  9.  
  10. int main() {
  11.  
  12. int t; cin>>t;
  13. while(t--) {
  14. int n; cin>>n;
  15. ll temp;
  16. map<ll,ll> pos;
  17. for(int i = 0;i<n;i++) {
  18. cin>>temp;
  19. pos[temp] =i;
  20. }
  21. ll result = 0;
  22. int q; cin>>q;
  23. while(q--) {
  24. ll type; cin>>type;
  25. if(type == 1) {
  26. ll k; cin>>k;
  27. result +=k;
  28. }
  29. else {
  30. ll x; cin>>x;
  31. auto it = pos.find(x);
  32. ll ans = -2;
  33. if(it!=pos.end()) {
  34. ans = it->second+result;
  35. ans%=n;
  36. ans+=n;
  37. ans%=n;
  38. }
  39. cout<<ans+1<<endl;
  40. }
  41. }
  42.  
  43. }
  44. return 0;
  45. }
Success #stdin #stdout 0s 5284KB
stdin
2
7
1 2 3 4 5 6 7
7
2 9
1 2
2 4
1 -2
2 3
1 -5
2 6
2
1 2
1
2 2
stdout
-1
6
3
1
2