結果
問題 | No.1097 Remainder Operation |
ユーザー |
![]() |
提出日時 | 2020-05-23 00:26:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 225 ms / 2,000 ms |
コード長 | 816 bytes |
コンパイル時間 | 1,809 ms |
コンパイル使用メモリ | 171,472 KB |
実行使用メモリ | 5,608 KB |
最終ジャッジ日時 | 2024-11-22 16:11:29 |
合計ジャッジ時間 | 6,303 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){int N;cin >> N;vector<int> A(N);for (int i = 0; i < N; i++){cin >> A[i];}vector<int> B(N);for (int i = 0; i < N; i++){B[i] = (i + A[i]) % N;}vector<int> ord(N, -1);vector<long long> S(1, 0);int c = 0;int l = 0;int curr = 0;while (1){if (ord[curr] == -1){ord[curr] = S.size() - 1;S.push_back(S.back() + A[curr]);curr = B[curr];} else {c = S.size() - ord[curr] - 1;l = ord[curr];break;}}int Q;cin >> Q;long long CS = S[l + c] - S[l];for (int i = 0; i < Q; i++){long long K;cin >> K;if (K <= l){cout << S[K] << endl;} else {cout << S[l] + (K - l) / c * CS + S[l + (K - l) % c] - S[l] << endl;}}}