結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー 👑 rin204rin204
提出日時 2022-06-24 16:58:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 464 ms / 3,000 ms
コード長 2,187 bytes
コンパイル時間 2,783 ms
コンパイル使用メモリ 216,196 KB
実行使用メモリ 24,320 KB
最終ジャッジ日時 2024-04-25 22:49:26
合計ジャッジ時間 12,982 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 5 ms
6,812 KB
testcase_03 AC 84 ms
8,924 KB
testcase_04 AC 129 ms
9,236 KB
testcase_05 AC 164 ms
7,468 KB
testcase_06 AC 227 ms
11,568 KB
testcase_07 AC 290 ms
11,996 KB
testcase_08 AC 134 ms
9,784 KB
testcase_09 AC 197 ms
11,660 KB
testcase_10 AC 226 ms
10,436 KB
testcase_11 AC 135 ms
6,940 KB
testcase_12 AC 213 ms
11,152 KB
testcase_13 AC 102 ms
7,424 KB
testcase_14 AC 193 ms
7,040 KB
testcase_15 AC 116 ms
7,680 KB
testcase_16 AC 227 ms
8,756 KB
testcase_17 AC 391 ms
15,796 KB
testcase_18 AC 319 ms
13,708 KB
testcase_19 AC 388 ms
15,860 KB
testcase_20 AC 36 ms
6,940 KB
testcase_21 AC 89 ms
7,928 KB
testcase_22 AC 133 ms
8,704 KB
testcase_23 AC 61 ms
6,944 KB
testcase_24 AC 128 ms
6,940 KB
testcase_25 AC 342 ms
14,756 KB
testcase_26 AC 325 ms
15,036 KB
testcase_27 AC 62 ms
6,940 KB
testcase_28 AC 70 ms
9,472 KB
testcase_29 AC 464 ms
24,320 KB
testcase_30 AC 359 ms
15,896 KB
testcase_31 AC 74 ms
10,172 KB
testcase_32 AC 460 ms
18,692 KB
testcase_33 AC 427 ms
17,332 KB
testcase_34 AC 178 ms
13,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void solve(){    
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> L(k), R(k), C(k), I(q);
    vector<long long> H(k), X(q);
    for(int i = 0; i < k; i++){
        cin >> L[i] >> R[i] >> C[i] >> H[i];
    }
    for(int i = 0; i < q; i++){
        cin >> I[i] >> X[i];
    }

    fenwick_tree<long long> bit(n + 1);
    for(int i = 0; i < k; i++){
        bit.add(L[i] - 1, H[i]);
        bit.add(R[i], -H[i]);
    }

    vector<int> ans(q);
    vector<int> LL, RR;
    vector<vector<int>> ind(1, vector<int>());
    LL.push_back(0);
    RR.push_back(k);
    for(int i = 0; i < q; i++){
        long long h = bit.sum(0, I[i]);
        if(h < X[i]) ans[i] = -1;
        else ind[0].push_back(i);
    }
    while(!ind.empty()){
        vector<int> nLL, nRR;
        vector<vector<int>> nind;
        int bj = 0;
        int size = ind.size();
        fenwick_tree<long long> bit(n + 1);
        for(int i = 0; i < size; i++){
            if(RR[i] - LL[i] <= 1){
                for(auto j:ind[i]){
                    ans[j] = C[RR[i] - 1];
                }
                continue;
            }
            int mid = (LL[i] + RR[i]) / 2;
            for(int j = bj; j < mid; j++){
                bit.add(L[j] - 1, H[j]);
                bit.add(R[j], -H[j]);
            }
            vector<int> bef, aft;
            for(auto j:ind[i]){
                long long h = bit.sum(0, I[j]);
                if(h < X[j]) aft.push_back(j);
                else bef.push_back(j);
            }
            if(!bef.empty()){
                nLL.push_back(LL[i]);
                nRR.push_back(mid);
                nind.push_back(bef);
            }
            if(!aft.empty()){
                nLL.push_back(mid);
                nRR.push_back(RR[i]);
                nind.push_back(aft);
            }
            bj = mid;
        }

        LL = nLL;
        RR = nRR;
        ind = nind;
    }
    for(auto a:ans){
        cout << a << "\n";
    }




}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int t;
    t = 1;
    // cin >> t;
    while(t--) solve();
}
    
    
0