結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー KudeKude
提出日時 2022-10-14 22:31:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 281 ms / 6,000 ms
コード長 1,605 bytes
コンパイル時間 4,451 ms
コンパイル使用メモリ 241,000 KB
実行使用メモリ 34,132 KB
最終ジャッジ日時 2023-09-08 22:39:46
合計ジャッジ時間 18,454 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 121 ms
20,180 KB
testcase_04 AC 203 ms
22,732 KB
testcase_05 AC 114 ms
19,620 KB
testcase_06 AC 175 ms
21,856 KB
testcase_07 AC 202 ms
23,852 KB
testcase_08 AC 190 ms
22,144 KB
testcase_09 AC 97 ms
14,092 KB
testcase_10 AC 89 ms
13,280 KB
testcase_11 AC 144 ms
18,044 KB
testcase_12 AC 142 ms
18,268 KB
testcase_13 AC 100 ms
13,516 KB
testcase_14 AC 102 ms
8,676 KB
testcase_15 AC 224 ms
24,608 KB
testcase_16 AC 175 ms
23,316 KB
testcase_17 AC 76 ms
9,796 KB
testcase_18 AC 270 ms
33,060 KB
testcase_19 AC 277 ms
33,408 KB
testcase_20 AC 272 ms
32,516 KB
testcase_21 AC 269 ms
32,668 KB
testcase_22 AC 277 ms
34,088 KB
testcase_23 AC 273 ms
34,132 KB
testcase_24 AC 281 ms
33,068 KB
testcase_25 AC 275 ms
32,676 KB
testcase_26 AC 274 ms
33,508 KB
testcase_27 AC 273 ms
33,912 KB
testcase_28 AC 279 ms
33,312 KB
testcase_29 AC 273 ms
32,880 KB
testcase_30 AC 277 ms
34,120 KB
testcase_31 AC 274 ms
32,612 KB
testcase_32 AC 272 ms
33,608 KB
testcase_33 AC 255 ms
32,460 KB
testcase_34 AC 242 ms
33,596 KB
testcase_35 AC 243 ms
32,608 KB
testcase_36 AC 239 ms
32,604 KB
testcase_37 AC 241 ms
33,528 KB
testcase_38 AC 61 ms
7,664 KB
testcase_39 AC 102 ms
9,928 KB
testcase_40 AC 187 ms
33,516 KB
testcase_41 AC 1 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

struct S { ll a, b; };
S op(S x, S y) { return {x.a + y.a, x.b + y.b}; }
S e() { return {0, 0}; }

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI a(n), t(n);
  vector<tuple<int, int, int, int>> qs;
  vector<S> init(n);
  rep(i, n) {
    int a, t;
    cin >> a >> t;
    init[i] = {0, a};
    qs.emplace_back(t, -n + i, a, 0);
    qs.emplace_back(t + a, -n + i, a, 0);
  }
  segtree<S, op, e> seg(init);
  int q;
  cin >> q;
  rep(i, q) {
    int d, l, r;
    cin >> d >> l >> r;
    l--;
    qs.emplace_back(d, i, l, r);
  }
  sort(all(qs));
  VL ans(q);
  for(auto [t, i, l, r]: qs) {
    if (i < 0) {
      i += n;
      if (seg.get(i).a == 0) seg.set(i, {-1, t + l - 1});
      else seg.set(i, {0, 0});
    } else {
      auto [a, b] = seg.prod(l, r);
      ans[i] = a * t + b;
    }
  }
  for(ll x: ans) cout << x << '\n';
}
0