結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー 👑 emthrmemthrm
提出日時 2022-10-14 22:20:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 260 ms / 6,000 ms
コード長 2,906 bytes
コンパイル時間 4,120 ms
コンパイル使用メモリ 212,244 KB
実行使用メモリ 19,452 KB
最終ジャッジ日時 2023-09-08 22:19:05
合計ジャッジ時間 20,933 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 108 ms
11,112 KB
testcase_04 AC 180 ms
12,096 KB
testcase_05 AC 103 ms
11,092 KB
testcase_06 AC 164 ms
11,580 KB
testcase_07 AC 182 ms
12,484 KB
testcase_08 AC 176 ms
11,936 KB
testcase_09 AC 86 ms
7,948 KB
testcase_10 AC 80 ms
7,508 KB
testcase_11 AC 130 ms
11,452 KB
testcase_12 AC 132 ms
11,316 KB
testcase_13 AC 89 ms
7,968 KB
testcase_14 AC 98 ms
7,896 KB
testcase_15 AC 205 ms
13,536 KB
testcase_16 AC 159 ms
11,576 KB
testcase_17 AC 70 ms
7,144 KB
testcase_18 AC 259 ms
19,348 KB
testcase_19 AC 260 ms
19,216 KB
testcase_20 AC 255 ms
19,288 KB
testcase_21 AC 254 ms
19,228 KB
testcase_22 AC 258 ms
19,284 KB
testcase_23 AC 255 ms
19,288 KB
testcase_24 AC 256 ms
19,352 KB
testcase_25 AC 254 ms
19,352 KB
testcase_26 AC 256 ms
19,296 KB
testcase_27 AC 255 ms
19,228 KB
testcase_28 AC 253 ms
19,232 KB
testcase_29 AC 254 ms
19,220 KB
testcase_30 AC 251 ms
19,352 KB
testcase_31 AC 252 ms
19,204 KB
testcase_32 AC 253 ms
19,356 KB
testcase_33 AC 231 ms
19,212 KB
testcase_34 AC 234 ms
19,324 KB
testcase_35 AC 233 ms
19,452 KB
testcase_36 AC 234 ms
19,200 KB
testcase_37 AC 232 ms
19,228 KB
testcase_38 AC 64 ms
8,920 KB
testcase_39 AC 108 ms
9,048 KB
testcase_40 AC 191 ms
19,288 KB
testcase_41 AC 2 ms
4,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Abelian>
struct FenwickTree {
  explicit FenwickTree(const int n, const Abelian ID = 0)
      : n(n), ID(ID), data(n, ID) {}

  void add(int idx, const Abelian val) {
    for (; idx < n; idx |= idx + 1) {
      data[idx] += val;
    }
  }

  Abelian sum(int idx) const {
    Abelian res = ID;
    for (--idx; idx >= 0; idx = (idx & (idx + 1)) - 1) {
      res += data[idx];
    }
    return res;
  }

  Abelian sum(const int left, const int right) const {
    return left < right ? sum(right) - sum(left) : ID;
  }

  Abelian operator[](const int idx) const { return sum(idx, idx + 1); }

  int lower_bound(Abelian val) const {
    if (val <= ID) return 0;
    int res = 0, exponent = 1;
    while (exponent <= n) exponent <<= 1;
    for (int mask = exponent >> 1; mask > 0; mask >>= 1) {
      const int idx = res + mask - 1;
      if (idx < n && data[idx] < val) {
        val -= data[idx];
        res += mask;
      }
    }
    return res;
  }

 private:
  const int n;
  const Abelian ID;
  std::vector<Abelian> data;
};

int main() {
  int n; cin >> n;
  FenwickTree<ll> bit(n);
  FenwickTree<int> num(n);
  vector<tuple<int, int, int>> queries;
  REP(i, n) {
    int a, t; cin >> a >> t;
    bit.add(i, a);
    queries.emplace_back(t, 0, i);
    queries.emplace_back(t + a, 1, i);
  }
  int q; cin >> q;
  vector<int> l(q), r(q);
  REP(i, q) {
    int d; cin >> d >> l[i] >> r[i]; --l[i]; --r[i];
    queries.emplace_back(d, 2, i);
  }
  sort(ALL(queries));
  vector<ll> ans(q);
  for (const auto& [d, type, i] : queries) {
    if (type == 0) {
      bit.add(i, d - 1);
      num.add(i, 1);
    } else if (type == 1) {
      bit.add(i, -bit[i]);
      num.add(i, -1);
    } else if (type == 2) {
      // cout << '[' << d << "]\n";
      // REP(j, n) cout << bit[j] << " \n"[j + 1 == n];
      // REP(j, n) cout << num[j] << " \n"[j + 1 == n];
      ans[i] = bit.sum(l[i], r[i] + 1) - 1LL * num.sum(l[i], r[i] + 1) * d;
    }
  }
  REP(i, q) cout << ans[i] << '\n';
  return 0;
}
0