結果

問題 No.1097 Remainder Operation
ユーザー SSRSSSRS
提出日時 2020-05-24 17:40:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,075 bytes
コンパイル時間 2,494 ms
コンパイル使用メモリ 186,564 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-02 05:14:54
合計ジャッジ時間 4,947 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 39 ms
5,376 KB
testcase_18 AC 35 ms
5,628 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
int main(){
  //想定TLE
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  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] << "\n";
    } else {
      long long tmp = S[l] + (K - l) / c * CS;
      long long ub = l + (K - l) % c;
      for (int j = l; j <= ub; j++){
        tmp += S[j];
      }
      cout << tmp << "\n";
    }
  }
}
0