結果

問題 No.1097 Remainder Operation
ユーザー risujirohrisujiroh
提出日時 2020-06-26 21:50:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,042 bytes
コンパイル時間 2,470 ms
コンパイル使用メモリ 202,176 KB
実行使用メモリ 5,396 KB
最終ジャッジ日時 2023-09-18 04:09:37
合計ジャッジ時間 4,379 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 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 37 ms
4,384 KB
testcase_18 AC 34 ms
4,908 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

struct dsu {
  int cc;
  vector<int> p, sz;
  dsu(int n = 0) : cc(n), p(n, -1), sz(n, 1) {}
  int root(int v) const {
    while (p[v] != -1) v = p[v];
    return v;
  }
  bool unite(int u, int v) {
    u = root(u), v = root(v);
    if (u == v) return false;
    --cc;
    if (sz[u] < sz[v]) swap(u, v);
    p[v] = u;
    sz[u] += sz[v];
    return true;
  }
  bool same(int u, int v) const { return root(u) == root(v); }
  int size(int v) const { return sz[root(v)]; }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& e : a) cin >> e;
  dsu d(n);
  for (int i = 0; i < n; ++i) {
    d.unite(i, (i + a[i]) % n);
  }
  int k = d.size(0);
  vector<long long> b(k + 1);
  for (int t = 0; t < k; ++t) {
    b[t + 1] = b[t] + a[b[t] % n];
  }
  int q;
  cin >> q;
  while (q--) {
    long long m;
    cin >> m;
    cout << m / k * b[k] + b[m % k] << '\n';
  }
}
0