QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298018#7748. Karshilov's Matching Problem IIDualqwqWA 123ms32316kbC++201.7kb2024-01-05 15:55:232024-01-05 15:55:23

Judging History

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

  • [2024-08-25 20:42:18]
  • hack成功,自动添加数据
  • (/hack/789)
  • [2024-01-05 15:55:23]
  • 评测
  • 测评结果:WA
  • 用时:123ms
  • 内存:32316kb
  • [2024-01-05 15:55:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
typedef pair<int,int> pii;
#define FI first
#define SE second
#define mkp make_pair
int n,Q;
char s[N],t[N];
int nxt[N],Z[N],L[N];
ll w[N],sum[N];
int ql[N],qr[N];
ll ans[N];
set<int> Is;
vector<int> del[N]; // i + L[i]
vector<int> Qs[N];
struct BIT {
	ll tr[N];
	#define lowbit(x) (x&(-x))
	inline void upd(int x,ll v) { for(int i = x;i <= n;i += lowbit(i)) tr[i] += v;}
	inline ll Sum(int x) { ll res = 0;for(int i = x;i;i ^= lowbit(i)) res += tr[i];return res;}
} C;
int main() {
	scanf("%d%d",&n,&Q);
	scanf("%s%s",s + 1,t + 1);
	for(int i = 1;i <= n;i++) scanf("%lld",&w[i]),w[i] += w[i - 1];
	for(int i = 1;i <= Q;i++) scanf("%d%d",&ql[i],&qr[i]),Qs[qr[i]].push_back(i);
	Z[1] = n;
	for(int i = 2,l = 0,r = 0;i <= n;i++) {
		if(i <= r) Z[i] = min(Z[i - l + 1],r - i + 1);
		while(s[1 + Z[i]] == s[i + Z[i]]) ++Z[i];
		if(i + Z[i] - 1 > r) l = i,r = i + Z[i] - 1;
	}
	for(int i = 1,l = 0,r = 0;i <= n;i++) {
		if(i <= r) L[i] = min(Z[i - l + 1],r - i + 1);
		while(s[1 + L[i]] == t[i + L[i]]) ++L[i];
		if(i + L[i] - 1 > r) l = i,r = i + L[i] - 1;
	}
	for(int i = 1;i <= n;i++) del[i + L[i]].push_back(i);
	nxt[1] = 0;
	for(int i = 2,j = 0;i <= n;i++) {
		while(j && s[i] != s[j + 1]) j = nxt[j];
		if(s[i] == s[j + 1]) ++j;
		nxt[i] = j;
	}
	for(int i = 1;i <= n;i++) sum[i] = sum[nxt[i]] + w[i];
	for(int r = 1;r <= n;r++) {
		Is.insert(r);
		for(auto i : del[r]) Is.erase(i),C.upd(i,w[L[i]]);
		for(auto i : Qs[r]) {
			auto it = Is.lower_bound(ql[i]);
			if(it != Is.end())
				ans[i] += sum[r - (*it) + 1];
			ans[i] += C.Sum(r) - C.Sum(ql[i] - 1);
		}
	}
	for(int i = 1;i <= Q;i++) cout << ans[i] << endl;
	return 0;
}	


详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 20196kb

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: 3ms
memory: 20000kb

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: 99ms
memory: 27512kb

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: 0
Accepted
time: 87ms
memory: 27992kb

input:

150000 150000
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

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

result:

ok 150000 lines

Test #5:

score: 0
Accepted
time: 103ms
memory: 28260kb

input:

150000 150000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

386150762496368
2769669390423140
1025785181073675
1707930121656247
332135612349048
113937878332307
1128519694119799
476402941643931
980441978140407
1004994648999517
676169371268202
2607965889355671
273766796671958
711480908011402
71754482763611
400453994282744
975387094872830
810536618300388
2229061...

result:

ok 150000 lines

Test #6:

score: 0
Accepted
time: 115ms
memory: 28064kb

input:

150000 150000
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

25254725752128652
23497896664383313
15195391464047263
41143572895791434
7513384536045842
8871310939247699
17423823866879881
14601201534396958
6203483865940624
24953281161800570
24776576029495768
1687640411226
31563282955464371
29947970968962218
1149303801639767
5806503923049299
11201332188941891
116...

result:

ok 150000 lines

Test #7:

score: 0
Accepted
time: 97ms
memory: 30640kb

input:

150000 150000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

4570597927951323
11761063519994765
289982253793476
15684854914181269
19579321543184889
459972639580770
15246459216963247
1833393949769247
22425556248999709
11209560100586843
2883954996867615
14371655418173335
29207399108721
5943079608253242
1664456073054861
27405606916506455
23082758946788297
381175...

result:

ok 150000 lines

Test #8:

score: -100
Wrong Answer
time: 123ms
memory: 32316kb

input:

150000 150000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

5791790094145291
21917013030988777
11237472002329727
84315407720465773
32198634509153899
40728716039967676
5913555967331675
10487781019914529
270012821917938205
239347797488036653
216168445985667902
67452321725546144
457298584810665039
187789940805492303
46241700003064393
242312618101113
42260337439...

result:

wrong answer 1st lines differ - expected: '5697498028074951', found: '5791790094145291'