Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 0 KBi |
#2 |
Correcto
|
0.001 s | 0 KBi |
#3 |
Correcto
|
0.001 s | 0 KBi |
#4 |
Correcto
|
0.001 s | 0 KBi |
#5 |
Correcto
|
0.004 s | 0 KBi |
#6 |
Correcto
|
0.145 s | 49 KBi |
#7 |
Correcto
|
0.087 s | 49 KBi |
#8 |
Correcto
|
0.002 s | 0 KBi |
#9 |
Correcto
|
0.002 s | 0 KBi |
#10 |
Correcto
|
0.001 s | 0 KBi |
#11 |
Correcto
|
0.009 s | 2 KBi |
#12 |
Correcto
|
0.013 s | 5 KBi |
#13 |
Correcto
|
0.006 s | 5 KBi |
#14 |
Correcto
|
0.021 s | 5 KBi |
#15 |
Correcto
|
0.019 s | 5 KBi |
#16 |
Correcto
|
0.005 s | 5 KBi |
#17 |
Correcto
|
0.002 s | 0 KBi |
#18 |
Correcto
|
0.006 s | 0 KBi |
#19 |
Correcto
|
0.002 s | 0 KBi |
#20 |
Correcto
|
0.004 s | 0 KBi |
#21 |
Correcto
|
0.245 s | 49 KBi |
#22 |
Correcto
|
0.309 s | 49 KBi |
#23 |
Correcto
|
0.92 s | 49 KBi |
#24 |
Correcto
|
0.206 s | 49 KBi |
#25 |
Correcto
|
0.558 s | 49 KBi |
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define pb push_back #define ff first #define ss second #define ii pair<int, int> #define vi vector<int> #define vii vector<ii> #define lli long long int #define fast_io \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); using namespace std; ostream &operator<<(ostream &os, const vector<int> &v) { for (auto const &i : v) { os << i << " "; } os << endl; return os; } const lli mod = (1e9) + 7; const int N = 1e5 + 5; const lli LOG2 = 62; lli jump[N][LOG2]; int main() { fast_io; lli n, r; cin >> n >> r; lli v; REP(u, n) { cin >> v; jump[u][0] = v; } for (lli j = 1; j < LOG2; j++) { for (lli u = 0; u < n; u++) { jump[u][j] = jump[jump[u][j - 1]][j - 1]; } } function<lli(lli, lli)> go = [&](lli u, lli R) { int ans = u; for(int i = 0;R;R >>= 1, i++){ if(R & 1){ ans = jump[ans][i]; } } return ans; }; vi ans(n); REP(i, n) { lli pos = go(i, r); ans[pos] = i + 1; } cout << ans << endl; return 0; }