Cod sursa(job #2720125)
| Utilizator | Data | 10 martie 2021 16:54:26 | |
|---|---|---|---|
| Problema | Stramosi | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
const int NMAX = 250001;
const int KMAX = 21;
int n, m, dp[KMAX][NMAX];
int main() {
f >> n >> m;
for(int i = 1;i <= n;++i)
f >> dp[1][i];
for(int i = 2;i <= KMAX;++i)
for(int j = 1;j <= n;++j)
dp[i][j] = dp[i - 1][ dp[i - 1][j] ];
for(;m--;) {
int x, y;
f >> x >> y;
g << dp[y][x] << '\n';
}
return 0;
}
