結果

問題 No.2421 entersys?
ユーザー FplusFplusFFplusFplusF
提出日時 2023-08-12 14:16:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,693 bytes
コンパイル時間 2,989 ms
コンパイル使用メモリ 240,552 KB
実行使用メモリ 82,284 KB
最終ジャッジ日時 2024-04-30 05:33:35
合計ジャッジ時間 22,294 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 999 ms
65,156 KB
testcase_12 AC 1,012 ms
65,200 KB
testcase_13 AC 1,009 ms
65,200 KB
testcase_14 AC 1,039 ms
65,176 KB
testcase_15 AC 1,019 ms
65,188 KB
testcase_16 AC 1,011 ms
69,548 KB
testcase_17 AC 1,030 ms
69,788 KB
testcase_18 AC 1,018 ms
69,512 KB
testcase_19 AC 1,010 ms
69,616 KB
testcase_20 AC 1,021 ms
69,628 KB
testcase_21 AC 663 ms
52,476 KB
testcase_22 AC 910 ms
65,456 KB
testcase_23 AC 1,458 ms
82,228 KB
testcase_24 AC 1,426 ms
82,176 KB
testcase_25 AC 1,452 ms
82,284 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
template<class T> map<ll,ll> compress(vector<T> x){
    vector<T> unique_v=x;
    int n=x.size();
    sort(all(unique_v));
    map<ll,ll> mp;
    unique_v.erase(unique(all(unique_v)),unique_v.end());
    for(int i=0;i<n;i++){
        mp[x[i]]=lower_bound(all(unique_v),x[i])-unique_v.begin();
    }
    return mp;
}
struct segment_tree{
    vector<ll> v,lazy;
    ll n;
    segment_tree(ll x){
        ll s=1;
        while(s<x) s*=2;
        n=s;
        v.assign(s*2-1,0);
        lazy.assign(s*2-1,0);
    }
    void eval(ll k,ll l,ll r){
        if(lazy[k]!=0){
            v[k]+=lazy[k];
            if(1<r-l){
                lazy[2*k+1]+=lazy[k]/2;
                lazy[2*k+2]+=lazy[k]/2;
            }
        }
        lazy[k]=0;
    }
    void add(ll a,ll b,ll x){
        add_sub(a,b,x,0ll,0ll,n);
    }
    void add_sub(ll a,ll b,ll x,ll k,ll l, ll r){
        eval(k,l,r);
        if(r<=a||b<=l){
            return;
        }else if(a<=l&&r<=b){
            lazy[k]+=(r-l)*x;
            eval(k,l,r);
            return;
        }else{
            add_sub(a,b,x,k*2+1,l,(l+r)/2);
            add_sub(a,b,x,k*2+2,(l+r)/2,r);
            v[k]=v[k*2+1]+v[k*2+2];
            return;
        }
    }
    ll query(ll a,ll b){
        return query_sub(a,b,0ll,0ll,n);
    }
    ll query_sub(ll a,ll b,ll k,ll l,ll r){
        if(r<=a||b<=l){
            return 0;
        }
        eval(k,l,r);
        if(a<=l&&r<=b){
            return v[k];
        }else{
            ll vl=query_sub(a,b,k*2+1,l,(l+r)/2);
            ll vr=query_sub(a,b,k*2+2,(l+r)/2,r);
            return vl+vr;
        }
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> v;
    map<string,set<pll>> mp;
    vector<ll> vl(n),vr(n);
    rep(i,n){
        string x;
        ll l,r;
        cin >> x >> l >> r;
        mp[x].insert({r,l});
        v.push_back(l);
        v.push_back(r);
        vl[i]=l;
        vr[i]=r;
    }
    for(auto &[k,st]:mp) st.insert({INF,INF});
    ll q;
    cin >> q;
    vector<vector<ll>> que(q);
    vector<string> str(q);
    rep(i,q){
        ll z;
        cin >> z;
        if(z==1){
            string x;
            ll t;
            cin >> x >> t;
            str[i]=x;
            que[i]={1,t};
        }
        if(z==2){
            ll t;
            cin >> t;
            que[i]={2,t};
            v.push_back(t);
        }
        if(z==3){
            string x;
            ll l,r;
            cin >> x >> l >> r;
            str[i]=x;
            que[i]={3,l,r};
            v.push_back(l);
            v.push_back(r);
        }
    }
    map<ll,ll> z=compress(v);
    ll m=z.size();
    segment_tree st(m);
    rep(i,n) st.add(z[vl[i]],z[vr[i]]+1,1);
    rep(i,q){
        if(que[i].front()==1){
            string x=str[i];
            ll t=que[i][1];
            ll l,r;
            tie(r,l)=(*mp[x].lower_bound({t,t}));
            if(l<=t&&t<=r) cout << "Yes\n";
            else cout << "No\n";
        }
        if(que[i].front()==2){
            ll t=que[i][1];
            cout << st.query(z[t],z[t]+1) << '\n';
        }
        if(que[i].front()==3){
            string x=str[i];
            ll l=que[i][1],r=que[i][2];
            mp[x].insert({r,l});
            st.add(z[l],z[r]+1,1);
        }
    }
}
0