#include<bits/stdc++.h>
using namespace std;
int n,cntq;
string s;
bool verif(int le, int ri)
{
for(int i=0;i<=ri-le;i++)
if(s[le+i]!=s[ri-i])
return 0;
return 1;
}
int p[100005];
bool query(int le, int ri)
{
if(le<1 || ri>n || le>ri)
return 0;
if(le==ri)
return 1;
cntq++;
return verif(le,ri);
if(cntq>200000)
{
while(1);
}
int aux;
cout<<"? "<<le<<" "<<ri<<endl;
cin>>aux;
return aux;
}
signed main()
{
cin>>n;
s.resize(n+2);
for(int i=1;i<=n;i++)
{
int c = rand()%26;
s[i] = c+'a';
}
int le=1,ri=1,mxm=1;
for(int i=1;i<=n;i++)
{
p[i] = max(max(0,mxm/2-5), min(ri-i, p[le + (ri-i)]));
while(query(i-p[i],i+p[i]))
p[i]++;
if(i+p[i] > ri)
{
le = i-p[i];
ri = i+p[i];
}
mxm = max(mxm, 2*p[i]-1);
}
le=1;
ri=1;
for(int i=1;i<n;i++)
{
p[i] = max(max(0,mxm/2-5), min(ri-i-1, p[le+(ri-i)-1]));
while(query(i-p[i],i+1+p[i]))
p[i]++;
if(i+1+p[i] > ri)
{
le = i-p[i];
ri = i+1+p[i];
}
mxm = max(mxm, 2*p[i]);
}
cout<<"! "<<mxm<<endl;
cout<<cntq<<" queries\n";
return 0;
}
/**
neven
1 2 3 4 5 6 7 8 9
l r
a b c b a
1 2 3 4 5 6 7 8 9
l r
a b c c b a
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
L = 7, expected 30 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
L = 7, expected 30 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
856 KB |
L = 7, expected 52 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
L = 7, expected 30 |
2 |
Halted |
0 ms |
0 KB |
- |