QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#845005#1942. Another Substring Query ProblemSymbolizeWA 1454ms994788kbC++201.5kb2025-01-06 13:51:342025-01-06 13:51:35

Judging History

This is the latest submission verdict.

  • [2025-01-06 13:51:35]
  • Judged
  • Verdict: WA
  • Time: 1454ms
  • Memory: 994788kb
  • [2025-01-06 13:51:34]
  • Submitted

answer

/*
	Luogu name: Symbolize
	Luogu uid: 672793
*/
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define rep1(i,l,r) for(register int i=l;i<=r;++i)
#define rep2(i,l,r) for(register int i=l;i>=r;--i)
#define rep3(i,x,y,z) for(register int i=x[y];~i;i=z[i])
#define rep4(i,x) for(auto i:x)
#define debug() puts("----------")
const int N=2e5+10;
const int inf=0x3f3f3f3f3f3f3f3f;
const int base=12347;
const int mod=1e9+7;
using namespace std;
int n,q,prod[N],h[N];
map<int,bool> vis;
map<pii,vector<int> > mp;
string s;
int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return f*x;
}
int get(int i,int j){return (h[j]-h[i-1]*prod[j-i+1]%mod+mod)%mod;}
signed main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s;
	s=" "+s;
	n=s.length()-1;
	prod[0]=1;
	rep1(i,1,n) prod[i]=prod[i-1]*base%mod;
	rep1(i,1,n) h[i]=(h[i-1]*base%mod+s[i])%mod;
	q=read();
	while(q--)
	{
		string t;
		cin>>t;
		t=" "+t;
		int len=t.length()-1;
		int now=0;
		rep1(i,1,len) now=(now*base%mod+t[i])%mod;
		int k=read();
		if(!vis[len])
		{
			rep1(i,1,n-len+1)
			{
				int j=i+len-1;
				if(get(i,j)==now) mp[make_pair(now,len)].push_back(i);
			}
			vis[len]=1;
		}
		if(mp[make_pair(now,len)].size()>=k) cout<<mp[make_pair(now,len)][k-1]<<"\n";
		else puts("-1");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1454ms
memory: 994788kb

input:

hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh...

output:

50997
112451
97534
13355
150562
5772
146250
10904
4343
194777
71395
96501
6809
18571
166901
114789
123587
176339
29660
82650
63509
80101
47907
66143
199971
108032
140518
49221
46212
28127
61461
149025
142818
33646
17132
196161
36671
28656
16860
141951
139429
72866
162807
21343
194803
16263
118701
20...

result:

ok 631 lines

Test #2:

score: -100
Wrong Answer
time: 27ms
memory: 10748kb

input:

gnzlzbsarybaxilacuopvdkhjfiynrgfdhsrecyxedcrriztcxboczhfaseqglcwshaewaepasxqpaxxbroxndbxqabrvtrrshrnnlyfodtxyltjkbghfkjcqrqsuwdsgypcaroaojqbfrjqbdrimglxcqtfmqaeogqunaegfpfzcmyjwfgbwaigwitcyspiedbisjuedeyseneuzjdteifzvdfzhenapmmreqpvwsmtrxowjnmmrthzhojgxsoppfgfgohoghuwvqclzsmeydusfndrdyqokpqwupixyoxr...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer 3rd lines differ - expected: '174057', found: '-1'