結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー pockynypockyny
提出日時 2024-01-21 02:18:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,094 ms / 6,000 ms
コード長 2,110 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 110,440 KB
実行使用メモリ 86,024 KB
最終ジャッジ日時 2024-01-21 02:18:49
合計ジャッジ時間 40,103 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,692 KB
testcase_01 AC 3 ms
9,692 KB
testcase_02 AC 4 ms
9,692 KB
testcase_03 AC 367 ms
48,380 KB
testcase_04 AC 697 ms
56,192 KB
testcase_05 AC 348 ms
47,708 KB
testcase_06 AC 619 ms
54,800 KB
testcase_07 AC 657 ms
56,868 KB
testcase_08 AC 668 ms
55,040 KB
testcase_09 AC 297 ms
33,588 KB
testcase_10 AC 318 ms
32,188 KB
testcase_11 AC 480 ms
49,604 KB
testcase_12 AC 469 ms
49,708 KB
testcase_13 AC 342 ms
33,412 KB
testcase_14 AC 304 ms
29,520 KB
testcase_15 AC 786 ms
58,808 KB
testcase_16 AC 576 ms
55,416 KB
testcase_17 AC 215 ms
29,040 KB
testcase_18 AC 967 ms
86,024 KB
testcase_19 AC 1,005 ms
86,024 KB
testcase_20 AC 996 ms
86,024 KB
testcase_21 AC 994 ms
86,024 KB
testcase_22 AC 1,034 ms
86,024 KB
testcase_23 AC 1,081 ms
86,024 KB
testcase_24 AC 1,094 ms
86,024 KB
testcase_25 AC 1,000 ms
86,024 KB
testcase_26 AC 984 ms
86,024 KB
testcase_27 AC 976 ms
86,024 KB
testcase_28 AC 977 ms
86,024 KB
testcase_29 AC 974 ms
86,024 KB
testcase_30 AC 998 ms
86,024 KB
testcase_31 AC 996 ms
86,024 KB
testcase_32 AC 971 ms
86,024 KB
testcase_33 AC 810 ms
81,804 KB
testcase_34 AC 801 ms
81,804 KB
testcase_35 AC 770 ms
81,804 KB
testcase_36 AC 807 ms
81,804 KB
testcase_37 AC 817 ms
81,804 KB
testcase_38 AC 177 ms
29,600 KB
testcase_39 AC 274 ms
31,920 KB
testcase_40 AC 166 ms
31,772 KB
testcase_41 AC 3 ms
9,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <atcoder/lazysegtree>
#include <vector>
#include <algorithm>

using namespace std;
using namespace atcoder;
typedef long long ll;
struct S{ll len,val = 0;};
struct F{ll x;};
S op(S l,S r){return S{l.len + r.len,l.val + r.val};}
S e(){return S{0,0};}
S mapping(F l,S r){return S{r.len,r.val + l.x*r.len};}
F compo(F l,F r){return F{l.x + r.x};}
F id(){return F{0};}
ll a[200010],t[200010],d[200010],l[200010],r[200010];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,n; cin >> n;
    vector<ll> z;
    z.push_back(0); z.push_back(1);
    for(i=1;i<=n;i++){
        cin >> a[i] >> t[i];
        z.push_back(t[i]);
        z.push_back(a[i] + t[i]);
    }
    vector<vector<int>> b(n + 1),c(n + 1);
    int q; cin >> q;
    for(i=0;i<q;i++){
        cin >> d[i] >> l[i] >> r[i];
        l[i]--;
        z.push_back(d[i] + 1);
        b[l[i]].push_back(i);
        c[r[i]].push_back(i);
    }
    sort(z.begin(),z.end());
    z.erase(unique(z.begin(),z.end()),z.end());
    vector<S> v;
    for(i=0;i<z.size() - 1;i++){
        v.push_back({z[i + 1] - z[i],0});
    }

    // for(ll u:z) cout << u << " ";
    // cout << endl;
    
    lazy_segtree<S,op,e,F,mapping,compo,id> seg(v);
    auto prod = [&](int l,int r){
        int le = lower_bound(z.begin(),z.end(),l) - z.begin();
        int ri = lower_bound(z.begin(),z.end(),r) - z.begin();
        return seg.prod(le,ri).val;
    };

    auto add = [&](int l,int r,ll x){
        int le = lower_bound(z.begin(),z.end(),l) - z.begin();
        int ri = lower_bound(z.begin(),z.end(),r) - z.begin();
        seg.apply(le,ri,{x});
    };

    vector<ll> ans(q);
    for(i=0;i<=n;i++){
        add(0,1,a[i]);
        if(i){
            add(t[i],t[i] + a[i],-1);
        }
        for(int id:b[i]){
            ans[id] -= prod(0,d[id] + 1);
        }
        for(int id:c[i]){
            ans[id] += prod(0,d[id] + 1);
        }
        // for(int j=0;j<v.size();j++){
        //     cout << seg.get(j).val << " ";
        // }
        // cout << "\n";
    }
    for(i=0;i<q;i++) cout << ans[i] << "\n";
}
0