Submission #66950054


Source Code Expand

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define AMARI 998244353
//#define AMARI 1000000007
#define el '\n'
#define El '\n'
#define YESNO(x) ((x) ? "Yes" : "No")
#define YES YESNO(true)
#define NO YESNO(false)
#define REV_PRIORITY_QUEUE(tp) priority_queue<tp,vector<tp>,greater<tp>>
#define EXIT_ANS(x) {cout << (x) << '\n'; return;}
template <typename T> void inline SORT(vector<T> &v){sort(v.begin(),v.end()); return;}
template <typename T> void inline VEC_UNIQ(vector<T> &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return;}
template <typename T> T inline MAX(vector<T> &v){return *max_element(v.begin(),v.end());}
template <typename T> T inline MIN(vector<T> &v){return *min_element(v.begin(),v.end());}
template <typename T> T inline SUM(vector<T> &v){T ans = 0; for(int i = 0; i < (int)v.size(); i++)ans += v[i]; return ans;}
template <typename T> void inline DEC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]--; return;}
template <typename T> void inline INC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]++; return;}
void inline TEST(void){cerr << "TEST" << endl; return;}
template <typename T> bool inline chmin(T &x,T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}
template <typename T> bool inline chmax(T &x,T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template <typename T = long long> vector<T> inline get_vec(int n){
    vector<T> ans(n);
    for(int i = 0; i < n; i++)cin >> ans[i];
    return ans;
}
template <typename T> void inline print_vec(vector<T> &vec,bool kaigyou = false){
    int n = (int)vec.size();
    for(int i = 0; i < n; i++){
        cout << vec[i];
        if(kaigyou || i == n - 1)cout << '\n';
        else cout << ' ';
    }
    if(!n)cout << '\n';
    return;
}
template <typename T> void inline debug_vec(vector<T> &vec,bool kaigyou = false){
    int n = (int)vec.size();
    for(int i = 0; i < n; i++){
        cerr << vec[i];
        if(kaigyou || i == n - 1)cerr << '\n';
        else cerr << ' ';
    }
    if(!n)cerr << '\n';
    return;
}
vector<vector<int>> inline get_graph(int n,int m = -1,bool direct = false){
    if(m == -1)m = n - 1;
    vector<vector<int>> g(n);
    while(m--){
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        if(!direct)g[v].push_back(u);
    }
    return g;
}

vector<int> make_inv(vector<int> p){
    int n = (int)p.size();
    vector<int> ans(n);
    for(int i = 0; i < n; i++)ans[p[i]] = i;
    return ans;
}

//trie 木
//trie 木想定のものはロリハで通ることも多いが、大抵こっちの方が計算量が良い(というかロリハが logMOD がしょっちゅうかかるため遅い)
//ノードに何かを乗せられるようにした。割と色んな演算が乗りそう。
//string にのみ対応させているが、vector に対応させたやつも作ると今後嬉しそう
template <typename T> class ococo_trie {
private:
    //trie木に乗せる演算
    T func(T l,T r){
        return min(l,r);
    }

    //特に指定しなかった時に何を入れるか。func の単位元だと嬉しそう。
    T e = 'a';


    const array<int,26> temparr = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
    vector<array<int,26>> child_idx;
    vector<T> val;
    vector<int> par;
    
public:
    ococo_trie(void){
        child_idx.push_back(temparr);
        val.push_back(e);
        par.push_back(-1);
    }
    //文字列を追加し、その文字列の一番最後に対応する index を返す
    int push(string s,int idx = 0){
        for(int i = 0; i < (int)s.size(); i++){
            if(child_idx[idx][s[i] - 'a'] != -1){
                idx = child_idx[idx][s[i] - 'a'];
                continue;
            }
            child_idx[idx][s[i] - 'a'] = (int)child_idx.size();
            par.push_back(idx);
            idx = (int)child_idx.size();
            child_idx.push_back(temparr);
            val.push_back(s[i]);
            
        }
        return idx;
    }

    //文字列 s を trie 木から探し、見つからなかったら-1を、見つかったら末尾に対応する trie木内の index を返す。
    int search(string s){
        int idx = 0;
        for(int i = 0; i < (int)s.size(); i++){
            idx = child_idx[idx][s[i] - 'a'];
            if(idx == -1)return -1;
        }
        return idx;
    }

    //点 idx の値を得る
    T get_val_point(int idx){
        return val[idx];
    }

    //trie 木内にある文字列 S について、対応する val を返す。
    //trie 木内にない文字列の値を調べようとしたとき、trie 木内にあった部分までの演算を得る
    T get_val_string(string s){
        T ans = val[0];
        int idx = 0;
        for(int i = 0; i < (int)s.size(); i++){
            idx = child_idx[idx][s[i] - 'a'];
            if(idx == -1)return ans;
            ans = func(ans,val[idx]);
        }
        return ans;
    }

    string get_string(int idx){
        string ans;
        while(idx != 0){
            //cerr << idx << el;
            ans.push_back(val[idx]);
            idx = par[idx];
        }
        reverse(ans.begin(),ans.end());
        return ans;
    }

    //idx 番目の頂点の値を x にする
    void update_val(int idx,T x){
        val[idx] = x;
        return;
    }
};


#define MULTI_TEST_CASE false
void solve(void){
    //問題を見たらまず「この問題設定から言えること」をいっぱい言う
    //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
    //複数の解法のアイデアを思いついた時は全部メモしておく
    //g++ -D_GLIBCXX_DEBUG -Wall -O2 d.cpp -o o
    int n,q;
    cin >> n >> q;
    ococo_trie<char> trie;
    vector<int> idx(n,0);
    int server_idx = 0;

    while(q--){
        int t;
        cin >> t;
        if(t == 1){
            int p;
            cin >> p;
            p--;
            idx[p] = server_idx;
        }
        if(t == 2){
            int p;
            cin >> p;
            p--;
            string s;
            cin >> s;
            idx[p] = trie.push(s,idx[p]);
        }
        if(t == 3){
            int p;
            cin >> p;
            p--;
            server_idx = idx[p];
        }
    }
    cerr << server_idx << el;
    string ans = trie.get_string(server_idx);
    cout << ans << el;
    return;
}

void calc(void){
    return;
}

signed main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE)cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Submission Info

Submission Time
Task D - Conflict 2
User ococonomy1
Language C++ 17 (gcc 12.2)
Score 425
Code Size 7200 Byte
Status AC
Exec Time 118 ms
Memory 118912 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 49
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 02_random2_12.txt, 02_random2_13.txt, 02_random2_14.txt, 02_random2_15.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 04_random4_00.txt, 04_random4_01.txt, 05_random5_00.txt, 05_random5_01.txt, 06_handmade_00.txt, 06_handmade_01.txt, 06_handmade_02.txt, 06_handmade_03.txt, 06_handmade_04.txt, 06_handmade_05.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3392 KiB
00_sample_01.txt AC 1 ms 3432 KiB
00_sample_02.txt AC 1 ms 3460 KiB
01_random_00.txt AC 43 ms 60136 KiB
01_random_01.txt AC 58 ms 59980 KiB
01_random_02.txt AC 95 ms 115940 KiB
01_random_03.txt AC 39 ms 60168 KiB
01_random_04.txt AC 108 ms 116128 KiB
01_random_05.txt AC 26 ms 31816 KiB
01_random_06.txt AC 90 ms 116000 KiB
01_random_07.txt AC 45 ms 59684 KiB
01_random_08.txt AC 23 ms 17804 KiB
01_random_09.txt AC 38 ms 31840 KiB
01_random_10.txt AC 99 ms 115844 KiB
01_random_11.txt AC 14 ms 17316 KiB
01_random_12.txt AC 94 ms 116148 KiB
01_random_13.txt AC 88 ms 116072 KiB
01_random_14.txt AC 55 ms 59620 KiB
01_random_15.txt AC 29 ms 31240 KiB
02_random2_00.txt AC 21 ms 4480 KiB
02_random2_01.txt AC 20 ms 4528 KiB
02_random2_02.txt AC 21 ms 4484 KiB
02_random2_03.txt AC 20 ms 4484 KiB
02_random2_04.txt AC 117 ms 116624 KiB
02_random2_05.txt AC 115 ms 116444 KiB
02_random2_06.txt AC 114 ms 116564 KiB
02_random2_07.txt AC 19 ms 4276 KiB
02_random2_08.txt AC 117 ms 116440 KiB
02_random2_09.txt AC 116 ms 116544 KiB
02_random2_10.txt AC 115 ms 116604 KiB
02_random2_11.txt AC 18 ms 4072 KiB
02_random2_12.txt AC 118 ms 116440 KiB
02_random2_13.txt AC 115 ms 116516 KiB
02_random2_14.txt AC 113 ms 116580 KiB
02_random2_15.txt AC 15 ms 3824 KiB
03_random3_00.txt AC 112 ms 118436 KiB
03_random3_01.txt AC 114 ms 118372 KiB
03_random3_02.txt AC 114 ms 118300 KiB
03_random3_03.txt AC 107 ms 117480 KiB
04_random4_00.txt AC 111 ms 118912 KiB
04_random4_01.txt AC 111 ms 118768 KiB
05_random5_00.txt AC 115 ms 118436 KiB
05_random5_01.txt AC 116 ms 117076 KiB
06_handmade_00.txt AC 1 ms 3468 KiB
06_handmade_01.txt AC 94 ms 117792 KiB
06_handmade_02.txt AC 16 ms 3800 KiB
06_handmade_03.txt AC 23 ms 3704 KiB
06_handmade_04.txt AC 16 ms 3816 KiB
06_handmade_05.txt AC 26 ms 17932 KiB