結果

問題 No.2421 entersys?
ユーザー くけくけ
提出日時 2023-08-12 15:28:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,890 bytes
コンパイル時間 5,406 ms
コンパイル使用メモリ 292,432 KB
実行使用メモリ 71,488 KB
最終ジャッジ日時 2024-04-30 09:30:09
合計ジャッジ時間 26,577 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,812 KB
testcase_02 AC 5 ms
6,940 KB
testcase_03 WA -
testcase_04 AC 3 ms
6,944 KB
testcase_05 WA -
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 5 ms
6,940 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 4 ms
6,940 KB
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 AC 1,063 ms
62,436 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};
int main(){
    ll n ;
    cin >> n ;
    set<ll> it ;
    set<pair<ll,ll>> L[n+2] ;
    vector<pair<ll,ll>> V[n] ;
    map<string,ll> mp ;
    vector<tuple<ll,ll,ll,ll,ll>> vt ;
    ll a = 1 ;
    rep(i,n){
        string x;
        ll l, r ;
        cin >> x >> l >> r ;
        if( mp[x] == 0 ) mp[x] = a++ ;
        L[mp[x]].insert({l,r}) ;
        it.insert(l) ;
        it.insert(r) ;
    }
    ll q ;
    cin >> q ;
    // クエリ先読み
    rep(i,q){
        ll t ;
        cin >> t ;
        string x ;
        ll num = 0 , time = 0 , l = 0 , r = 0 ;
        if( t == 1 ){
            cin >> x ;
            cin >> time ;
            num = mp[x] ;
        }
        if( t == 2 ){
            cin >> time ;
            it.insert(time) ;
        }
        if( t == 3 ){
            cin >> x >> l >> r ;
            num = mp[x] ;
            it.insert(l) ;
            it.insert(r) ;
        }
        vt.push_back({t,num,time,l,r}) ;
    }
    vector<ll> v ;
    for( auto p : it) v.push_back(p) ;
    LazySegmentTree seg( vector<ll>(it.size(), 0) );
    rep(i,n){
        for( auto [l,r] : L[i] ){
            auto p = lower_bound(v.begin(),v.end(),l) ;
            auto q = lower_bound(v.begin(),v.end(),r) ;
            ll pd = distance(v.begin(),p) ;
            ll qd = distance(v.begin(),q) ;
            seg.add(pd,qd+1,1) ;
        }
    }
    rep(i,q){
        auto [t,x,time,l,r] = vt[i] ;
        if( t == 1 ){
            auto p = L[x].lower_bound({time,time}) ;
            pair<ll,ll> pw = *p ;
            if( pw.first <= time && time <= pw.second ){
                cout << "Yes" << endl ;
            }
            else{
                cout << "No" << endl ;
            }
        }
        if( t == 2 ){
            auto p = lower_bound(v.begin(),v.end(),time) ;
            ll pd = distance(v.begin(),p) ;
            cout << seg.getsum(pd,pd+1) << endl ;
        }
        if( t == 3 ){
            auto p = lower_bound(v.begin(),v.end(),l) ;
            auto q = lower_bound(v.begin(),v.end(),r) ;
            ll pd = distance(v.begin(),p) ;
            ll qd = distance(v.begin(),q) ;
            seg.add(pd,qd+1,1) ;
            // 区間に加算してクエリ2を処理する。
            L[x].insert({l,r}) ;
        }
    }

 }
0