13E - Holes - CodeForces Solution


data structures dsu *2700

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
using I=int;
using B=bool;
const I N=1e5;
I a_arr[N];
tuple<I,I,I>jmps[N];
I siz;
I n;
void upd(I i){
  I low=i*siz,upp=min((i+1)*siz,n);
  for(I j=upp-1;j>=low;j--){
    I k=j+a_arr[j];
    if(k>=upp){jmps[j]={k,j,1};continue;}
    auto[x,y,z]=jmps[k];
    jmps[j]={x,y,z+1};
  }
}
pair<I,I>qry(I i){
  I res1=i,res2=0;
  while(i<n){
    auto[x,y,z]=jmps[i];
    i=x,res1=y,res2+=z;
  }
  return{res1,res2};
}
I main(){
  cin.tie(0)->sync_with_stdio(0);
  I m;cin>>n>>m;
  for(I i=0;i<n;i++)cin>>a_arr[i];
  siz=sqrt(n);
  for(I i=0;i<(n+siz-1)/siz;i++)upd(i);
  while(m--){
    I t;cin>>t;
    if(t==0){
      I a,b;cin>>a>>b,a--;
      a_arr[a]=b,upd(a/siz);
    }
    if(t==1){
      I a;cin>>a,a--;
      auto[res1,res2]=qry(a);
      printf("%i %i\n",res1+1,res2);
    }
  }
}


Comments

Submit
0 Comments
More Questions

450A - Jzzhu and Children
546A - Soldier and Bananas
32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima
41A - Translation
1559A - Mocha and Math
832A - Sasha and Sticks
292B - Network Topology
1339A - Filling Diamonds
910A - The Way to Home
617A - Elephant
48A - Rock-paper-scissors
294A - Shaass and Oskols
1213A - Chips Moving
490A - Team Olympiad
233A - Perfect Permutation
1360A - Minimal Square
467A - George and Accommodation
893C - Rumor
227B - Effective Approach
1534B - Histogram Ugliness
1611B - Team Composition Programmers and Mathematicians
110A - Nearly Lucky Number
1220B - Multiplication Table
1644A - Doors and Keys
1644B - Anti-Fibonacci Permutation
1610A - Anti Light's Cell Guessing
349B - Color the Fence
144A - Arrival of the General