QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#262823#7748. Karshilov's Matching Problem IIzhaohaikunWA 130ms34044kbC++141.9kb2023-11-24 07:42:312023-11-24 07:42:32

Judging History

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

  • [2024-08-25 20:42:18]
  • hack成功,自动添加数据
  • (/hack/789)
  • [2023-11-24 07:42:32]
  • 评测
  • 测评结果:WA
  • 用时:130ms
  • 内存:34044kb
  • [2023-11-24 07:42:31]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T& x, T y) {x = min(x, y);}
const int N = 3e5 + 10;
int n, m, bor[N], f[N];
ll val[N], ans[N], w[N], bt[N];
char s[N], t[N], a[N];
vector <pair <int, int>> v[N];
vector <int> hh[N];
void kmp() {
	int j = 0;
	val[1] = w[1];
	F(i, 2, n) {
		while (j && s[i] != s[j + 1]) j = bor[j];
		if (s[i] == s[j + 1]) j++;
		val[i] = val[j] + w[i];
		// debug << i << " " << j << " " << val[i] << endl;
	}
}
void exkmp() {
	int mx = 0, pos;
	F(i, 1, 2 * n) {
		if (i <= mx) f[i] = min(f[i - pos + 1], mx - i + 1);
		while (i + f[i] <= 2 * n && a[f[i] + 1] == a[i + f[i]]) f[i]++;
		if (i + f[i] - 1 > mx) {
			mx = i + f[i] - 1;
			pos = i;
		}
	}
}
void modify(int x, ll y) {
	for (; x; x -= x & -x) bt[x] += y;
}
ll query(int x) {
	ll s = 0;
	for (; x <= n; x += x & -x) s += bt[x];
	return s;
}
signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	cin >> n >> m;
	cin >> (s + 1) >> (t + 1);
	F(i, 1, n) {
		a[i] = s[i];
		a[n + i] = t[i];
	}
	F(i, 1, n) cin >> w[i], w[i] += w[i - 1];
	kmp();
	exkmp();
	F(i, 1, n) f[i] = f[i + n];
	F(i, 1, m) {
		int l, r; cin >> l >> r;
		v[r].emplace_back(l, i);
	}
	set <int> s;
	F(r, 1, n) {
		s.insert(r);
		hh[r + f[r]].push_back(r);
		for (int i: hh[r]) s.erase(i), modify(i, w[f[i]]);
		for (auto [l, id]: v[r]) {
			ans[id] = query(l);
			auto pos = s.lower_bound(l);
			if (pos != s.end()) ans[id] += val[r - *pos + 1];
		}
	}
	F(i, 1, m) cout << ans[i] << '\n';
	return 0;
}
/* why?
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 24492kb

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: 25152kb

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: 0
Accepted
time: 80ms
memory: 32032kb

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:

ok 150000 lines

Test #4:

score: -100
Wrong Answer
time: 130ms
memory: 34044kb

input:

150000 150000
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

528900815691571
112638556022185
514229554849356
2216206133639915
295388515578381
1658587138269057
652142121207636
166322478628783
490195029871161
1191292846892788
1468501126902703
487990867773908
55994169916421
553022799845713
2522992078581539
2339888502167342
2881203249819745
154700081279584
152537...

result:

wrong answer 14th lines differ - expected: '568966315599642', found: '553022799845713'