QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#719855#7748. Karshilov's Matching Problem IIMine_KingWA 88ms17204kbC++142.2kb2024-11-07 09:25:032024-11-07 09:25:04

Judging History

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

  • [2024-11-07 09:25:04]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:17204kb
  • [2024-11-07 09:25:03]
  • 提交

answer

// 長い夜の終わりを信じながら
// Think twice, code once.
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define eputchar(c) putc(c, stderr)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define eputs(str) fputs(str, stderr), putc('\n', stderr)
using namespace std;

int n, m;
long long w[150005];
string s, t;
int nxt[150005], z[300005], ri[300005];
long long val[150005], sum[150005];
struct SegmentTree {
#define ls(x) ((x) * 2)
#define rs(x) ((x) * 2 + 1)

	int mx[600005], l[600005], r[600005];

	void build(int ll, int rr, int now = 1) {
		l[now] = ll, r[now] = rr;
		if (ll == rr) {mx[now] = ll + z[n + 1 + ll] - 1; return;}
		int mid = (ll + rr) / 2;
		build(ll, mid, ls(now)), build(mid + 1, rr, rs(now));
		mx[now] = max(mx[ls(now)], mx[rs(now)]);
		return;
	}
	int query(int ll, int rr, int val, int now = 1) {
		if (ll <= l[now] && r[now] <= rr) {
			if (mx[now] < val) return 0;
			if (l[now] == r[now]) return l[now];
			if (mx[ls(now)] >= val) return query(ll, rr, val, ls(now));
			else return query(ll, rr, val, rs(now));
		}
		int mid = (l[now] + r[now]) / 2;
		if (rr <= mid) return query(ll, rr, val, ls(now));
		else if (mid < ll) return query(ll, rr, val, rs(now));
		else return query(ll, rr, val, ls(now)) ? : query(ll, rr, val, rs(now));
	}

#undef ls
#undef rs
} tr;

int main() {
	scanf("%d%d", &n, &m);
	cin >> s >> t;
	s = " " + s, t = " " + t;
	for (int i = 1; i <= n; i++) scanf("%lld", &w[i]);
	val[1] = w[1];
	for (int i = 2, j = 0; i <= n; i++) {
		while (j && s[j + 1] != s[i]) j = nxt[j];
		if (s[j + 1] == s[i]) nxt[i] = ++j;
		val[i] = val[j] + w[i];
	}
	for (int i = 1; i <= n; i++) val[i] += val[i - 1], w[i] += w[i - 1];
	string ss = s + t;
	ss[n + 1] = '#';
	for (int i = 2, j = 0; i <= 2 * n + 1; i++) {
		if (i < j + z[j]) z[i] = min(z[i - j + 1], j + z[j] - i);
		while (i + z[i] <= 2 * n + 1 && ss[i + z[i]] == ss[1 + z[i]]) z[i]++;
		if (i + z[i] > j + z[j]) j = i;
		if (i > n + 1) sum[i - n - 1] = sum[i - n - 2] + w[z[i]];
	}
	tr.build(1, n);
	while (m--) {
		int l, r;
		scanf("%d%d", &l, &r);
		int pos = tr.query(l, r, r);
		printf("%lld\n", sum[pos - 1] - sum[l - 1] + val[r - pos + 1]);
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 12000kb

input:

8 5
abbabaab
aababbab
1 2 4 8 16 32 64 128
1 1
2 3
3 5
4 7
1 8

output:

1
3
3
16
38

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 9968kb

input:

15 4
heheheheehhejie
heheheheheheheh
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
2 3
4 8
2 6
1 15

output:

3
13
13
174

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 88ms
memory: 17204kb

input:

150000 150000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

108147037823514
221878585246974
455339807727642
440286198422821
148115747906237
88695249853257
351159618462315
58850354020997
65824434822005
270158033672354
197732558443069
298193894693053
239511187032650
28139154231325
408380171835227
268053430937402
32417121185965
104813548228675
44074926058619
78...

result:

wrong answer 193rd lines differ - expected: '355571725239632', found: '365268496360949'