QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#147420 | #6759. 字符串 | HaccerKat# | 36 | 106ms | 66272kb | C++20 | 4.5kb | 2023-08-23 07:45:51 | 2023-08-25 01:29:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template<typename T>
int SIZE(T (&t)){
return t.size();
}
template<typename T, size_t N>
int SIZE(T (&t)[N]){
return N;
}
string to_string(char t){
return "'" + string({t}) + "'";
}
string to_string(bool t){
return t ? "true" : "false";
}
string to_string(const string &t, int x1=0, int x2=1e9){
string ret = "";
for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){
ret += t[i];
}
return '"' + ret + '"';
}
string to_string(const char* t){
string ret(t);
return to_string(ret);
}
template<size_t N>
string to_string(const bitset<N> &t, int x1=0, int x2=1e9){
string ret = "";
for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){
ret += t[i] + '0';
}
return to_string(ret);
}
template<typename T, typename... Coords>
string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C);
template<typename T, typename S>
string to_string(const pair<T, S> &t){
return "(" + to_string(t.first) + ", " + to_string(t.second) + ")";
}
template<typename T, typename... Coords>
string to_string(const T (&t), int x1, int x2, Coords... C){
string ret = "[";
x1 = min(x1, SIZE(t));
auto e = begin(t);
advance(e,x1);
for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){
ret += to_string(*e, C...) + (i != _i ? ", " : "");
e = next(e);
}
return ret + "]";
}
template<int Index, typename... Ts>
struct print_tuple{
string operator() (const tuple<Ts...>& t) {
string ret = print_tuple<Index - 1, Ts...>{}(t);
ret += (Index ? ", " : "");
return ret + to_string(get<Index>(t));
}
};
template<typename... Ts>
struct print_tuple<0, Ts...> {
string operator() (const tuple<Ts...>& t) {
return to_string(get<0>(t));
}
};
template<typename... Ts>
string to_string(const tuple<Ts...>& t) {
const auto Size = tuple_size<tuple<Ts...>>::value;
return print_tuple<Size - 1, Ts...>{}(t);
}
void dbgr(){;}
template<typename Heads, typename... Tails>
void dbgr(Heads H, Tails... T){
cout << to_string(H) << " | ";
dbgr(T...);
}
void dbgs(){;}
template<typename Heads, typename... Tails>
void dbgs(Heads H, Tails... T){
cout << H << " ";
dbgs(T...);
}
/*
formatted functions:
*/
/*
consider __VA_ARGS__ as a whole:
dbgv() prints values only
dbg() prints name and values
*/
#define dbgv(...) cout << to_string(__VA_ARGS__) << endl;
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
//#define dbg(...)
/*
consider __VA_ARGS__ as a sequence of arguments:
dbgr() prints values only
dbgm() prints names and values
*/
#define dbgr(...) dbgr(__VA_ARGS__); cout << endl;
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
// using u128 = __uint128_t;
// using i128 = __int128;
const int mod = 1000000007;
const int N = 4005;
const int LOG = 20;
const int inf = 1e9;
const double eps = 1e-11;
string s, t;
int n, m, k, qq;
int lcp[N][N];
void solve() {
cin >> n >> qq >> s;
t = s;
reverse(t.begin(), t.end());
memset(lcp, 0, sizeof(lcp));
for (int i = n - 1; i >= 0; i--) {
for (int j = n - 1; j >= 0; j--) {
lcp[i][j] = (s[i] == t[j] ? lcp[i + 1][j + 1] + 1 : 0);
}
}
while (qq--) {
int p, r;
cin >> p >> r;
p--;
int out = 0;
for (int l = 1; l <= r; l++) {
int inv = n - p - 2 * l;
int x = lcp[p][inv];
int np = p + x, ninv = inv + x;
if (x < l && s[np] < t[ninv]) out++;
}
cout << out << "\n";
}
}
int32_t main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
int c, tt;
cin >> c >> tt;
while (tt--) {
solve();
}
}
詳細信息
Test #1:
score: 4
Accepted
time: 21ms
memory: 66112kb
input:
1 5 5 5 aaaaa 4 1 2 1 2 2 2 2 4 1 5 5 abaab 1 1 1 2 2 1 3 1 1 1 5 5 baaaa 1 2 2 2 2 2 2 1 2 2 5 5 babab 1 2 2 2 4 1 2 2 2 2 5 5 baaab 2 2 2 1 1 1 1 2 2 2
output:
0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 2 1 2 2 1 0 0 0 1
result:
ok 25 numbers
Test #2:
score: 4
Accepted
time: 16ms
memory: 66144kb
input:
2 5 10 10 babbbbbaaa 1 4 9 1 6 2 2 3 2 1 1 5 1 5 4 2 1 2 2 4 10 10 baabbaabab 1 5 2 4 2 4 2 3 3 4 5 3 2 3 1 5 3 1 4 1 10 10 aaaaabaabb 1 5 6 2 3 2 2 2 1 1 5 1 1 5 1 5 1 4 3 3 10 10 babbaababb 5 3 7 1 7 2 1 4 6 1 4 2 2 4 2 4 4 1 1 5 10 10 babbbaabba 2 3 1 5 6 2 2 4 1 5 4 1 2 3 5 2 2 3 1 5
output:
2 0 0 3 1 2 2 0 1 3 1 2 2 1 3 1 1 1 1 0 3 0 1 0 0 1 3 3 2 2 2 0 1 1 1 0 3 3 0 2 2 1 1 3 1 0 2 0 2 1
result:
ok 50 numbers
Test #3:
score: 4
Accepted
time: 17ms
memory: 66112kb
input:
3 5 19 19 baaababbbbbaaabbbaa 13 1 1 7 7 6 10 2 4 5 18 1 16 1 7 6 6 5 6 5 3 8 4 7 6 3 2 8 14 3 11 4 11 3 1 4 1 9 19 19 bbaababbaaaaababbba 9 1 10 4 16 1 1 9 4 6 5 4 15 1 1 7 2 6 5 7 14 3 1 9 11 3 1 7 8 6 2 8 10 1 2 8 8 2 20 19 baabaaabaabaaaababba 3 7 1 8 4 5 14 2 7 7 1 5 1 8 15 2 2 8 2 6 3 5 2 4 6 ...
output:
0 2 0 0 4 0 0 0 4 4 6 6 3 7 2 1 1 1 3 0 2 0 2 3 1 1 1 1 2 1 2 2 1 1 2 0 2 0 4 0 1 1 4 0 0 2 5 4 3 2 2 2 6 0 5 5 2 6 1 7 2 2 1 2 0 0 2 4 5 1 5 2 4 3 1 0 6 1 0 4 7 0 0 0 4 0 4 1 1 7 1 7 4 0 0 2
result:
ok 96 numbers
Test #4:
score: 4
Accepted
time: 22ms
memory: 66132kb
input:
4 5 46 50 abababbbbbbbbbabaabaaababbaaaaabababbababaaaaa 1 13 19 1 7 19 22 7 3 21 3 17 3 21 31 6 1 23 11 4 19 11 4 17 2 21 7 20 10 8 25 9 9 19 6 4 7 18 5 4 2 1 12 9 6 20 17 13 7 1 9 17 1 21 12 6 11 11 1 23 5 16 28 6 4 17 10 2 3 19 34 5 21 13 1 23 13 6 31 5 6 20 4 20 3 21 16 1 1 21 17 2 2 19 23 4 1 7...
output:
9 0 0 3 12 11 12 5 14 0 3 5 6 0 0 0 0 0 0 4 0 0 0 10 0 0 14 0 0 14 10 4 5 0 12 1 9 14 0 5 0 5 12 0 14 1 6 1 7 8 8 7 5 15 5 0 16 0 0 13 0 5 14 9 1 14 6 0 5 15 13 9 7 1 0 3 15 4 5 5 3 1 6 1 12 3 0 16 1 7 8 3 13 0 2 0 14 0 3 1 4 0 8 7 3 8 8 13 7 1 13 13 15 3 9 3 9 10 1 10 1 0 10 15 5 0 5 6 2 9 0 12 5 4...
result:
ok 246 numbers
Test #5:
score: 4
Accepted
time: 24ms
memory: 66188kb
input:
5 5 97 98 bbaabaabbababaaaababaabababaabaababbbbbbaababaabaaabbaabbabaabbaababbabbbbbaababbbbabbbbbbbaaaaab 71 13 77 7 13 3 14 40 18 21 13 38 20 18 2 48 30 27 84 4 3 34 4 15 18 36 55 20 3 44 9 36 10 24 15 8 55 15 48 6 38 18 30 16 19 7 4 47 76 4 36 28 3 38 7 43 13 3 7 22 55 12 9 22 26 17 30 23 24 31 ...
output:
1 7 0 38 7 18 8 25 15 4 30 9 17 15 40 5 14 7 11 3 1 8 4 31 3 3 34 24 0 8 8 3 12 13 20 8 0 0 6 5 9 10 16 21 2 16 1 24 2 9 6 9 31 15 26 7 9 12 25 0 18 0 19 24 31 18 41 3 9 13 11 19 0 1 25 1 0 22 27 17 35 0 7 10 3 9 21 5 15 0 33 2 5 5 18 24 9 20 5 14 1 12 4 15 0 10 9 4 6 18 2 10 3 31 14 26 13 1 13 6 4 ...
result:
ok 482 numbers
Test #6:
score: 4
Accepted
time: 30ms
memory: 66124kb
input:
6 5 998 992 bibbaabpaapbaabbibbbbabbaabbaafbaabbaabbaabbaabfaabbaabbabbbabbbaabpaapbaabbbabobabbaabbaafbaabbaabbaabbaabfaabbaabbabbbbbbbaabpaapbaabbbbbbbabbaabbaafbaabbaabbaabbaabfaabbaabbabobabbbaabpaapbaabbbabbbabbaabbaafbaabbaabbaabbaabfaabbaabbabbbbibbaabpaapbaabbibbbbabbaabbaafbaabbaabbaabbaabf...
output:
32 48 41 62 267 134 145 111 337 312 88 335 139 173 174 97 77 19 155 291 125 23 110 17 13 167 61 126 6 74 214 59 0 200 42 47 125 9 3 119 132 216 0 31 105 61 4 355 141 39 53 60 89 39 52 208 259 17 12 194 355 77 65 53 298 60 138 308 198 120 118 114 207 8 9 68 264 307 366 2 356 6 15 32 120 56 6 93 67 36...
result:
ok 4970 numbers
Test #7:
score: 4
Accepted
time: 48ms
memory: 66132kb
input:
7 5 1988 1997 bvappavbbaabavavpavbbaabbvappavbbaabbvappavbbaabbvappavbbaaqbvappavbbaabbvappavbqaabbvappavbbaabbvappavbbaabbvappavbbaabbvappavabaabbvappavbbaaqbvappavbbaabbpappavbqaabbvappavbbaabavappavbbaabbvappavbbapbbvappavbbaabbvappavbbaaqbvappavbbaabbvappavbqaabbvappavbbaabbvappavbbpabbvappavbba...
output:
20 302 418 404 6 12 674 787 520 153 145 127 633 4 157 792 146 103 326 395 41 38 130 151 222 2 8 301 48 314 90 194 37 53 6 124 558 828 512 89 13 140 221 47 492 94 123 111 63 12 436 34 1 169 681 135 205 303 114 453 96 227 420 112 663 85 43 104 713 28 42 8 17 180 613 81 19 713 89 446 260 171 14 501 58 ...
result:
ok 9977 numbers
Test #8:
score: 4
Accepted
time: 68ms
memory: 66204kb
input:
8 5 2977 2978 aabaaaabaabaaaabaabaaaabaabnaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaanbaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaa...
output:
465 335 734 0 461 942 8 412 161 207 532 754 409 375 164 1044 567 1109 1112 1041 96 400 888 1263 30 1029 887 56 614 1099 98 765 128 841 54 372 16 9 935 124 1072 706 232 790 558 16 371 264 52 1255 661 391 0 358 492 696 1197 441 183 129 493 740 256 128 584 53 1185 239 1214 891 844 151 401 243 395 1134 ...
result:
ok 14916 numbers
Test #9:
score: 4
Accepted
time: 106ms
memory: 66272kb
input:
9 5 3992 3963 baaamarbaaaabramaaabbaabmarbaaaabrambaabbaabmarbaaaabrambaabbaabmarbaaaabrambbabbaabmarbaaaabrambaabbaabmarbaaaabrambaabbaaamarbaaaabramaaabbaabmarbaaaabrambaabbaabmarbaaaabrambaabbabbmarbaaaabrambaabbaabmarbaaaabrambaabbaabmarbaaaabrambaabbaaamarbaaaabramaaabbaabmarbaaaabrambaabbaabma...
output:
336 177 335 701 21 1027 512 925 1488 1776 101 446 1240 1607 541 20 314 269 324 474 86 1128 18 372 311 1047 462 80 1177 972 201 5 626 845 652 719 476 86 361 699 827 499 1740 121 325 435 40 891 201 204 62 132 1255 52 813 492 867 845 793 61 1432 1544 5 27 51 19 428 842 1242 752 1302 225 176 108 1154 31...
result:
ok 19867 numbers
Test #10:
score: 0
Runtime Error
input:
10 5 21773 22026 babaaababbabbbbbaababbababaabbababbabbbbabaaaaabaabbabbbbbbaaaabaababbbabbbbbabaababbaababbbbaaabaabbaaaabbbbaaaabbbbbabaaaaaaaabbabbabbaabbbbabbbaaabbabbabababbaabaabbaabbaaaaabaabaababaabbaaaaaabababbaabbababaabbabbaaaaaaaaabbaabbbaabbababbbbbaaaaaabaaabbbaabaaabbabbabaabbbbabbabb...
output:
result:
Test #11:
score: 0
Runtime Error
input:
11 5 47391 45803 aababababbbbbbbbbbbaabaabababaababbbbabbabbabaabbbbabbbbaaaababbabababbabbabbaabbbaaabaaaabbbabababbaababbbabbabbabbbabaabbabaabaaaabbbbbbbbabbbbbababbaaababbbababbabaababbaaaaaaaaabaababaababbaaaabbbbaaababbaabaaabbabaaaaaabbababababbababaaaabbbaaaaaaaaaaabbbbbbbabbbaaabababaaababa...
output:
result:
Test #12:
score: 0
Runtime Error
input:
12 5 69918 68763 bbabbbabbbaaabaabbbbbbbbbabbbbbbbbaaabaabaabbbaabaaaabbabbabbbbbabbbbaabaaaabaabbababbbbbaaababbabbbbaabbbaaabaaaaababaaabbbbababababbababbbaaabbbbaabbabbbbbbbbabbabbbbaaabbbbaaababbbaaabaaabbabaaabbaabbbaaabbbbbbaabaabbbaabaaabbbabbbbbaabaabbabbbabbababbaaaabbbbbbbaabaaaabbabaaaaab...
output:
result:
Test #13:
score: 0
Runtime Error
input:
13 5 86855 85346 bbaaababbbbbaaaabbbaabbabbabbaabbbabbbbbbbaabaabbaabbaaaabbabaaaabbaaaabababbbbbbbbaabbabababaabaababaaabbabaabaaabaabaabbbabbabbbaabaaaabbbbabbbaabbabaabbabbbaabbbbbaaaaabbbbaaaababbbabaaabaababaababaaabbbaaaababbabaababaabababaababbabbbabaabaaabbabababbbbbbaaaababababbabaabaaaaabb...
output:
result:
Test #14:
score: 0
Runtime Error
input:
14 5 95651 97657 babbbababaaaabaaaaaaaabbaaabaababbaabbaabbabbaaabababaabaaaabaaaabbbabbabbaaaabbaabbbbbbbbaabbaabbbaaabaaabababbabababbabbbababaabaababbaabbababbbabbbbabbbbabbaaaaabaaaabbabbbabbbabbaababbbabbaaabaabbbbbbbabbabbbabaaaabaaaaaaaababaababbabaaaabaababaababbaaaaababaaabbbbabababbbabaabb...
output:
result:
Test #15:
score: 0
Runtime Error
input:
15 5 21209 21227 babababakakababfbrbabababauabababfbababababakabababfbababababakabababfbababababakabababfbababababakabababfbababababakabababfbalabababakabababfbababababakabababfbrbabababauabababfbababababakabababfbababababakabababfbababababakabababfbababababakabababfbababababakabababfbababababakabab...
output:
result:
Test #16:
score: 0
Runtime Error
input:
16 5 73529 68306 babsbababwbsbabsbabababsbabsbababwbsbadsbababwbsbabsbabsbwbsbabsbababwbsbabsbababwbsbabsbababwbsbabsbabababsbabsbababwbsbadsbababwbsbabsbabsbwbsbabsbababwbsbabsbababwbsbrbsbababwbsbabsbabababsbabsbababwbsbadsbababwbsbabsbabsbwbsbabsbababwbsbabsbababwbsbabsbababwbsbabsbabababsbabsbab...
output:
result:
Test #17:
score: 0
Runtime Error
input:
17 5 87085 88577 ababababababvbabababababababababababvbabababababababababababvbabababatabababababababvbabababababababababababvbabababababababababababvbabababababababababababvbabababababababababababvbabababababababababababvbabababababababababababvbabababababababababababvbabababatabababababababvbababa...
output:
result:
Test #18:
score: 0
Runtime Error
input:
18 5 99489 97628 abababacababababacababababacababababacababababacababababacababababacababababacababababacababayabacababababacabababxbacababababacababababacababababacababababacababababacababababacababababacababababacababababacababayabacababababacababababacababababacababababacababababacababababacababa...
output:
result:
Test #19:
score: 0
Runtime Error
input:
19 5 23197 23286 abbbaabaaabbaabbaaabaabbbabbabbhaabaaabbaabbaaabaabbbabbambbaabaaabbaabbaaabaabbmabbabbbaabaaabbaabbaaabaabbbabbabbbaabaaabbaabbaaabaabbbabbabbbaabaaabbaabbaaabaabbaabbambbaabaaabbaabbaaabaabbmabbabbbaabaaabbaabbaaabaahbbabbabbbaabaaabbaabbbaabaabbbabbabbbaabaaabbaabbaaabaabbbabbamb...
output:
result:
Test #20:
score: 0
Runtime Error
input:
20 5 49694 49669 bbabbbbbbabbbbbbbaabbbbbbaabbbbbbasbbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbsabbbbbbaabbbbbbaabbbbbbbabbbbbbabbbbbbbaabbbbbbaabbbbbbasbbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbsabbbbbbaabbbbbbaabbbbbbbabbbbbbabbbbbbbaabbbbbbaabbbbbbasbbbbbbaabbbbbbaabbbbbbaa...
output:
result:
Test #21:
score: 0
Runtime Error
input:
21 5 74422 74421 baabbllbbaabblabbaabbllbbaabbllbblabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbblbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllpbaabbllbbaabbllbbaabpllbbaa...
output:
result:
Test #22:
score: 0
Runtime Error
input:
22 5 89983 89431 bajbbbzbbaabbzabbjabbaabbajbbazbbaabbzbbbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbjabbaabbajbbbzbbaabbzabbjabbaabbajbbazbbaabbzbbbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbja...
output:
result:
Test #23:
score: 0
Runtime Error
input:
23 5 94783 94700 baabaaaabaabbaabbaabaaaabaabbaabbaabaaaabaabbaaabaabavaabaabaaabbaabaaaabaabbaabbaapaaaabaabbaabbaabaaaabaabbaaabaabaaaabaabaaabbaabaaaabaabbaaabaabaaaabaabbaabbaabaaaabaabbaaabaabaaaabaabaaabbaabaaaabaabbaabbaabaaaabaabbaabbaabaaaabaabbaaabaabaaaabaabaaabbaabaaaabaabbaabbaabaaaabaa...
output:
result:
Test #24:
score: 0
Runtime Error
input:
24 5 99576 99977 babbbaabbaabbbabbaabbadbbaabbaabbdabbaabbadbbaabbaabbdabbaabbabbbaabbaabbbabbaabbadbbaabbaabbdabbaabbadbbaabbaabbdabbaabbabbbaabbaabbbabbaabbadbbaabbaabbdabbaabbadbbaabbaabbdabbaabbabbbbabbaabbbabbaabbadbbaabbaabbdabbaabbadbbaabbaabbdabbaabbabbbaabbaabbbabbaabbadbbaabbaabbdabbaabbad...
output:
result:
Test #25:
score: 0
Runtime Error
input:
25 5 99821 99309 aabbaabbaxbbaabbaabbaabbxabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbabbbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbbabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaxbbaabbaabbaabbxabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbabbbaabeaabbaab...