Skip to content

Instantly share code, notes, and snippets.

@theortsac
Created July 2, 2023 17:52
Show Gist options
  • Save theortsac/3b4d579f2f6c0aa99377244b021a9adb to your computer and use it in GitHub Desktop.
Save theortsac/3b4d579f2f6c0aa99377244b021a9adb to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int MAXLOG = 30;
int prox[MAXLOG + 1][MAXN];
int main() {
int n, q;
cin >> n >> q; // só usaremos o valor q no futuro
for (int x = 1; x <= n; x++) {
cin >> prox[0][x];
}
for (int i = 1; i <= MAXLOG; i++) {
for (int x = 1; x <= n; x++) {
prox[i][x] = prox[i-1][[prox[i-1][x]];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment