#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,ri,mxm=1;
le=ri=1;
for(int i=1;i<n;i++)
{
p[i] = max(max(0,mxm/2), 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]);
}
le=ri=1;
for(int i=1;i<=n;i++)
{
p[i] = max(max(0,(mxm+1)/2), 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);
}
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 |
Correct |
102 ms |
596 KB |
Output is correct |
2 |
Correct |
90 ms |
592 KB |
Output is correct |
3 |
Correct |
72 ms |
848 KB |
Output is correct |
4 |
Correct |
84 ms |
592 KB |
Output is correct |
5 |
Correct |
98 ms |
448 KB |
Output is correct |
6 |
Correct |
89 ms |
848 KB |
Output is correct |
7 |
Correct |
34 ms |
436 KB |
Output is correct |
8 |
Correct |
76 ms |
700 KB |
Output is correct |
9 |
Correct |
78 ms |
444 KB |
Output is correct |
10 |
Correct |
83 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
596 KB |
Output is correct |
2 |
Correct |
90 ms |
592 KB |
Output is correct |
3 |
Correct |
72 ms |
848 KB |
Output is correct |
4 |
Correct |
84 ms |
592 KB |
Output is correct |
5 |
Correct |
98 ms |
448 KB |
Output is correct |
6 |
Correct |
89 ms |
848 KB |
Output is correct |
7 |
Correct |
34 ms |
436 KB |
Output is correct |
8 |
Correct |
76 ms |
700 KB |
Output is correct |
9 |
Correct |
78 ms |
444 KB |
Output is correct |
10 |
Correct |
83 ms |
436 KB |
Output is correct |
11 |
Correct |
688 ms |
900 KB |
Output is correct |
12 |
Correct |
683 ms |
1380 KB |
Output is correct |
13 |
Correct |
850 ms |
1136 KB |
Output is correct |
14 |
Correct |
732 ms |
1236 KB |
Output is correct |
15 |
Correct |
725 ms |
988 KB |
Output is correct |
16 |
Correct |
393 ms |
968 KB |
Output is correct |
17 |
Correct |
439 ms |
1232 KB |
Output is correct |
18 |
Correct |
784 ms |
1276 KB |
Output is correct |
19 |
Correct |
392 ms |
1016 KB |
Output is correct |
20 |
Correct |
826 ms |
836 KB |
Output is correct |
21 |
Correct |
789 ms |
1216 KB |
Output is correct |
22 |
Correct |
721 ms |
832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1270 ms |
1412 KB |
Output is correct |
2 |
Correct |
908 ms |
1380 KB |
Output is correct |
3 |
Correct |
1252 ms |
1164 KB |
Output is correct |
4 |
Correct |
795 ms |
1288 KB |
Output is correct |
5 |
Correct |
592 ms |
1244 KB |
Output is correct |
6 |
Correct |
1224 ms |
1724 KB |
Output is correct |
7 |
Correct |
613 ms |
1096 KB |
Output is correct |
8 |
Correct |
1262 ms |
1448 KB |
Output is correct |
9 |
Correct |
1263 ms |
1652 KB |
Output is correct |
10 |
Correct |
1194 ms |
1224 KB |
Output is correct |
11 |
Correct |
541 ms |
1032 KB |
Output is correct |
12 |
Correct |
576 ms |
1044 KB |
Output is correct |
13 |
Correct |
1213 ms |
1112 KB |
Output is correct |
14 |
Correct |
1080 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
596 KB |
Output is correct |
2 |
Correct |
90 ms |
592 KB |
Output is correct |
3 |
Correct |
72 ms |
848 KB |
Output is correct |
4 |
Correct |
84 ms |
592 KB |
Output is correct |
5 |
Correct |
98 ms |
448 KB |
Output is correct |
6 |
Correct |
89 ms |
848 KB |
Output is correct |
7 |
Correct |
34 ms |
436 KB |
Output is correct |
8 |
Correct |
76 ms |
700 KB |
Output is correct |
9 |
Correct |
78 ms |
444 KB |
Output is correct |
10 |
Correct |
83 ms |
436 KB |
Output is correct |
11 |
Correct |
688 ms |
900 KB |
Output is correct |
12 |
Correct |
683 ms |
1380 KB |
Output is correct |
13 |
Correct |
850 ms |
1136 KB |
Output is correct |
14 |
Correct |
732 ms |
1236 KB |
Output is correct |
15 |
Correct |
725 ms |
988 KB |
Output is correct |
16 |
Correct |
393 ms |
968 KB |
Output is correct |
17 |
Correct |
439 ms |
1232 KB |
Output is correct |
18 |
Correct |
784 ms |
1276 KB |
Output is correct |
19 |
Correct |
392 ms |
1016 KB |
Output is correct |
20 |
Correct |
826 ms |
836 KB |
Output is correct |
21 |
Correct |
789 ms |
1216 KB |
Output is correct |
22 |
Correct |
721 ms |
832 KB |
Output is correct |
23 |
Correct |
1270 ms |
1412 KB |
Output is correct |
24 |
Correct |
908 ms |
1380 KB |
Output is correct |
25 |
Correct |
1252 ms |
1164 KB |
Output is correct |
26 |
Correct |
795 ms |
1288 KB |
Output is correct |
27 |
Correct |
592 ms |
1244 KB |
Output is correct |
28 |
Correct |
1224 ms |
1724 KB |
Output is correct |
29 |
Correct |
613 ms |
1096 KB |
Output is correct |
30 |
Correct |
1262 ms |
1448 KB |
Output is correct |
31 |
Correct |
1263 ms |
1652 KB |
Output is correct |
32 |
Correct |
1194 ms |
1224 KB |
Output is correct |
33 |
Correct |
541 ms |
1032 KB |
Output is correct |
34 |
Correct |
576 ms |
1044 KB |
Output is correct |
35 |
Correct |
1213 ms |
1112 KB |
Output is correct |
36 |
Correct |
1080 ms |
1236 KB |
Output is correct |
37 |
Correct |
1191 ms |
1364 KB |
Output is correct |
38 |
Correct |
1130 ms |
1884 KB |
Output is correct |
39 |
Correct |
1258 ms |
1292 KB |
Output is correct |
40 |
Correct |
1092 ms |
1108 KB |
Output is correct |
41 |
Correct |
1056 ms |
1360 KB |
Output is correct |
42 |
Correct |
772 ms |
900 KB |
Output is correct |
43 |
Correct |
583 ms |
804 KB |
Output is correct |
44 |
Correct |
1079 ms |
1108 KB |
Output is correct |
45 |
Correct |
542 ms |
1040 KB |
Output is correct |
46 |
Correct |
1209 ms |
1500 KB |
Output is correct |
47 |
Correct |
1130 ms |
1268 KB |
Output is correct |
48 |
Correct |
1123 ms |
1296 KB |
Output is correct |
49 |
Correct |
622 ms |
972 KB |
Output is correct |
50 |
Correct |
1161 ms |
1256 KB |
Output is correct |
51 |
Correct |
1142 ms |
1148 KB |
Output is correct |
52 |
Correct |
1171 ms |
1208 KB |
Output is correct |