#include #include using namespace std; using namespace atcoder; using usize = ::std::size_t; //using u64 = ::std::int_least64_t; using u64 = long long; static constexpr u64 Inf = ::std::numeric_limits::max() / 2; int N; struct Doubling { const int LOG; vector< vector< int > > table; Doubling(int sz, int64_t lim_t) : LOG(64 - __builtin_clzll(lim_t)) { table.assign(LOG, vector< int >(sz, -1)); } void set_next(int k, int x) { table[0][k] = x; } void build() { for(int k = 0; k + 1 < LOG; k++) { for(int i = 0; i < table[k].size(); i++) { if(table[k][i] == -1) table[k + 1][i] = -1; else table[k + 1][i] = table[k][i] + table[k][(i + table[k][i]) % N]; } } } int query(int k, int64_t t) { int sum = k + 1; for(int i = LOG - 1; i >= 0; i--) { if((t >> i) & 1) { sum += table[i][k]; k = (k + table[i][k])%N; } } return sum; } }; int main(int argc, char *argv[]) { /*std::ifstream in("in.txt"); std::cin.rdbuf(in.rdbuf());*/ cin.tie(0); ios::sync_with_stdio(false); int K; cin >> N >> K; vector P(N); for (int i = 0; i < N; i++) { cin >> P[i]; } Doubling doubling(N, 1e10); for (int i = 0; i < N; i++) { doubling.set_next(i, P[i]); } doubling.build(); for (int i = 0; i < N; i++) { cout << doubling.query(i, K) << endl; } return 0; }