結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー 👑 rin204rin204
提出日時 2022-06-24 16:57:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,181 bytes
コンパイル時間 2,661 ms
コンパイル使用メモリ 215,208 KB
実行使用メモリ 16,432 KB
最終ジャッジ日時 2024-04-25 22:49:01
合計ジャッジ時間 11,889 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 5 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 64 ms
9,472 KB
testcase_29 WA -
testcase_30 AC 333 ms
16,020 KB
testcase_31 AC 69 ms
9,916 KB
testcase_32 AC 367 ms
14,088 KB
testcase_33 WA -
testcase_34 AC 167 ms
13,440 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]){
                int 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