Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.002 s | 0 KBi |
#2 |
Correcto
|
0.003 s | 0 KBi |
#3 |
Correcto
|
0.004 s | 0 KBi |
#4 |
Correcto
|
0.002 s | 0 KBi |
#5 |
Correcto
|
0.004 s | 0 KBi |
#6 |
Correcto
|
0.13 s | 52 KBi |
#7 |
Correcto
|
0.214 s | 53 KBi |
#8 |
Correcto
|
0.002 s | 0 KBi |
#9 |
Correcto
|
0.002 s | 0 KBi |
#10 |
Correcto
|
0.002 s | 0 KBi |
#11 |
Correcto
|
0.004 s | 0 KBi |
#12 |
Correcto
|
0.03 s | 6 KBi |
#13 |
Correcto
|
0.01 s | 6 KBi |
#14 |
Correcto
|
0.053 s | 5 KBi |
#15 |
Correcto
|
0.014 s | 5 KBi |
#16 |
Correcto
|
0.014 s | 6 KBi |
#17 |
Correcto
|
0.002 s | 0 KBi |
#18 |
Correcto
|
0.002 s | 0 KBi |
#19 |
Correcto
|
0.007 s | 30 KBi |
#20 |
Correcto
|
0.002 s | 0 KBi |
#21 |
Correcto
|
0.921 s | 52 KBi |
#22 |
Tiempo límite excedido
|
1.087 s | 52 KBi |
#23 |
Correcto
|
0.799 s | 52 KBi |
#24 |
Correcto
|
0.561 s | 53 KBi |
#25 |
Tiempo límite excedido
|
1.051 s | 58 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 = 1e4 + 1; int main() { fast_io; lli n, r; cin >> n >> r; const lli LOG2 = 62; vector<vector<lli>> jump(n, vector<lli>(LOG2, -1)); 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 << '\n'; return 0; }