fork download
  1. const int MAX_N = 1e5 + 5;
  2. const int BLOCK_SIZE = 350;
  3.  
  4. int last[MAX_N];
  5. int cnt[MAX_N];
  6. int a[MAX_N];
  7. int n, m;
  8.  
  9. void update(int i){
  10. int nextPos = i + a[i];
  11. if(nextPos > n)
  12. last[i] = i,
  13. cnt[i] = 0;
  14. else if(i / BLOCK_SIZE == nextPos / BLOCK_SIZE)
  15. last[i] = last[nextPos],
  16. cnt[i] = cnt[nextPos] + 1;
  17. else
  18. last[i] = nextPos,
  19. cnt[i] = 1;
  20. }
  21.  
  22. int main(){
  23. ios_base::sync_with_stdio(0);
  24. cin.tie(0); cout.tie(0);
  25.  
  26. cin >> n >> m;
  27.  
  28. for(int i = 1; i <= n; i++)
  29. cin >> a[i];
  30.  
  31. for(int i = n; i >= 1; i--)
  32. update(i);
  33.  
  34. while(m--){
  35. int query;
  36. cin >> query;
  37.  
  38. if(query == 1){
  39. int x;
  40. cin >> x;
  41.  
  42. int cntJump = 0;
  43.  
  44. while(last[x] != x){
  45. // lastPos = last[x];
  46. cntJump += cnt[x];
  47. x = last[x];
  48. }
  49.  
  50. while(x + a[x] <= n){
  51. cntJump++;
  52. // lastPos = x + a[x];
  53. x = x + a[x];
  54. }
  55. cout << x << " " << cntJump + 1 << '\n';
  56. }
  57.  
  58. else{
  59. int x, y;
  60. cin >> x >> y;
  61. a[x] = y;
  62. // update(x);
  63. for(int i = x; i >= 1 && i / BLOCK_SIZE == x / BLOCK_SIZE; i--)
  64. update(i);
  65. }
  66. }
  67.  
  68. return 0;
  69. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:23:3: error: ‘ios_base’ has not been declared
   ios_base::sync_with_stdio(0);
   ^~~~~~~~
prog.cpp:24:3: error: ‘cin’ was not declared in this scope
   cin.tie(0); cout.tie(0);
   ^~~
prog.cpp:24:3: note: suggested alternative: ‘main’
   cin.tie(0); cout.tie(0);
   ^~~
   main
prog.cpp:24:15: error: ‘cout’ was not declared in this scope
   cin.tie(0); cout.tie(0);
               ^~~~
prog.cpp:24:15: note: suggested alternative: ‘cnt’
   cin.tie(0); cout.tie(0);
               ^~~~
               cnt
stdout
Standard output is empty