fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int dolek[100001];
  6.  
  7. void symuluj(int a, int n) {
  8. int ile = 1;
  9. while (true) {
  10. if (a + dolek[a] > n)
  11. break;
  12.  
  13. a += dolek[a];
  14. ile ++;
  15. }
  16.  
  17. cout << a << ' ' << ile << '\n';
  18. }
  19.  
  20. int main() {
  21. ios_base::sync_with_stdio(0);
  22. cin.tie(0); cout.tie(0);
  23.  
  24. int n, q;
  25. cin >> n >> q;
  26.  
  27. for (int i = 1; i <= n; i ++)
  28. cin >> dolek[i];
  29.  
  30. while (q --) {
  31. int a, b, c;
  32. cin >> a;
  33.  
  34. if (a == 1) {
  35. cin >> b;
  36. symuluj(b, n);
  37. }
  38. else {
  39. cin >> b >> c;
  40. dolek[b] = c;
  41. }
  42. }
  43. }
Success #stdin #stdout 0.01s 5476KB
stdin
6 4
2 6 2 2 1 3
1 2
1 1
0 5 2
1 1
stdout
2 1
6 4
5 3