結果

問題 No.2421 entersys?
ユーザー new_textfilenew_textfile
提出日時 2023-08-12 15:14:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,285 ms / 3,000 ms
コード長 5,186 bytes
コンパイル時間 3,168 ms
コンパイル使用メモリ 244,144 KB
実行使用メモリ 92,624 KB
最終ジャッジ日時 2024-11-20 00:33:23
合計ジャッジ時間 23,247 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 4 ms
5,248 KB
testcase_02 AC 6 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 3 ms
5,248 KB
testcase_05 AC 5 ms
5,248 KB
testcase_06 AC 4 ms
5,248 KB
testcase_07 AC 5 ms
5,248 KB
testcase_08 AC 6 ms
5,248 KB
testcase_09 AC 8 ms
5,248 KB
testcase_10 AC 4 ms
5,248 KB
testcase_11 AC 1,016 ms
72,452 KB
testcase_12 AC 1,010 ms
72,484 KB
testcase_13 AC 993 ms
72,844 KB
testcase_14 AC 965 ms
73,100 KB
testcase_15 AC 979 ms
72,660 KB
testcase_16 AC 1,022 ms
78,172 KB
testcase_17 AC 1,017 ms
78,092 KB
testcase_18 AC 1,015 ms
78,696 KB
testcase_19 AC 1,032 ms
77,584 KB
testcase_20 AC 1,024 ms
78,248 KB
testcase_21 AC 842 ms
58,144 KB
testcase_22 AC 941 ms
78,108 KB
testcase_23 AC 1,258 ms
92,624 KB
testcase_24 AC 1,285 ms
92,576 KB
testcase_25 AC 1,268 ms
92,436 KB
testcase_26 AC 669 ms
47,224 KB
testcase_27 AC 668 ms
47,192 KB
testcase_28 AC 667 ms
47,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// #include <atcoder/modint>
// #include <atcoder/segtree>
#include <atcoder/lazysegtree>
// #include <atcoder/dsu>
// #include <atcoder/scc>
using namespace atcoder;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef priority_queue<pll, vpll, function<bool(pll,pll)> > pqpll; 
typedef priority_queue<ll, vll, function<bool(pll,pll)> > pqll;
 
struct edge{ ll to, cost; edge(ll e_to,ll e_cost): to(e_to), cost(e_cost){} };
typedef vector<vector<edge>> Graph;
 
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (1LL << 60)
#define INF (1 << 30)
#define fs first
#define sc second
#define EPS (ld)1e-10
#define ALL(a) a.begin(), a.end()
#define tcheck(a) if((clock() - start)/(ld)CLOCKS_PER_SEC >= a) break
#define debug(s) cout << #s << endl
#define debugval(x) cout << #x" = " << x << endl
 
template<typename T> ll sz(vector<T> &pos){ return (ll)pos.size(); }
template<typename T> ll sz(priority_queue<T, vector<T> > &que) {return (ll)que.size(); }
template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &que) {return (ll)que.size(); }
ll sz(string &s) {return (ll)s.size(); } 
 
template<typename T> void chmin(T &a, T b) { if(a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if(a < b) a = b; }
 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
// ll dx[4] = {0,-1,0,1},dy[4] = {-1,0,1,0};
ll dx[8] = {0,-1,-1,-1,0,1,1,1},dy[8] = {-1,-1,0,1,1,1,0,-1};
inline bool isinside(ll i,ll n){ return (i < n && i >= 0); }

pll op(pll a, pll b){return {a.fs + b.fs, a.sc + b.sc};}
pll e(){return {0,0}; }
pll mapping(ll f, pll x){ return {x.fs + x.sc*f, x.sc}; }
ll composition(ll f,ll g){return f+g;}
ll id(){return 0;}

int main(){    
    
    ll n;
    cin >> n;

    vector<pair<string,pll>> memo(n);
    rep(i,0,n){
        cin >> memo[i].fs >> memo[i].sc.fs >> memo[i].sc.sc;
        memo[i].sc.fs--;
    }

    ll q; cin >> q;
    vector<pair<array<ll,3>,string>> query(q);
    rep(i,0,q){
        ll op; cin >> op;
        if(op == 1){
            string x; cin >> x;
            ll t; cin >> t;
            t--;
            query[i].fs = array<ll,3>({1,t,-1});
            query[i].sc = x;
        }
        else if(op == 2){
            ll t; cin >> t;
            t--;
            query[i].fs = array<ll,3>({2,t,-1});
        }
        else{
            string x; cin >> x;
            ll l,r; cin >> l >> r;
            l--;
            query[i].fs = array<ll,3>({3,l,r});
            query[i].sc = x;
        }
    }

    map<string,set<pll>> mp;
    auto add = [&mp](string x, ll l, ll r){
        auto& st = mp[x];
        if(st.size() == 0){
            st.emplace(LINF,LINF);
            st.emplace(-LINF,-LINF);
        }

        st.emplace(l,r);
        auto it = st.lower_bound(pll(l,r)); it--;

        if(it->first <= l && l <= it->second){
            l = min(l, it->first), r = max(r, it->second);
            st.erase(it);
        }
        it = st.lower_bound(pll(l,r));
        while(1){
            if(l <= it->first && it->first <= r){
                r = max(r, it->second);
                it = st.erase(it);
            }
            else break;
        }
        st.insert(pll(l,r));
    };

    vll tmemo;
    rep(i,0,n){
        add(memo[i].fs, memo[i].sc.fs, memo[i].sc.sc);
        tmemo.emplace_back(memo[i].sc.fs);
        tmemo.emplace_back(memo[i].sc.sc);
    }

    rep(i,0,q){
        if(query[i].fs[0] == 2) tmemo.emplace_back(query[i].fs[1]);
        else if(query[i].fs[0] == 3){
            tmemo.emplace_back(query[i].fs[1]);
            tmemo.emplace_back(query[i].fs[2]);
        }
    }
    sort(ALL(tmemo));
    tmemo.erase(unique(ALL(tmemo)),tmemo.end());

    map<ll,ll> zaatu;
    rep(i,0,sz(tmemo)) zaatu[tmemo[i]] = i;
    
    lazy_segtree<pll,op,e,ll,mapping,composition,id> seg(vector<pll>(sz(tmemo)+1,{0,1}));
    rep(i,0,n) seg.apply(zaatu[memo[i].sc.fs], zaatu[memo[i].sc.sc],1);

    rep(i,0,q){
        if(query[i].fs[0] == 1){
            ll t = query[i].fs[1];

            auto& st = mp[query[i].sc];
            
            if(st.size() == 0) cout << "No" << endl;
            else{
                auto it = st.lower_bound(pll(t, LINF)); it--;
                if(it->first <= t && t < it->second) cout << "Yes" << endl;
                else cout << "No" << endl;
            }
        }
        else if(query[i].fs[0] == 2){
            auto [op,t,_] = query[i].fs;
            cout << seg.get(zaatu[t]).fs << endl;
        }
        else if(query[i].fs[0] == 3){
            auto [arr,x] = query[i];
            auto [op,l,r] = arr;
            add(x,l,r);
            seg.apply(zaatu[l],zaatu[r],1);
        }
    }
}
0