結果
問題 | No.1097 Remainder Operation |
ユーザー | itohdak |
提出日時 | 2020-07-03 14:31:59 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 238 ms / 2,000 ms |
コード長 | 1,477 bytes |
コンパイル時間 | 1,733 ms |
コンパイル使用メモリ | 173,240 KB |
実行使用メモリ | 69,244 KB |
最終ジャッジ日時 | 2023-10-14 23:30:50 |
合計ジャッジ時間 | 7,449 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 1 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,352 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 11 ms
8,408 KB |
testcase_08 | AC | 11 ms
8,508 KB |
testcase_09 | AC | 11 ms
8,400 KB |
testcase_10 | AC | 11 ms
8,516 KB |
testcase_11 | AC | 11 ms
8,460 KB |
testcase_12 | AC | 125 ms
69,124 KB |
testcase_13 | AC | 149 ms
69,180 KB |
testcase_14 | AC | 147 ms
69,228 KB |
testcase_15 | AC | 165 ms
69,244 KB |
testcase_16 | AC | 137 ms
69,192 KB |
testcase_17 | AC | 107 ms
69,136 KB |
testcase_18 | AC | 95 ms
69,120 KB |
testcase_19 | AC | 117 ms
69,244 KB |
testcase_20 | AC | 115 ms
69,240 KB |
testcase_21 | AC | 236 ms
69,220 KB |
testcase_22 | AC | 238 ms
69,192 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,n-1,0) #define all(v) v.begin(), v.end() const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; class Doubling { public: int N; int logK; vector<vector<pair<int, ll>>> next; Doubling(int N, vector<int>& ini, vector<ll>& A, ll K) { logK = log2(K); next = vector<vector<pair<int, ll>>>(logK+1, vector<pair<int, ll>>(N)); rep(i, N) { next[0][i].first = ini[i]; next[0][i].second = A[i]; } rep(k, logK) { rep(i, N) { next[k+1][i].first = next[k][next[k][i].first].first; next[k+1][i].second = next[k][i].second + next[k][next[k][i].first].second; } } } pair<int, ll> query(int p, ll q) { ll sum = 0; for(int k=logK; k>=0; k--) { if(p == -1) break; if((q>>k)&1) { sum += next[k][p].second; p = next[k][p].first; } } return make_pair(p, sum); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<ll> A(N); rep(i, N) cin >> A[i]; int Q; cin >> Q; vector<ll> K(Q); rep(i, Q) cin >> K[i]; vector<int> ini(N); rep(i, N) ini[i] = (i+A[i])%N; Doubling db(N, ini, A, *max_element(all(K))); rep(i, Q) cout << db.query(0, K[i]).second << "\n"; return 0; }