QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#378650#8576. Symphony in c++ majorucup_team_qiuly#WA 757ms106788kbC++143.1kb2024-04-06 13:59:572024-04-06 13:59:58

Judging History

你现在查看的是最新测评结果

  • [2024-04-06 13:59:58]
  • 评测
  • 测评结果:WA
  • 用时:757ms
  • 内存:106788kb
  • [2024-04-06 13:59:57]
  • 提交

answer

// 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(...) fprintf (stderr, __VA_ARGS__)

#define lep(i, l, r) for (int i = (l), i##_end = (r); i <= i##_end; ++ i)
#define rep(i, r, l) for (int i = (r), i##_end = (l); i >= i##_end; -- i)

char _c; bool _f; template <class T> inline void IN (T & x) {
	x = 0, _f = 0; while (_c = getchar (), ! isdigit (_c)) if (_c == '-') _f = 1;
	while (isdigit (_c)) x = x * 10 + _c - '0', _c = getchar (); if (_f) x = - x;
}

const int mod = 998244353;
inline int mul (int x, int y) { return 1ll * x * y % mod; }
inline int qpow (int x, int y, int r = 1) { for ( ; y; y >>= 1, x = mul (x, x)) if (y & 1) r = mul (r, x); return r; }
inline void pls (int & x, int y) { x += y; if (x >= mod) x -= mod; }
inline int add (int x, int y) { x += y; if (x >= mod) x -= mod; return x; }

const int N = 5e5 + 5;

int n, m;
char str[N], fix[N];

/*
do 0
re 3
mi 2
fa 1
so 0
la 1
ti 2
*/

const char fro[] = { 'd', 'r', 'm', 'f', 's', 'l', 't' };
const int match[] = { 0, 3, 2, 1, 0, 1, 2 };
const char sub[] = { 'o', 'a', 'i', 'e' };

const int inf = 1e9 + 7;
int tr[N << 2][5][5];

inline void chkmax (int & x, int y) { if (x < y) x = y; }

inline void pushup (int x) {
	int l = x << 1, r = x << 1 | 1;
	memset (tr[x], - inf, sizeof tr[x]);
	lep (k, 0, 4) lep (i, 0, 4) lep (j, 0, 4) {
		chkmax (tr[x][i][j], tr[l][i][k] + tr[r][k][j] + (k < 4));
	}
	lep (i, 0, 4) lep (j, 0, 4) {
		chkmax (tr[x][i][j], tr[l][i][j]);
		chkmax (tr[x][i][j], tr[r][i][j]);
	}
}
void build (int x, int l, int r) {
	if (l == r) {
		memset (tr[x], - inf, sizeof tr[x]), tr[x][4][4] = 0;
		lep (i, 0, 6) if (str[l] == fro[i]) tr[x][4][match[i]] = 0;
		lep (i, 0, 3) if (str[l] == sub[i]) tr[x][i][4] = 0;
	} else {
		int mid = l + r >> 1;
		build (x << 1, l, mid);
		build (x << 1 | 1, mid + 1, r);
		pushup (x);
	}
}
void update (int x, int l, int r, int L, int R) {
	if (L > r || R < l) return ;
	if (l == r) {
		memset (tr[x], - inf, sizeof tr[x]), tr[x][4][4] = 0;
		lep (i, 0, 6) if (str[l] == fro[i]) tr[x][4][match[i]] = 0;
		lep (i, 0, 3) if (str[l] == sub[i]) tr[x][i][4] = 0;
	} else {
		int mid = l + r >> 1;
		update (x << 1, l, mid, L, R);
		update (x << 1 | 1, mid + 1, r, L, R);
		pushup (x);
	}
}

int vec[5];
void query (int x, int l, int r, int L, int R) {
	if (L <= l && r <= R) {
		vector <int> nxt (5, - inf);
		lep (i, 0, 4) lep (j, 0, 4) chkmax (nxt[j], vec[i] + tr[x][i][j]);
		lep (i, 0, 4) chkmax (vec[i], nxt[i]);
	} else {
		int mid = l + r >> 1;
		if (L <= mid) query (x << 1, l, mid, L, R);
		if (R > mid) query (x << 1 | 1, mid + 1, r, L, R);
	}
}

signed main () {
	IN (n), IN (m), scanf ("%s", str + 1);
	build (1, 1, n);
	for (int i, j; m; -- m) {
		char opt[4]; scanf ("%s", opt);
		if (opt[0] == '?') {
			IN (i), IN (j);
			memset (vec, - inf, sizeof vec), vec[4] = 0;
			query (1, 1, n, i, j);
			printf ("%d\n", (j - i + 1) - vec[4] * 2);
		} else {
			IN (i), IN (j), scanf ("%s", fix);
			lep (p, i, j) str[p] = fix[p - i];
			update (1, 1, n, i, j);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3824kb

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: 757ms
memory: 106788kb

input:

500000 300000
rfsraltzititrofomloldlaefikdemaddaafmimiioiuaueiaedifacmxamttiiitaaltiiireexeafsaaraedosotlaioootaiosizlifiioadhnxiofsasaflleaiisstaotdlliulilxatrpdaraaraaoiaeoooiumwuumarlifesroloistedoaaieolisaoatamsredorrfiifaaidfeassfioaiasmstomasallsftsrfaiiirteomaeiirefldmlaoaofrxlaeuilioirafotoa...

output:

122161
133272
96934
55220
91561
148158
73511
4107
300804
54047
56749
265935
127618
170711
79242
209453
84746
83235
184048
77181
94078
172950
202768
97802
92457
67257
171532
145782
53866
165849
104921
179179
35076
55907
17293
74512
319361
244769
118822
162827
175178
136085
43121
237589
112904
48618
1...

result:

wrong answer 1st numbers differ - expected: '122151', found: '122161'