QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#479750 | #8576. Symphony in c++ major | ucup-team3519# | WA | 1030ms | 191720kb | C++20 | 4.4kb | 2024-07-15 20:42:28 | 2024-07-15 20:42:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define pb push_back
typedef long long LL;
typedef pair<int, int> pi;
const int MN = 5e5 + 120;
//d r m f s l t
const int INF = 2e9 + 1000;
struct info {
array<array<int, 3>, 8> tab;
info() {
for(auto& a0 : tab) {
for(auto &y : a0) y = 0;
}
}
}i0;
void upd(array<int, 3> &a, array<int, 3> b) {
if(a[1] == 0) {
a = b;
return;
}
if(a[1] <= b[1]) return;
a = b;
}
void show(info i) {
cout << "show" << endl;
for(auto a8 : i.tab) {
for(auto y : a8) cout << y << " ";
cout << endl;
}
}
info operator+ (const info & a, const info & b) {
if(a.tab[0][0] == -1) return b;
info c;
// show(c);
// show(a), show(b);
for(int i = 0; i <= 7; i++) {
auto [acost, apos, ares] = a.tab[i];
// auto [acost, apos, ares] = b.tab[i];
for(int j = 0; j <= 7; j++) {
if(!(ares >> j & 1)) {
continue;
}
auto [bcost, bpos, bres] = b.tab[j];
if(bpos == INF) {
upd(c.tab[i], array<int, 3>{acost, apos, ares | bres});
} else {
upd(c.tab[i], array<int, 3>{acost + bcost, min(apos, bpos), bres});
}
}
}
// show(c);
return c;
}
info seg[MN * 4];
void pull(int x) {
seg[x] = seg[x * 2] + seg[x * 2 + 1];
}
void modify(int x, int l, int r, int p, const info &i) {
if(l == r) {
seg[x] = i;
return;
}
int mid = l + r >> 1;
if(p <= mid) modify(x * 2, l, mid, p, i);
else modify(x * 2 + 1, mid + 1, r, p, i);
pull(x);
}
info query(int x, int l, int r, int ql, int qr) {
// cout << "l , r" << l << " " << r << endl;
if(ql <= l && qr >= r) {
return seg[x];
}
int mid = l + r >> 1;
auto ans = i0;
if(ql <= mid) ans = ans + query(x * 2, l, mid, ql, qr);
if(qr >= mid + 1) ans = ans + query(x * 2 + 1, mid + 1, r, ql, qr);
return ans;
}
map<char, int> mp;
info get_info(char c, int pos) {
info in;
if(mp[c] < 0) {
int x = -mp[c];
for(int j = 0; j <= 7; j++) {
in.tab[j][1] = INF;
in.tab[j][2] = (1 << j) | (1 << x) | 1;
}
} else {
int x = mp[c];
for(int j = 0; j <= 7; j++) {
if(1 << j & x) {
in.tab[j][0] = 1;
in.tab[j][1] = pos;
in.tab[j][2] = 1;
} else {
in.tab[j][0] = 0;
in.tab[j][1] = INF;
in.tab[j][2] = 1 | 1 << j;
}
}
}
// for(auto a8 : in.tab) {
// }
return in;
}
void build(int x, int l, int r, string & s) {
if(l == r) {
seg[x] = get_info(s[l], l);
return;
}
int mid = l + r >> 1;
build(x * 2, l, mid, s), build(x * 2 + 1, mid + 1, r, s);
pull(x);
}
void solve() {
int n, q; cin >> n >> q;
string s; cin >> s;
s = " " + s;
build(1, 1, n, s);
// cout << query(1, 1, n, 2, 2).tab[0][0] << endl;
// cout << query(1, 1, n, 3, 4).tab[0][0] << endl;
// show(query(1, 1, n, 3, 3));
// show(query(1, 1, n, 4, 4));
// show(query(1, 1, n, 3, 4));
// cout << query(1, 1, n, 2, 4).tab[0][0] << endl;
// cout << query(1, 1, n, 3, 4).tab[0][1] << endl;
// for(int i = 3; i <= 4; i++) show(query(1, 1, n, i, i));
for(int i = 1; i <= q; i++) {
char t; cin >> t;
// cout << "i : " << i << endl;
// for(int i = 1; i <= n; i++) {
// show(query(1, 1, n, i, i));
// }
if(t == '#') {
int i, j; cin >> i >> j;
string s; cin >> s;
for(int t = i; t <= j; t++) {
modify(1, 1, n, t, get_info(s[t - i], t));
}
} else {
int i, j; cin >> i >> j;
cout << (j - i + 1) - 2 * query(1, 1, n, i, j).tab[0][0] << "\n";
}
}
}
int main() {
i0.tab[0][0] = -1;
mp['d'] = -1;
mp['r'] = -2;
mp['m'] = -3;
mp['f'] = -4;
mp['s'] = -5;
mp['l'] = -6;
mp['t'] = -7;
mp['o'] = 2 + 32;
mp['e'] = 4;
mp['i'] = 8 + 128;
mp['a'] = 16 + 64;
ios::sync_with_stdio(0), cin.tie(0);
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 191300kb
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: 1030ms
memory: 191720kb
input:
500000 300000 rfsraltzititrofomloldlaefikdemaddaafmimiioiuaueiaedifacmxamttiiitaaltiiireexeafsaaraedosotlaioootaiosizlifiioadhnxiofsasaflleaiisstaotdlliulilxatrpdaraaraaoiaeoooiumwuumarlifesroloistedoaaieolisaoatamsredorrfiifaaidfeassfioaiasmstomasallsftsrfaiiirteomaeiirefldmlaoaofrxlaeuilioirafotoa...
output:
135329 147566 107060 61128 101393 164026 81423 4543 333056 59871 62919 294389 141330 189129 87772 231861 93716 92193 203806 85443 104202 191424 224624 108026 102387 74575 189926 161488 59618 183689 116211 198415 38656 61921 19205 82376 353609 270913 131634 180313 193852 150813 47577 262923 125030 53...
result:
wrong answer 1st numbers differ - expected: '122151', found: '135329'