QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#788603 | #6509. Not Another Range Query Problem | OIer_kzc# | WA | 24ms | 15112kb | C++20 | 1.9kb | 2024-11-27 17:37:28 | 2024-11-27 17:37:30 |
Judging History
answer
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <vector>
#include <algorithm>
#define LOG(FMT...) fprintf(stderr, FMT)
#define eb emplace_back
using namespace std;
constexpr int N = 500005;
int n, m;
char str[N];
void prework(int *pr) {
static int stk[N], tt;
tt = 0;
for (int i = 1; i <= n; ++i) {
int last = 1;
while (tt && str[stk[tt]] == str[i]) {
last = pr[stk[tt]] + 1;
--tt;
}
pr[i] = last;
stk[++tt] = i;
}
}
int pr[N], sf[N];
struct Req {
int y, k;
Req() {}
Req(int _y, int _k) : y(_y), k(_k) {}
};
vector<Req> ls[N], rs[N];
int res[N];
struct BIT {
int fw[N];
void clear() {
memset(fw, 0, sizeof fw);
}
void A(int x) {
for (; x; x &= x - 1) {
++fw[x];
}
}
int Q(int x) {
int ret = 0;
for (; x <= n; x += x & -x) {
ret += fw[x];
}
return ret;
}
} fw;
int main() {
scanf("%d%d%s", &n, &m, str + 1);
prework(pr);
reverse(str + 1, str + n + 1);
prework(sf);
reverse(sf + 1, sf + n + 1);
reverse(str + 1, str + n + 1);
/* for (int i = 1; i <= n; ++i) {
printf("%d ", pr[i]);
}
puts("");
for (int i = 1; i <= n; ++i) {
printf("%d ", sf[i]);
}
puts(""); */
for (int i = 0, k, l, r; i < m; ++i) {
scanf("%d%d%d", &l, &r, &k);
ls[r].eb(k, i);
rs[l].eb(k, i);
}
for (int i = 1; i <= n; ++i) {
fw.A(pr[i]);
for (auto [y, k] : ls[i]) {
res[k] += fw.Q(y + 1);
}
}
/* for (int i = 1; i <= n; ++i) {
LOG("%d ", fw.Q(i));
}
LOG("\n"); */
fw.clear();
for (int i = n; i; --i) {
fw.A(sf[i]);
for (auto [y, k] : rs[i]) {
res[k] += fw.Q(y + 1);
}
}
/* for (int i = 1; i <= n; ++i) {
LOG("%d ", fw.Q(i));
}
LOG("\n"); */
for (int i = 1; i <= n; ++i) {
for (auto [y, k] : rs[i]) {
res[k] -= fw.Q(y + 1);
}
}
for (int i = 0; i < m; ++i) {
printf("%d\n", max(res[i], 0));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 12592kb
input:
9 7 100110001 2 5 1 3 6 1 4 8 2 2 7 1 1 9 1 1 9 0 1 9 8
output:
2 1 1 3 4 9 0
result:
ok 7 numbers
Test #2:
score: -100
Wrong Answer
time: 24ms
memory: 15112kb
input:
100 100000 0000011010101000111011110110000111110101101010111111101011011010111001111010111000001000011000001010 76 99 3 25 84 7 45 83 11 10 12 10 69 86 4 27 28 1 22 42 42 4 86 25 26 91 22 20 81 17 50 78 0 77 93 50 31 50 34 7 46 13 78 89 0 79 98 0 2 84 33 58 93 11 56 75 2 55 77 68 7 9 41 44 46 11 47 ...
output:
5 0 0 0 1 0 0 0 0 0 29 0 0 0 12 20 0 0 3 0 0 0 0 0 0 0 0 2 18 1 0 57 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 0 0 1 0 0 0 0 0 0 0 0 8 6 0 0 0 0 0 8 0 0 16 0 19 29 40 21 12 26 0 21 6 0 7 2 0 0 0 1 0 0 0 1 0 0 0 51 0 0 0 8 11 0 9 1 9 3 0 16 22 0 2 0 6 0 0 0 0 0 0 0 46 59 0 0 43 10 0 0 0 2 15 0...
result:
wrong answer 1st numbers differ - expected: '8', found: '5'