結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー butsurizukibutsurizuki
提出日時 2022-10-07 11:44:14
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 393 ms / 6,000 ms
コード長 1,499 bytes
コンパイル時間 9,066 ms
コンパイル使用メモリ 336,820 KB
実行使用メモリ 40,596 KB
最終ジャッジ日時 2023-09-08 20:38:46
合計ジャッジ時間 27,395 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 164 ms
24,668 KB
testcase_04 AC 282 ms
28,952 KB
testcase_05 AC 150 ms
23,592 KB
testcase_06 AC 233 ms
27,432 KB
testcase_07 AC 257 ms
30,024 KB
testcase_08 AC 252 ms
28,044 KB
testcase_09 AC 124 ms
17,300 KB
testcase_10 AC 116 ms
16,252 KB
testcase_11 AC 187 ms
22,124 KB
testcase_12 AC 195 ms
21,656 KB
testcase_13 AC 132 ms
16,968 KB
testcase_14 AC 140 ms
12,476 KB
testcase_15 AC 320 ms
31,292 KB
testcase_16 AC 247 ms
29,140 KB
testcase_17 AC 105 ms
13,344 KB
testcase_18 AC 370 ms
39,816 KB
testcase_19 AC 392 ms
39,372 KB
testcase_20 AC 374 ms
40,596 KB
testcase_21 AC 387 ms
39,552 KB
testcase_22 AC 363 ms
39,436 KB
testcase_23 AC 393 ms
39,540 KB
testcase_24 AC 373 ms
39,428 KB
testcase_25 AC 390 ms
39,384 KB
testcase_26 AC 365 ms
40,584 KB
testcase_27 AC 387 ms
39,504 KB
testcase_28 AC 367 ms
40,168 KB
testcase_29 AC 387 ms
39,320 KB
testcase_30 AC 366 ms
39,364 KB
testcase_31 AC 391 ms
39,504 KB
testcase_32 AC 371 ms
39,408 KB
testcase_33 AC 343 ms
39,312 KB
testcase_34 AC 325 ms
40,144 KB
testcase_35 AC 345 ms
39,316 KB
testcase_36 AC 328 ms
40,324 KB
testcase_37 AC 340 ms
39,380 KB
testcase_38 AC 83 ms
12,352 KB
testcase_39 AC 144 ms
13,452 KB
testcase_40 AC 257 ms
39,312 KB
testcase_41 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "testlib.h"
#include <bits/stdc++.h>
#include <atcoder/segtree>

using namespace std;
using namespace atcoder;
using pl=pair<long long,long long>;
using ppl=pair<pl,pl>;

pl op(pl a,pl b){
  return {a.first+b.first,a.second+b.second};
}

pl e(){return {0,0};}

int main(){
  registerValidation();
  long long n=inf.readLong(1ll,200000ll);inf.readEoln();
  vector<pl> init(n);
  vector<ppl> event;
  for(int i=0;i<n;i++){
    long long a=inf.readLong(0ll,1000000000ll);inf.readSpace();
    long long t=inf.readLong(1ll,1000000000ll);inf.readEoln();
    init[i]={0,a};
    if(a!=0){
      event.push_back({{t,-i},{-1,t+a-1}}); // if a==1 this comes first
      event.push_back({{t+a-1,-i},{0,0}}); // if a==1 this comes second
    }
  }
  long long q=inf.readLong(1ll,200000ll);inf.readEoln();
  for(int i=1;i<=q;i++){
    long long d=inf.readLong(0ll,2000000000ll);inf.readSpace();
    long long l=inf.readLong(1ll,n);inf.readSpace();
    long long r=inf.readLong(l,n);inf.readEoln();
    event.push_back({{d,i},{l,r}});
  }
  inf.readEof();
  segtree<pl,op,e> seg(init);
  sort(event.begin(),event.end());
  vector<long long> res(q+1);
  for(auto &nx : event){
    long long x=nx.first.first;
    long long knd=nx.first.second;
    long long l=nx.second.first;
    long long r=nx.second.second;
    if(knd<=0){
      seg.set(-knd,{l,r});
    }
    else{
      pl f=seg.prod(l-1,r);
      res[knd]=f.first*x+f.second;
    }
  }
  for(int i=1;i<=q;i++){cout << res[i] << "\n";}
  return 0;
}
0