QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644311#7039. Counting Failures on a TriexzzduangAC ✓3727ms29740kbC++142.0kb2024-10-16 13:03:512024-10-16 13:03:51

Judging History

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

  • [2024-10-16 13:03:51]
  • 评测
  • 测评结果:AC
  • 用时:3727ms
  • 内存:29740kb
  • [2024-10-16 13:03:51]
  • 提交

answer

#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<map>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pii pair<int,int>
#define lowbit(x) ((x)&-(x))
#define popcount(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define umap unordered_map
#define all(x) x.begin(),x.end()
#define mk make_pair
#define pb push_back
#define ckmax(x,y) x=max(x,y)
#define ckmin(x,y) x=min(x,y)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define int long long
using namespace std;
inline int read(){
	int x=0,f=0; char ch=getchar();
	while(!isdigit(ch)) f|=(ch==45),ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return f?-x:x;
}
#define N 100005
const __int128 mo=1000000000000000003;
__int128 ha[N],bas=37,pre[N],b[N];
inline void red(__int128 &x){x>=mo?x-=mo:0;}
int n,m,q,f[N][17];
char s[N];
map<__int128,int> mp;
inline __int128 query(int l,int r){
	return (pre[r]-pre[l-1]*b[r-l+1]%mo+mo)%mo;
}
signed main(){
	for(int cas=read();cas--;){
		mp.clear();
		n=read(),m=read(),q=read();
		mp[0]=0;
		b[0]=1;
		for(int i=1;i<=max(n,m);++i) b[i]=b[i-1]*bas%mo;
		for(int i=1;i<=n;++i){
			int x=read();char c=getchar();
			red(ha[i]=ha[x]*bas%mo+c-'a'+1);
			mp[ha[i]]=i;
		}
		scanf("%s",s+1);
		for(int i=1;i<=m;++i){
			red(pre[i]=pre[i-1]*bas%mo+s[i]-'a'+1);
		}
		for(int i=1;i<=m;++i){
			int l=i,r=m;
			while(l<=r){
				int mid=l+r>>1;
				if(mp.count(query(i,mid))) l=mid+1;
				else r=mid-1;
			}
			f[i][0]=min(m+1,r+2);
		}
		for(int j=0;j<17;++j) f[m+1][j]=m+1;
		for(int j=1;j<17;++j){
			for(int i=1;i<=m;++i){
				f[i][j]=f[f[i][j-1]][j-1];
			}
		}
		for(int i=1;i<=q;++i){
			int L=read(),R=read();
			int cnt=0,dst;
			for(int j=16;~j;--j){
				if(f[L][j]<=R) L=f[L][j],cnt|=(1<<j);
			}
			if(mp.count(query(L,R))) dst=mp[query(L,R)];
			else dst=0,cnt++;
			printf("%lld %lld\n",cnt,dst);
		}
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
5 10 5
0 a
0 b
1 a
1 c
2 a
aaacbaacab
1 5
1 6
1 7
3 9
4 10

output:

2 2
2 5
3 0
2 1
4 0

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 723ms
memory: 6328kb

input:

1000
1000 1000 1000
0 a
1 a
2 b
3 a
4 b
5 a
6 b
7 b
8 a
9 b
10 b
11 b
12 b
13 b
14 b
15 a
16 a
17 b
18 a
19 a
20 b
21 a
22 b
23 a
24 b
25 a
26 b
27 b
28 b
29 b
30 a
31 b
32 a
33 a
34 a
35 b
36 b
37 b
38 a
39 a
40 b
41 a
42 b
43 a
44 b
45 b
46 a
47 a
48 a
49 a
50 b
51 b
52 a
53 b
54 b
55 a
56 a
57 b
...

output:

59 546
43 328
141 219
5 449
132 391
42 0
147 271
58 0
38 328
123 154
99 3
46 227
23 3
38 2
146 491
15 5
141 6
8 154
9 175
150 272
163 175
119 393
172 391
63 2
165 4
36 503
78 744
16 602
61 999
81 219
116 1
96 0
158 602
53 999
176 0
82 449
108 0
87 744
33 1
74 0
2 5
13 154
60 328
136 709
68 3
56 491
...

result:

ok 1000000 lines

Test #3:

score: 0
Accepted
time: 3727ms
memory: 29688kb

input:

10
100000 100000 100000
0 a
1 b
2 b
3 b
4 b
5 b
6 b
7 b
8 b
9 a
10 b
11 a
12 a
13 a
14 b
15 b
16 b
17 b
18 a
19 a
20 b
21 a
22 b
23 a
24 b
25 a
26 b
27 a
28 b
29 a
30 a
31 b
32 b
33 a
34 a
35 a
36 a
37 a
38 b
39 b
40 b
41 b
42 b
43 b
44 a
45 a
46 a
47 a
48 a
49 b
50 b
51 b
52 a
53 a
54 b
55 a
56 b
5...

output:

307 77
696 39
292 33
1101 72778
797 7
923 59
530 22
175 7
751 2
641 23
999 54
771 60
1031 19
736 10
1828 25
1223 49
1119 8
1360 1
1010 25
186 10
634 11
1898 60
515 138
67 44
698 25
678 104
585 7
1179 34332
643 6
551 31
758 8
474 13
763 25
1042 85
1385 21
248 56
712 7
161 12
650 1
883 276
155 21
110 ...

result:

ok 1000000 lines

Test #4:

score: 0
Accepted
time: 3579ms
memory: 29740kb

input:

10
100000 100000 100000
0 a
1 b
2 a
3 b
4 b
5 a
6 b
7 a
8 b
9 b
10 a
11 b
12 a
13 b
14 b
15 a
16 b
17 a
18 b
19 b
20 a
21 b
22 a
23 b
24 b
25 a
26 b
27 a
28 b
29 b
30 a
31 b
32 a
33 b
34 b
35 a
36 b
37 a
38 b
39 b
40 a
41 b
42 a
43 b
44 b
45 a
46 b
47 a
48 b
49 b
50 a
51 b
52 a
53 b
54 b
55 a
56 b
5...

output:

1 5257
2 30770
1 27739
1 51805
2 6968
2 78118
1 7789
1 45259
2 35890
2 40254
2 908
1 10889
0 71302
2 10214
1 37077
2 18525
1 54529
1 25673
0 20925
1 35947
2 27976
2 28747
1 38487
1 15732
1 11502
2 33825
0 2153
2 64539
0 30535
1 70629
2 32885
0 58060
2 925
2 62115
1 10023
2 66651
1 21139
2 66936
0 28...

result:

ok 1000000 lines