QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#83976#2135. How Many Strings Are Lesstriplem5ds#TL 1639ms176140kbC++144.3kb2023-03-04 19:37:272023-03-04 19:37:28

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:37:28]
  • 评测
  • 测评结果:TL
  • 用时:1639ms
  • 内存:176140kb
  • [2023-03-04 19:37:27]
  • 提交

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()) {
            for (auto p: cur.queryRanges) {
                for (int i = p.F; i <= p.S; i++) {
                    ans[i] = cur.curAdd;
                }
            }
            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;
}

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 54708kb

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: 8ms
memory: 52612kb

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: 14ms
memory: 52536kb

input:

1 1
abababababababababababab
ababababababababababababab
23 b

output:

0
1

result:

ok 2 number(s): "0 1"

Test #4:

score: 0
Accepted
time: 8ms
memory: 52600kb

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
2
2
0
2
2
2
2
2
0
2
2
0
0
2
0
0
0
2
0
2
0
2
2
0
0
0
0
2
2
0
2
2
0
0
2
2
2
2
2
2
2
0
0
2
0
2
2
2
2
0
2
2
2
2
2
2
2
0
0
2
0
2
2
0
0
0
0
2
0
2
2
0
0
2
2
2
0
2
0
0
2
2
2
2
0
0
0
0
2
2
0
2
2
2
2
0
2
2
2

result:

ok 101 numbers

Test #5:

score: 0
Accepted
time: 13ms
memory: 52548kb

input:

10 10
lvv
lvvl
lll
ll
vvll
vl
vllvv
vll
vllvl
llvl
vv
2 l
1 l
3 v
1 v
1 v
3 l
3 l
1 l
2 v
1 v

output:

3
1
1
2
10
10
9
9
1
3
10

result:

ok 11 numbers

Test #6:

score: 0
Accepted
time: 4ms
memory: 54660kb

input:

20 20
ffffqqqfqq
fffqfff
fq
qqfqff
fqfqqqf
fqfqf
fqfffffqfq
fqffffq
qfffqqfq
f
qq
f
fffffqq
q
qqqqffffq
qfqqqfff
ffqff
qqfqfqf
qqfq
qqqqfqqqf
ffqqfffqf
8 f
5 q
8 f
2 q
2 f
3 f
6 f
4 q
2 f
10 f
9 q
10 q
2 q
10 f
5 f
6 f
5 f
7 f
6 f
3 q

output:

3
3
3
3
11
2
2
2
4
2
2
2
2
11
11
11
11
11
11
11
11

result:

ok 21 numbers

Test #7:

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

input:

4 100
enf
gggppp
ppggpg
pggpgp
gppgpg
2 g
2 p
2 p
3 p
1 p
1 g
3 p
1 g
3 p
2 g
3 g
2 p
3 p
3 p
3 p
3 p
2 g
3 g
1 g
2 p
1 g
3 p
1 p
1 p
1 g
2 g
2 g
1 g
1 p
3 g
1 g
3 p
1 g
2 g
1 g
3 g
1 p
3 p
1 p
2 g
2 g
2 g
1 p
3 p
1 p
2 g
2 g
2 p
2 p
2 g
2 p
2 p
2 p
1 g
2 p
1 g
3 p
2 g
3 g
1 g
2 g
1 g
1 p
2 p
1 g
3 ...

output:

0
0
0
0
0
4
0
1
0
1
0
0
1
1
1
1
1
0
0
0
1
0
1
4
4
0
0
0
0
4
3
0
1
0
0
0
0
4
4
4
2
2
2
4
4
4
2
2
4
4
2
4
4
4
0
1
0
1
0
0
0
0
0
4
4
0
1
0
1
0
1
0
0
4
3
4
4
4
4
2
0
0
1
0
0
0
0
1
0
1
0
1
1
1
0
0
1
1
0
1
4

result:

ok 101 numbers

Test #8:

score: 0
Accepted
time: 13ms
memory: 52564kb

input:

50 50
yyy
iyiyiyyyiiii
yiiiyyyiiiyi
iiiiiiyyyyiiiyiyii
yiyyiyyiiy
yyyiiyiyiiyiiiyyyyiyy
iiyyyyyiiiiiiiiyyiyiyii
iy
iiyiyiiii
yyiiiiiyyyy
yiyiyiiiiiyiyyyiiyiy
iiiiiyyyy
yyiiiiyiiiyyiiy
iiyyiyyiyyiiyyyyiiiiyiiyiiyiyii
iiiiyyyiiyii
i
iiyyyyyyiiyiyii
iiyiiyyiyyyyyiiiiyiy
yyiyiyyyyiiyyiiyyiyyiyi
yyyiiyiy...

output:

45
45
22
22
45
45
45
45
2
45
37
22
22
22
33
22
22
22
22
33
45
2
2
45
45
45
45
45
45
45
45
45
37
45
45
45
37
45
2
2
19
45
37
45
37
45
45
2
2
7
7

result:

ok 51 numbers

Test #9:

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

input:

250 250
sbabbsb
bsbbb
asssaasbssa
sbaabbabaasbabaaabasaasbbsabbaaasasbsbbbaabs
sasasbbbbaassssabssaabasababssaaabaabssbsass
b
basasabbsbasaasbabsabbsabassbabssbasbbsaa
ssbassbaasbsabssssssasbsassabsasbsbsbsaasbsb
baabbsaabsbbassasasssbabsaaabababbsb
sababssaabababaaa
sbba
basaassbbsbaaaasbssbbbsbsbb...

output:

203
203
201
209
2
8
2
4
2
2
48
48
42
138
2
13
13
13
13
13
13
13
13
48
48
2
13
29
24
24
29
29
21
21
90
250
249
250
209
209
209
209
209
209
209
250
242
242
250
250
249
209
213
171
171
209
209
209
209
209
209
171
250
2
2
29
16
21
21
14
14
2
8
8
8
48
48
48
90
90
76
2
2
6
2
16
29
27
29
2
13
29
29
29
29
2...

result:

ok 251 numbers

Test #10:

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

input:

2500 2500
xdwxxxdxwxdwdxdwwwwdwxdxdwwxdxwwdxxdwwwdxxxxxdddwwwxdwxdxxxdwdwxxwwwwxwxdxwxdxdxwdxdxxdwdwxwwxddwwxdddddxxxddxwwxwxwxddwwxdwdxwxdxwwxdddwxwxwwddxdxdddwxwdwwdwwdwwxwdw
wwwwxwdxdxddwxwwdwwxxddxxw
w
wdxwxxxxwdwxdwdxxwwdxxxwwxwwxdwxwddddxwdwdxwdddxxdxddwwxddddxxxxdxwdwdwdxxxwdxwxxdwddwddwxwxww...

output:

1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1254
1254
1254
1254
...

result:

ok 2501 numbers

Test #11:

score: 0
Accepted
time: 121ms
memory: 70176kb

input:

10000 100000
bbbbjbbrrbjrjr
brjbrbjbjbrbjrbrjrbjbjrrjjbrjrjbjjrjr
bbjjbbjrbbbbrjjrbbbbrrbrjrbrbjjbbjbbbj
jbbrjbjbjjbbbjbrbbrbjbbrrbrbrrbrrbjbjjjrbjrrrrrbjbbjrrjjbrjjrbrrrbb
b
jjbrjrjrrrjbbbrjjbjjjbrrbbjjjjjjbrrbjjbrrrjrrjrbjrrbbjbrjj
jbjrbbrbjjjjbrbbrbjbrbjjbjrbbjjrjrbrjjbjjbbjjbbjjjbrbrrb
jjrbbrbrr...

output:

91
91
90
90
90
90
91
91
91
91
99
99
5034
5034
5033
5045
5034
5034
5034
5034
5034
5034
59
59
59
59
59
59
59
59
60
10000
9999
8383
8383
8383
10000
5034
5034
3396
3511
4524
4524
4480
4482
4482
3396
3396
3413
3413
3413
3396
10000
9997
9997
9997
9997
9997
8889
8383
8383
8383
8390
7812
8383
8385
8383
8383...

result:

ok 100001 numbers

Test #12:

score: 0
Accepted
time: 16ms
memory: 56076kb

input:

31313 31313
plg
pqgqgaglaal
lag
lagqgqppqap
agpgglg
aaaaglgpqg
pap
lggap
llgaqqqpgpqg
ppllllaqgaqg
lalglplp
al
laglag
aaq
qalaapppg
p
lqg
gpalqq
apllpqqp
qp
qqgaqpgg
lqqg
qp
qlgqagpgggg
gagqaaqp
lqllpplaalpl
ag
p
qpppqaaal
qppgqaalqaa
lqql
la
qaglaa
glpapqlagqlp
aaaqagaqqql
pggqgqlqlpq
qlqggg
g
lagl...

output:

21893
8285
10985
10985
9667
23496
23496
20763
20975
31092
28391
31092
30496
30694
8285
10985
11197
16009
15597
16009
675
6114
5930
16009
31092
27062
26864
23496
23053
23496
24821
16009
18619
13220
31092
29755
16009
16009
16009
18619
18418
18005
16009
17331
18619
14635
14635
15280
8285
8716
8285
675
...

result:

ok 31314 numbers

Test #13:

score: 0
Accepted
time: 119ms
memory: 68528kb

input:

313131 131313
ysy
ys
gsg
i
g
s
isi
i
i
yia
say
g
ig
ig
aai
a
ag
aga
ig
ag
ya
gyi
is
agy
g
yi
gg
gga
ia
ag
yy
ggg
sa
y
sgs
aa
gai
i
i
s
ia
aii
sag
si
a
a
i
a
i
iig
sss
i
ig
gys
gg
i
igy
y
gg
gg
ya
yaa
aii
yi
ss
iag
say
siy
iy
gss
gi
y
a
sy
g
aa
ai
si
a
as
ia
iyg
sy
sga
gs
sis
ys
iyy
iya
s
g
y
ii
sis
...

output:

304123
312262
312262
275523
303314
303314
312262
275523
276335
293975
312262
303314
302486
25081
61655
58283
58283
43370
43370
61655
43370
52466
25081
25887
312262
284732
285545
284732
240474
240474
312262
96576
240474
239617
238827
237997
212894
240474
240474
240474
96576
124117
87296
240474
240474...

result:

ok 131314 numbers

Test #14:

score: 0
Accepted
time: 816ms
memory: 176140kb

input:

1000000 1000000
s
v
c
g
g
w
q
p
o
x
b
r
q
t
l
w
a
e
v
a
d
i
i
u
i
b
m
x
d
x
p
f
d
d
h
j
o
p
y
x
r
h
d
w
n
w
z
i
z
r
j
w
j
j
y
s
m
j
e
z
k
m
p
j
k
o
h
d
z
i
k
h
w
k
h
v
i
r
b
z
x
a
v
b
y
r
a
h
y
z
v
l
u
z
y
e
e
s
z
z
w
p
t
d
b
h
b
h
m
q
v
b
e
f
d
r
q
t
n
i
t
u
f
q
h
p
d
m
x
b
k
k
d
z
c
l
q
w
o
x
b
j
...

output:

692520
807920
769459
538901
884904
500731
269604
538901
192697
38637
500731
154156
731303
423808
846522
231505
154156
654155
347013
846522
731303
76958
769459
115440
961752
884904
385537
884904
115440
154156
385537
731303
423808
615645
38637
231505
347013
192697
192697
231505
500731
385537
807920
19...

result:

ok 1000001 numbers

Test #15:

score: 0
Accepted
time: 1639ms
memory: 159248kb

input:

149439 1000000
pkmzs
zmzmzsp
zspzzmz
msszk
szkmsk
mpspkk
kzzspzs
kkspmss
kkskmpp
pkksk
szsmkpk
kpppspp
kppzks
skkmksp
kzzspsm
pkpkksp
kkkpzzs
kzssmkm
psspsz
smskk
kzssmsp
mszkppk
kzpskzp
kmmpsks
pzkzzks
pkppmkk
mmszspz
kmpkmpm
mkkpsmp
kmkzmpz
kzzpskz
zk
kkppspk
mmmkmzk
zmssmp
zzpkmk
pkzzzpp
ssskpmz
...

output:

69506
45944
60867
60650
9
18393
20218
19522
19575
45944
66612
66179
66101
85024
94244
90581
149402
137913
140215
139531
139642
9
27575
22131
23213
23090
18393
22063
21834
85024
88696
87275
87398
149402
126424
127297
127154
9
9187
14606
13568
13511
120639
114893
116035
116260
116187
45944
53708
51904...

result:

ok 1000001 numbers

Test #16:

score: -100
Time Limit Exceeded

input:

2 1000000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:


result: