Submission #65280633


Source Code Expand

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define xx first
#define yy second
#define PB push_back
#define MP make_pair

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
using vi = vector<int>;
template <typename T> using V = vector<T>;

template<class T> using uset = unordered_set<T>;
template<class T1, class T2> using umap = unordered_map<T1, T2>;

const vector<pair<int, int>> DIRS = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
constexpr int MOD = 1000000007;
mt19937_64 rnd(time(0));

class Node {
public:
    int cnt = -1;
    vector<Node> childs;
    bool insert(string& s, int i) {
        // cout << s << i << endl;
        if ( cnt == -2 ) return false;
        if ( cnt == -1 ) {
            cnt = 0;
            childs = vector<Node>(26);
        }
        if ( i == s.size() ) {
            cnt++;
            return true;
        } else {
            if ( childs[s[i]-'a'].insert(s, i+1) ) {
                cnt++;
                return true;
            }
            return false;
        }
    }
    int rem(string& s, int i) {
        // cout << s << i << endl;
        if ( cnt == -2 ) return 0;
        if ( cnt == -1 ) {
            cnt = 0;
            childs = vector<Node>(26);
        }
        int ret;
        if ( i == s.size() ) {
            ret = cnt;
            cnt = -2;
        } else {
            ret = childs[s[i]-'a'].rem(s, i+1);
            cnt -= ret;
        }
        return  ret;
    }
};

template <class T>
using ordered_set =  __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    int q;
    string s;
    Node root;
    while ( n-- ) {
        cin >> q >> s;
        if ( q == 1 ) {
            root.rem(s, 0);
        } else {
            root.insert(s, 0);
        }
        cout << root.cnt << '\n';
    }
    return 0;
}

Submission Info

Submission Time
Task E - Forbidden Prefix
User din2009siuc
Language C++ 20 (gcc 12.2)
Score 500
Code Size 2124 Byte
Status AC
Exec Time 277 ms
Memory 488208 KiB

Compile Error

Main.cpp: In member function ‘bool Node::insert(std::string&, int)’:
Main.cpp:36:16: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   36 |         if ( i == s.size() ) {
      |              ~~^~~~~~~~~~~
Main.cpp: In member function ‘int Node::rem(std::string&, int)’:
Main.cpp:55:16: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   55 |         if ( i == s.size() ) {
      |              ~~^~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 57
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.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, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 02_handmade_10.txt, 02_handmade_11.txt, 02_handmade_12.txt, 02_handmade_13.txt, 02_handmade_14.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3520 KiB
00_sample_02.txt AC 1 ms 3540 KiB
01_random_01.txt AC 238 ms 421660 KiB
01_random_02.txt AC 241 ms 421732 KiB
01_random_03.txt AC 262 ms 426128 KiB
01_random_04.txt AC 241 ms 421364 KiB
01_random_05.txt AC 238 ms 420828 KiB
01_random_06.txt AC 254 ms 430000 KiB
01_random_07.txt AC 222 ms 416432 KiB
01_random_08.txt AC 200 ms 378600 KiB
01_random_09.txt AC 170 ms 314132 KiB
01_random_10.txt AC 125 ms 231288 KiB
01_random_11.txt AC 198 ms 371892 KiB
01_random_12.txt AC 135 ms 251296 KiB
01_random_13.txt AC 218 ms 408332 KiB
01_random_14.txt AC 24 ms 4048 KiB
01_random_15.txt AC 24 ms 3876 KiB
01_random_16.txt AC 25 ms 3748 KiB
01_random_17.txt AC 14 ms 4208 KiB
01_random_18.txt AC 24 ms 3668 KiB
01_random_19.txt AC 93 ms 117860 KiB
01_random_20.txt AC 1 ms 3736 KiB
01_random_21.txt AC 8 ms 12432 KiB
01_random_22.txt AC 174 ms 319204 KiB
01_random_23.txt AC 7 ms 8632 KiB
01_random_24.txt AC 22 ms 3864 KiB
01_random_25.txt AC 16 ms 4348 KiB
01_random_26.txt AC 17 ms 4080 KiB
01_random_27.txt AC 39 ms 52816 KiB
01_random_28.txt AC 22 ms 3752 KiB
01_random_29.txt AC 13 ms 4020 KiB
01_random_30.txt AC 18 ms 3936 KiB
01_random_31.txt AC 12 ms 5184 KiB
01_random_32.txt AC 15 ms 4624 KiB
01_random_33.txt AC 10 ms 13016 KiB
01_random_34.txt AC 20 ms 3844 KiB
01_random_35.txt AC 15 ms 4772 KiB
01_random_36.txt AC 16 ms 4092 KiB
01_random_37.txt AC 30 ms 18352 KiB
01_random_38.txt AC 112 ms 108932 KiB
01_random_39.txt AC 149 ms 175220 KiB
01_random_40.txt AC 163 ms 219256 KiB
01_random_41.txt AC 175 ms 250220 KiB
02_handmade_01.txt AC 276 ms 488208 KiB
02_handmade_02.txt AC 277 ms 488104 KiB
02_handmade_03.txt AC 21 ms 3444 KiB
02_handmade_04.txt AC 21 ms 3520 KiB
02_handmade_05.txt AC 5 ms 3592 KiB
02_handmade_06.txt AC 5 ms 3536 KiB
02_handmade_07.txt AC 7 ms 3944 KiB
02_handmade_08.txt AC 7 ms 3808 KiB
02_handmade_09.txt AC 9 ms 5948 KiB
02_handmade_10.txt AC 9 ms 5944 KiB
02_handmade_11.txt AC 31 ms 27756 KiB
02_handmade_12.txt AC 29 ms 27816 KiB
02_handmade_13.txt AC 160 ms 245692 KiB
02_handmade_14.txt AC 161 ms 245752 KiB