Cod sursa(job #2574068)
| Utilizator | Data | 5 martie 2020 20:12:09 | |
|---|---|---|---|
| Problema | Stramosi | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
int n,m,i,x,k,stramos,pas,t,dp[250100][18];
int main()
{
f>>n>>m;
for(i=1;i<=n;i++)
{
f>>x;
dp[i][0]=x;
}
for(k=1;(1<<k)<=n;k++)
{
for(i=1;i<=n;i++)
{
dp[i][k]=dp[dp[i][k-1]][k-1];
}
}
for(i=1;i<=m;i++)
{
f>>stramos>>t;
pas=0;
while(t)
{
if(t%2==1)stramos=dp[stramos][pas];
pas++;
t/=2;
}
g<<stramos<<'\n';
}
return 0;
}
