QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#381683 | #8576. Symphony in c++ major | ucup-team004# | WA | 561ms | 85812kb | C++20 | 2.9kb | 2024-04-07 20:16:28 | 2024-04-07 20:16:30 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr int inf = 1E9;
struct Info {
int f[5];
int g[5];
Info() : f{}, g{0, 2, 4, 8, 16} {}
};
Info operator+(Info a, Info b) {
Info c;
for (int i = 0; i <= 4; i++) {
if (a.g[i] == 0) {
c.f[i] = a.f[i] + b.f[i];
c.g[i] = b.g[i];
} else {
for (int j = 1; j <= 4; j++) {
if (a.g[i] >> j & 1) {
int v = a.f[i] + b.f[j];
int s = b.g[j];
if (v > c.f[i]) {
c.f[i] = v;
c.g[i] = s;
} else if (v == c.f[i]) {
c.g[i] |= s;
}
}
}
}
}
return c;
}
constexpr int N = 1 << 20;
Info t[N];
Info val[N];
void build(int p, int l, int r) {
if (r - l == 1) {
t[p] = val[l];
return;
}
int m = (l + r) / 2;
build(2 * p, l, m);
build(2 * p + 1, m, r);
t[p] = t[2 * p] + t[2 * p + 1];
}
void modify(int p, int l, int r, int x, const Info &v) {
if (r - l == 1) {
t[p] = v;
return;
}
int m = (l + r) / 2;
if (x < m) {
modify(2 * p, l, m, x, v);
} else {
modify(2 * p + 1, m, r, x, v);
}
t[p] = t[2 * p] + t[2 * p + 1];
}
Info query(int p, int l, int r, int x, int y) {
if (l >= y || r <= x) {
return {};
}
if (l >= x && r <= y) {
return t[p];
}
int m = (l + r) / 2;
return query(2 * p, l, m, x, y) + query(2 * p + 1, m, r, x, y);
}
Info ch[128];
int id[128] {};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
id['a'] = 1;
id['e'] = 2;
id['i'] = 3;
id['o'] = 4;
for (auto s : std::vector<std::string>{"do", "re", "mi", "fa", "so", "la", "ti"}) {
for (int i = 0; i <= 4; i++) {
ch[s[0]].g[i] = (i == 0 ? 0 : 1 << i) | 1 << id[s[1]];
}
ch[s[1]].f[id[s[1]]] = 1;
ch[s[1]].g[id[s[1]]] = 0;
}
int n, q;
std::cin >> n >> q;
std::string s;
std::cin >> s;
for (int i = 0; i < n; i++) {
val[i] = ch[s[i]];
}
build(1, 0, n);
while (q--) {
char c;
std::cin >> c;
if (c == '?') {
int l, r;
std::cin >> l >> r;
l--;
auto res = query(1, 0, n, l, r);
int ans = r - l - 2 * res.f[0];
std::cout << ans << "\n";
} else {
int l, r;
std::cin >> l >> r;
l--;
std::string t;
std::cin >> t;
for (int i = l; i < r; i++) {
modify(1, 0, n, i, ch[t[i - l]]);
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 85544kb
input:
8 10 eldorado ? 1 3 ? 1 8 # 6 7 it ? 1 8 # 3 3 t ? 1 8 # 1 8 streamer ? 1 8 # 1 8 symphony ? 1 8
output:
3 4 6 6 6 6
result:
ok 6 numbers
Test #2:
score: -100
Wrong Answer
time: 561ms
memory: 85812kb
input:
500000 300000 rfsraltzititrofomloldlaefikdemaddaafmimiioiuaueiaedifacmxamttiiitaaltiiireexeafsaaraedosotlaioootaiosizlifiioadhnxiofsasaflleaiisstaotdlliulilxatrpdaraaraaoiaeoooiumwuumarlifesroloistedoaaieolisaoatamsredorrfiifaaidfeassfioaiasmstomasallsftsrfaiiirteomaeiirefldmlaoaofrxlaeuilioirafotoa...
output:
90843 99072 72316 41262 67939 110136 54559 3041 223822 40233 42201 197919 94830 126757 58804 155821 63302 61949 136726 57421 69810 128820 150532 72952 68463 49961 127366 108306 40194 123129 78087 133073 26206 41495 12847 55526 237639 182181 88298 121139 130364 101253 32189 176841 83998 36212 146517 ...
result:
wrong answer 1st numbers differ - expected: '122151', found: '90843'