結果

問題 No.885 アマリクエリ
ユーザー keijakkeijak
提出日時 2021-05-23 16:41:59
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 307 ms / 2,000 ms
コード長 1,626 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 119,552 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 02:27:04
合計ジャッジ時間 2,732 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 307 ms
5,248 KB
testcase_01 AC 69 ms
5,376 KB
testcase_02 AC 32 ms
5,376 KB
testcase_03 AC 24 ms
5,376 KB
testcase_04 AC 25 ms
5,376 KB
testcase_05 AC 18 ms
5,376 KB
testcase_06 AC 17 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 12 ms
5,376 KB
testcase_09 AC 74 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <type_traits>
#include <vector>

#define REP_(i, a_, b_, a, b, ...) \
  for (int i = (a), END_##i = (b); i < END_##i; ++i)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
using i64 = long long;

struct Input {
  inline operator int() { return read_int<int>(); }
  inline operator long long() { return read_int<long long>(); }
  inline operator unsigned() { return read_int<unsigned>(); }

 private:
  template <typename T>
  static T read_int() {
    T ret = 0, sgn = 1;
    int ch = getchar_unlocked();
    while (isspace(ch)) {
      ch = getchar_unlocked();
    }
    if constexpr (!std::is_unsigned<T>::value) {
      if (ch == '-') {
        sgn = -1;
        ch = getchar_unlocked();
      }
    }
    for (; ('0' <= ch) & (ch <= '9'); ch = getchar_unlocked()) {
      ret = (ret * 10) + (ch - '0');
    }
    ungetc(ch, stdin);
    if constexpr (std::is_unsigned<T>::value) {
      return ret;
    } else {
      return ret * sgn;
    }
  }
} input;

using namespace std;

int main() {
  const int n = input;
  vector<int> a(n);
  REP(i, n) a[i] = input;
  const int Q = input;
  vector<int> X(Q);
  REP(i, Q) X[i] = input;
  REP(i, 1, Q) { X[i] = min(X[i], X[i - 1]); }
  vector<i64> ans(Q + 1, 0);
  REP(i, n) {
    int p = a[i];
    int j = 0;
    while (true) {
      int q = lower_bound(X.begin() + j, X.end(), p, greater{}) - X.begin();
      ans[j] += p;
      ans[q] -= p;
      if (q == Q) break;
      p %= X[j];
      j = q;
    }
  }
  REP(i, 1, Q) { ans[i] += ans[i - 1]; }
  REP(i, Q) { printf("%lld\n", ans[i]); }
}
0