QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#83975#2135. How Many Strings Are Lesstriplem5ds#WA 11ms52696kbC++144.1kb2023-03-04 19:30:332023-03-04 19:30:37

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-04 19:30:37]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:52696kb
  • [2023-03-04 19:30:33]
  • 提交

answer

///Enta etfsh5t nseet el rank

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;
#define pb push_back
#define F first
#define S second
#define f(i, a, b) for (int i = a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x, y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll

using ll = long long;
using ull = unsigned long long;
using uint = uint32_t;
using ii = pair<int, int>;

const int N = 1e6 + 6, A = 26, LG = 18, MOD = 1e9 + 7;
const long double PI = acos(-1);
const long double EPS = 1e-9;
const ll INF = 1e15;

int tr[N][26], ptr;
int cnt[N];

void add(string s) {
    int cur = 0;
    cnt[cur] += 1;
    for (char c: s) {
        if (!tr[cur][c - 'a']) {
            tr[cur][c - 'a'] = ++ptr;
        }
        cur = tr[cur][c - 'a'];
        cnt[cur] += 1;
    }
}

struct state {
    vector<ii> queryRanges;
    int curNode, depth, curAdd;
};
set<pair<int, char>> st;
set<pair<int, char>> go[N];
int ans[N];

vector<tuple<char, int, int>> fass(int depth, int l, int r) {  ///elsamaka hh
    vector<tuple<char, int, int>> ret;
    auto it = prev(st.upper_bound({l, CHAR_MAX}));
    while (l <= r) {
        char c = it->S;
        it++;
        ret.push_back(make_tuple(c, l, min(r, it->F - 1)));
        l = it->F;
    }
    return ret;
}

int n, q;
bool vis[N];
string s;


void addEvents(int depth) {
    if (depth) {
        st.erase({0, s[depth - 1]});
    }
    for (auto p: go[depth]) {
        st.insert(p);
    }
}

void BFS() {
    queue<state> vq;
    vq.push(state{vector<ii>({ii(0, q)}), 0, 0, 0});
    while (vq.size()) {
        auto cur = vq.front();
        vq.pop();
        if (cur.depth == s.size()) continue;
        vector<tuple<char, int, int>> queries;
        if (!vis[cur.depth]) {
            addEvents(cur.depth);
            vis[cur.depth] = true;
        }
        for (auto p: cur.queryRanges) {
            auto to_add = fass(cur.depth, p.F, p.S);
            for (auto x: to_add)queries.push_back(x);
        }
        sort(rall(queries));
        int curSend = cur.curAdd;
        curSend += cnt[cur.curNode];
        for (char c = 'a'; c <= 'z'; ++c)if (tr[cur.curNode][c - 'a'])curSend -= cnt[tr[cur.curNode][c - 'a']];
        for (char c = 'a'; c <= 'z'; ++c) {
            vector<ii> to_send;
            while (queries.size() && get<0>(queries.back()) == c) {
                to_send.emplace_back(get<1>(queries.back()), get<2>(queries.back()));
                queries.pop_back();
            }
            if (!tr[cur.curNode][c - 'a']) {
                for (auto p: to_send) {
                    for (int i = p.F; i <= p.S; i++) {
                        ans[i] = curSend;
                    }
                }
            } else {
                if (to_send.size())
                    vq.push({to_send, tr[cur.curNode][c - 'a'], cur.depth + 1, curSend});
                curSend += cnt[tr[cur.curNode][c - 'a']];
            }
        }
    }

}

void doWork() {
    cin >> n >> q;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        go[i].insert({0, s[i]});
    }
    st.insert({INT_MAX, '#'});
    f(i, 0, n) {
        string str;
        cin >> str;
        if (str.size() > s.size())str.resize(s.size());
        add(str);
    }
    f(i, 1, q + 1) {
        int index;
        char c;
        cin >> index >> c;
        go[index - 1].insert({i, c});
    }

    BFS();

    f(i, 0, q + 1) cout << ans[i] << '\n';

}


int32_t main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif // ONLINE_JUDGE
    int t = 1;
//    cin >> t;
    while (t--)
        doWork();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 52624kb

input:

4 3
anatoly
boris
anatooo
anbbbbu
anba
5 o
3 b
7 x

output:

0
0
2
3

result:

ok 4 number(s): "0 0 2 3"

Test #2:

score: 0
Accepted
time: 9ms
memory: 52608kb

input:

5 5
abcde
buz
ababa
build
a
aba
1 b
3 z
2 u
4 z
1 a

output:

3
3
3
4
4
1

result:

ok 6 numbers

Test #3:

score: 0
Accepted
time: 11ms
memory: 52580kb

input:

1 1
abababababababababababab
ababababababababababababab
23 b

output:

0
1

result:

ok 2 number(s): "0 1"

Test #4:

score: -100
Wrong Answer
time: 9ms
memory: 52696kb

input:

4 100
b
dd
ds
ss
sd
1 d
1 s
1 s
1 d
1 s
1 s
1 s
1 s
1 s
1 d
1 s
1 s
1 d
1 d
1 s
1 d
1 d
1 d
1 s
1 d
1 s
1 d
1 s
1 s
1 d
1 d
1 d
1 d
1 s
1 s
1 d
1 s
1 s
1 d
1 d
1 s
1 s
1 s
1 s
1 s
1 s
1 s
1 d
1 d
1 s
1 d
1 s
1 s
1 s
1 s
1 d
1 s
1 s
1 s
1 s
1 s
1 s
1 s
1 d
1 d
1 s
1 d
1 s
1 s
1 d
1 d
1 d
1 d
1 s
1 d
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

wrong answer 3rd numbers differ - expected: '2', found: '0'