結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー keisuke6keisuke6
提出日時 2022-10-12 23:54:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,140 ms / 6,000 ms
コード長 1,927 bytes
コンパイル時間 2,908 ms
コンパイル使用メモリ 222,488 KB
実行使用メモリ 26,544 KB
最終ジャッジ日時 2023-09-08 20:40:40
合計ジャッジ時間 42,734 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 423 ms
20,228 KB
testcase_04 AC 778 ms
22,496 KB
testcase_05 AC 402 ms
13,296 KB
testcase_06 AC 692 ms
22,540 KB
testcase_07 AC 789 ms
22,472 KB
testcase_08 AC 779 ms
22,528 KB
testcase_09 AC 334 ms
11,988 KB
testcase_10 AC 326 ms
12,320 KB
testcase_11 AC 572 ms
14,804 KB
testcase_12 AC 581 ms
15,108 KB
testcase_13 AC 374 ms
12,952 KB
testcase_14 AC 469 ms
10,160 KB
testcase_15 AC 965 ms
24,068 KB
testcase_16 AC 649 ms
20,736 KB
testcase_17 AC 321 ms
8,916 KB
testcase_18 AC 1,115 ms
25,788 KB
testcase_19 AC 1,112 ms
25,892 KB
testcase_20 AC 1,122 ms
26,216 KB
testcase_21 AC 1,140 ms
25,780 KB
testcase_22 AC 1,127 ms
26,544 KB
testcase_23 AC 1,118 ms
25,800 KB
testcase_24 AC 1,135 ms
25,908 KB
testcase_25 AC 1,125 ms
26,204 KB
testcase_26 AC 1,130 ms
25,960 KB
testcase_27 AC 1,112 ms
25,832 KB
testcase_28 AC 1,105 ms
26,344 KB
testcase_29 AC 1,112 ms
25,628 KB
testcase_30 AC 1,113 ms
25,884 KB
testcase_31 AC 1,131 ms
25,600 KB
testcase_32 AC 1,108 ms
25,940 KB
testcase_33 AC 949 ms
25,828 KB
testcase_34 AC 949 ms
25,692 KB
testcase_35 AC 959 ms
25,832 KB
testcase_36 AC 974 ms
25,652 KB
testcase_37 AC 955 ms
25,940 KB
testcase_38 AC 386 ms
10,924 KB
testcase_39 AC 513 ms
12,160 KB
testcase_40 AC 780 ms
26,212 KB
testcase_41 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
struct SegmentTree {
private:
    int n;
    vector<int> node;
public:
    SegmentTree(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void add(int k, int val) {
        k += (n - 1);
        node[k] += val;

        while(k > 0) {
            k = (k - 1) / 2;
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    int getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];

        int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};
signed main(){
  int N;
  cin>>N;
  vector<int> A(N),T(N);
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
  SegmentTree s(vector<int>(N,0));
  SegmentTree t(vector<int>(N,0));
  for(int i=0;i<N;i++){
      cin>>A[i]>>T[i];
      pq.push({T[i],i});
      s.add(i,A[i]);
  }
  int q;
  cin>>q;
  vector<tuple<int,int,int,int>> Q(q);
  vector<int> a(q);
  for(int i=0;i<q;i++){
      int a,b,c;
      cin>>a>>b>>c;
      Q[i] = {a,b-1,c,i};
  }
  sort(Q.begin(),Q.end());
  for(int z=0;z<q;z++){
      int d,l,r,i;
      tie(d,l,r,i) = Q[z];
      while(!pq.empty() && (pq.top()).first <= d){
          int x,y;
          tie(x,y) = pq.top();
          pq.pop();
          if(!t.getsum(y,y+1)){
              s.add(y,T[y]-1);
              t.add(y,1);
              pq.push({A[y]+T[y],y});
          }
          else{
              s.add(y,-(A[y]+T[y]-1));
              t.add(y,-1);
          }
      }
      a[i] = s.getsum(l,r)-t.getsum(l,r)*d;
  }
  for(int i=0;i<q;i++) cout<<a[i]<<endl;
}
0