Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.001 s | 0 KBi |
#2 |
Correcto
|
0.004 s | 0 KBi |
#3 |
Correcto
|
0.002 s | 0 KBi |
#4 |
Correcto
|
0.001 s | 0 KBi |
#5 |
Correcto
|
0.004 s | 0 KBi |
#6 |
Correcto
|
0.138 s | 52 KBi |
#7 |
Correcto
|
0.134 s | 52 KBi |
#8 |
Correcto
|
0.001 s | 0 KBi |
#9 |
Correcto
|
0.003 s | 0 KBi |
#10 |
Correcto
|
0.001 s | 0 KBi |
#11 |
Correcto
|
0.001 s | 0 KBi |
#12 |
Correcto
|
0.009 s | 6 KBi |
#13 |
Correcto
|
0.013 s | 6 KBi |
#14 |
Correcto
|
0.016 s | 5 KBi |
#15 |
Correcto
|
0.013 s | 5 KBi |
#16 |
Correcto
|
0.043 s | 6 KBi |
#17 |
Correcto
|
0.003 s | 0 KBi |
#18 |
Correcto
|
0.001 s | 0 KBi |
#19 |
Correcto
|
0.001 s | 0 KBi |
#20 |
Correcto
|
0.003 s | 0 KBi |
#21 |
Correcto
|
0.8 s | 52 KBi |
#22 |
Tiempo límite excedido
|
1.062 s | 52 KBi |
#23 |
Correcto
|
0.686 s | 53 KBi |
#24 |
Correcto
|
0.57 s | 52 KBi |
#25 |
Tiempo límite excedido
|
1.081 s | 52 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; int jump[N][LOG2]; int go(int u, lli R, vector<vector<lli>> &jump){ int ans = u; for(int i = 0;R;R >>= 1, i++){ if(R & 1){ ans = jump[ans][i]; } } return ans; } int main() { fast_io; lli n, r; cin >> n >> r; lli v; vector<vector<lli>> jump(n, vector<lli>(LOG2, -1)); 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]; } } vi ans(n); REP(i, n) { lli pos = go(i, r, jump); ans[pos] = i + 1; } cout << ans << endl; return 0; }