結果
問題 | No.1097 Remainder Operation |
ユーザー |
|
提出日時 | 2020-09-24 16:36:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,301 bytes |
コンパイル時間 | 1,780 ms |
コンパイル使用メモリ | 177,104 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 04:58:56 |
合計ジャッジ時間 | 5,302 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 WA * 4 |
ソースコード
#include <algorithm>#include <bits/stdc++.h>using namespace std;#define rep(i, n) for (int i = 0; i < (int)(n); i++)#define all(x) (x).begin(), (x).end()#define ll long long#define ld long double#define INF 1000000000000000000typedef pair<ll, ll> pll;int main() {cin.tie(0);ios::sync_with_stdio(false);int N;cin >> N;vector<ll> A(N);rep(i, N) { cin >> A[i]; }ll X = 0;map<ll, bool> ma1, ma2;ll cnt = 0, e = 0;bool judge = 0;vector<ll> v, vv;while (1) {ll r = X % N;if (ma1[A[r]]) {judge = 1;}if (judge && ma2[A[r]]) {break;}if (!judge)ma1[A[r]] = true, v.push_back(A[r]);if (judge)ma2[A[r]] = true, vv.push_back(A[r]);X += A[r];}rep(i, v.size() - 1) { v[i + 1] += v[i]; }rep(i, vv.size()) { vv[i + 1] += vv[i]; }int Q;cin >> Q;rep(i, Q) {ll q;cin >> q;q--;if (q < (ll)v.size()) {cout << v[q] << endl;} else {q -= v.size();ll ans = v.back();ans += (q / (ll)vv.size()) * vv.back();ans += vv[(q % (ll)vv.size())];cout << ans << endl;}}}