結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー 👑 NachiaNachia
提出日時 2024-04-18 02:37:16
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 315 ms / 3,000 ms
コード長 1,544 bytes
コンパイル時間 1,185 ms
コンパイル使用メモリ 101,748 KB
実行使用メモリ 36,096 KB
最終ジャッジ日時 2024-10-09 20:17:05
合計ジャッジ時間 12,158 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/segtree>
using namespace std;
using i64 = long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


const i64 INF = 1001001001001001001;

template<class S> struct SegtreeSum{
    static S op(S l, S r){ return l + r; }
    static S e(){ return S(0); }
    using Type = struct atcoder::segtree<S,op,e>;
    struct LessThan{
        S y;
        LessThan(const S& s) : y(s) {}
        bool operator()(S x) const { return x < y; }
    };
};


int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
    int N; cin >> N;
    int K; cin >> K;
    int Q; cin >> Q;

    struct AddQuery{ int p; i64 x; };
    vector<vector<AddQuery>> addQueries(N+1);
    vector<int> col(K+1, -1);

    rep(i,K){
        int l; cin >> l; l--;
        int r; cin >> r;
        int c; cin >> c;
        int k; cin >> k;
        addQueries[l].push_back({ i, k });
        addQueries[r].push_back({ i, -k });
        col[i] = c;
    }

    struct AnswerQuery{ i64 h; int idx; };
    vector<vector<AnswerQuery>> answerQueries(N);
    rep(i,Q){
        int p; cin >> p; p--;
        i64 h; cin >> h;
        answerQueries[p].push_back({ h, i });
    }

    vector<int> ans(Q, -1);
    SegtreeSum<i64>::Type rq(K);

    rep(i,N){
        for(auto q : addQueries[i]) rq.set(q.p, rq.get(q.p) + q.x);
        for(auto q : answerQueries[i]) ans[q.idx] = col[rq.max_right(0, SegtreeSum<i64>::LessThan(q.h))];
    }

    rep(i,Q) cout << ans[i] << '\n';
    return 0;
}
0