結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー Nzt3Nzt3
提出日時 2022-10-26 23:08:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 283 ms / 6,000 ms
コード長 1,204 bytes
コンパイル時間 4,536 ms
コンパイル使用メモリ 206,912 KB
実行使用メモリ 28,372 KB
最終ジャッジ日時 2023-09-17 16:17:09
合計ジャッジ時間 25,603 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,996 KB
testcase_01 AC 1 ms
5,056 KB
testcase_02 AC 2 ms
5,060 KB
testcase_03 AC 127 ms
15,808 KB
testcase_04 AC 195 ms
15,792 KB
testcase_05 AC 118 ms
15,872 KB
testcase_06 AC 178 ms
15,740 KB
testcase_07 AC 204 ms
16,372 KB
testcase_08 AC 194 ms
15,660 KB
testcase_09 AC 99 ms
10,088 KB
testcase_10 AC 90 ms
9,640 KB
testcase_11 AC 143 ms
15,756 KB
testcase_12 AC 145 ms
15,904 KB
testcase_13 AC 100 ms
9,828 KB
testcase_14 AC 99 ms
9,700 KB
testcase_15 AC 228 ms
16,948 KB
testcase_16 AC 182 ms
16,508 KB
testcase_17 AC 74 ms
9,532 KB
testcase_18 AC 279 ms
28,160 KB
testcase_19 AC 278 ms
28,192 KB
testcase_20 AC 278 ms
28,104 KB
testcase_21 AC 283 ms
28,216 KB
testcase_22 AC 280 ms
28,128 KB
testcase_23 AC 279 ms
28,108 KB
testcase_24 AC 279 ms
28,188 KB
testcase_25 AC 279 ms
28,240 KB
testcase_26 AC 278 ms
28,236 KB
testcase_27 AC 280 ms
28,160 KB
testcase_28 AC 276 ms
28,108 KB
testcase_29 AC 277 ms
28,160 KB
testcase_30 AC 279 ms
28,316 KB
testcase_31 AC 280 ms
28,124 KB
testcase_32 AC 279 ms
28,216 KB
testcase_33 AC 260 ms
28,220 KB
testcase_34 AC 260 ms
28,100 KB
testcase_35 AC 261 ms
28,372 KB
testcase_36 AC 262 ms
28,236 KB
testcase_37 AC 261 ms
28,172 KB
testcase_38 AC 68 ms
9,792 KB
testcase_39 AC 115 ms
10,132 KB
testcase_40 AC 229 ms
28,100 KB
testcase_41 AC 2 ms
4,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long getsum(int l,int r,const vector<long long>& BIT){
  long long ret=0;
  for(;r>0;r-=r&-r)ret+=BIT[r];
  for(--l;l>0;l-=l&-l)ret-=BIT[l];
  return ret;
}
void add(int p,vector<long long>& BIT,int v){
  for(;p<BIT.size();p+=p&-p)BIT[p]+=v;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector<long long>val(N+1),cnt(N+1);
  vector<array<int,5>>evt;
  for(int i=1;i<=N;i++){
    int v;
    cin>>v;
    add(i,val,v);
    int t;
    cin>>t;
    evt.push_back({t,0,i,t-1,0});
    evt.push_back({t+v-1,1,i,-(v+t-1),0});
  }
  int Q;
  cin>>Q;
  vector<long long>ans(Q);
  for(int i=0;i<Q;i++){
    int D,L,R;
    cin>>D>>L>>R;
    evt.push_back({D,2,L,R,i});
  }
  sort(evt.begin(),evt.end());

  for(int i=0;i<N*2+Q;i++){
    switch(evt[i][1]){

      case 0:
        add(evt[i][2],val,evt[i][3]);
        add(evt[i][2],cnt,1);
        break;
      case 1:
        add(evt[i][2],val,evt[i][3]);
        add(evt[i][2],cnt,-1);
        break;
      case 2:
        ans[evt[i][4]]=getsum(evt[i][2],evt[i][3],val)-getsum(evt[i][2],evt[i][3],cnt)*evt[i][0];
        break;

    }
  }

  for(auto i:ans)cout<<i<<'\n';
}
0