Cod sursa(job #2901655)
| Utilizator | Data | 14 mai 2022 01:42:18 | |
|---|---|---|---|
| Problema | Stramosi | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("stramosi.in");
ofstream fout("stramosi.out");
int v[18][250017];
int main()
{
int N, M;
fin>>N>>M;
for(int i = 1; i<=N; i++)
fin>>v[0][i];
for(int i = 1; i<18; i++)
for(int j = 1; j<=N; j++){
v[i][j] = v[i-1][v[i-1][j]];
}
for(int i = 1; i<=M; i++){
int poz, stra, pow = 0;
fin>>poz>>stra;
while(stra){
if(stra%2!=0)
poz = v[pow][poz];
pow++;
stra = stra/2;
}
fout<<poz<<"\n";
}
}
