結果
| 問題 | No.1097 Remainder Operation |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-08 17:27:58 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1,084 ms / 2,000 ms |
| + 17µs | |
| コード長 | 1,172 bytes |
| 記録 | |
| コンパイル時間 | 2,972 ms |
| コンパイル使用メモリ | 355,932 KB |
| 実行使用メモリ | 9,860 KB |
| 最終ジャッジ日時 | 2026-10-08 17:28:10 |
| 合計ジャッジ時間 | 8,638 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
// WRONG #12 (LINEAR_REM_WALK): answers are correct, but each query walks the
// remaining (K-mu)%lam steps one by one -> O(Q * cycle length) = TLE.
// Input: T, then T cases of (N / A / Q / K_1..K_Q).
// Needs: big cycle (~1e5) and Q ~ 1e5 with random K up to 1e12.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static void solve() {
int n; scanf("%d", &n);
vector<ll> a(n);
for (auto &x : a) scanf("%lld", &x);
vector<int> seen(n, -1), path;
vector<ll> pre(1, 0);
int r = 0, steps = 0;
while (seen[r] == -1) {
seen[r] = steps;
path.push_back(r);
pre.push_back(pre.back() + a[r]);
steps++;
r = pre[steps] % n;
}
int mu = seen[r], lam = steps - mu;
ll S = pre[steps] - pre[mu];
int q; scanf("%d", &q);
while (q--) {
ll k; scanf("%lld", &k);
if (k <= steps) { printf("%lld\n", pre[k]); continue; }
ll t = k - mu, full = t / lam, rem = t % lam;
ll ans = pre[mu] + full * S;
for (ll i = 0; i < rem; i++) ans += a[path[mu + i]]; // BUG: O(rem) per query
printf("%lld\n", ans);
}
}
int main() {
solve();
}