QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#376880 | #6509. Not Another Range Query Problem | Fido_Puppy | WA | 14ms | 10928kb | C++23 | 1.9kb | 2024-04-04 18:04:43 | 2024-04-04 18:04:44 |
Judging History
answer
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define MT make_tuple
#define IT iterator
#define fi first
#define se second
#define For(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Rep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define CLR(a, v) memset(a, v, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define debug cerr << "ztxakking\n"
#define y0 ztxaknoi
#define y1 ztxakioi
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using vi = vector<int>;
template<typename T>
using V = vector<T>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 5e5 + 7;
int n, q, t[N], ans[N];
string s;
void add(int x, int k) {
for (; x <= n; x += x & -x) t[x] += k;
}
int qry(int x) {
int ans = 0;
for (; x; x -= x & -x) ans += t[x];
return ans;
}
V<tuple<int, int, int>> v[N];
vi b[N];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> q >> s, s = '@' + s;
For(i, 1, q) {
int l, r, k; cin >> l >> r >> k;
if (!k) ans[i] = r - l + 1; else v[k].eb(l, r, i);
}
int cnt = 0;
For(i, 1, n) {
if (s[i] != s[i - 1]) cnt = 0;
++cnt, b[cnt].pb(i);
}
For(i, 1, n) add(i, 1);
For(i, 1, n) {
for (int u : b[i]) add(u, -1);
for (auto [l, r, j] : v[i]) ans[j] = qry(r);
}
CLR(t, 0);
For(i, 1, n) add(i, 1), b[i].clear();
cnt = 0;
Rep(i, n, 1) {
if (i == n || s[i] != s[i + 1]) cnt = 0;
++cnt, b[cnt].pb(i);
}
For(i, 1, n) {
for (int u : b[i]) add(u, -1);
for (auto [l, r, j] : v[i]) ans[j] -= qry(l - 1);
}
For(i, 1, q) cout << max(0, ans[i]) << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9052kb
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: 14ms
memory: 10928kb
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'