#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 mxm=1;
for(int i=1;i<n;i++)
{
p[i] = mxm/2;
while(query(i-p[i],i+1+p[i]))
p[i]++;
mxm = max(mxm, 2*p[i]);
}
for(int i=1;i<=n;i++)
{
p[i] = (mxm+1)/2;
while(query(i-p[i],i+p[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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
600 KB |
Output is correct |
2 |
Correct |
70 ms |
448 KB |
Output is correct |
3 |
Correct |
77 ms |
612 KB |
Output is correct |
4 |
Correct |
75 ms |
344 KB |
Output is correct |
5 |
Correct |
85 ms |
856 KB |
Output is correct |
6 |
Correct |
72 ms |
692 KB |
Output is correct |
7 |
Correct |
39 ms |
452 KB |
Output is correct |
8 |
Correct |
89 ms |
600 KB |
Output is correct |
9 |
Correct |
65 ms |
344 KB |
Output is correct |
10 |
Correct |
69 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
600 KB |
Output is correct |
2 |
Correct |
70 ms |
448 KB |
Output is correct |
3 |
Correct |
77 ms |
612 KB |
Output is correct |
4 |
Correct |
75 ms |
344 KB |
Output is correct |
5 |
Correct |
85 ms |
856 KB |
Output is correct |
6 |
Correct |
72 ms |
692 KB |
Output is correct |
7 |
Correct |
39 ms |
452 KB |
Output is correct |
8 |
Correct |
89 ms |
600 KB |
Output is correct |
9 |
Correct |
65 ms |
344 KB |
Output is correct |
10 |
Correct |
69 ms |
600 KB |
Output is correct |
11 |
Correct |
748 ms |
696 KB |
Output is correct |
12 |
Correct |
810 ms |
1232 KB |
Output is correct |
13 |
Correct |
822 ms |
972 KB |
Output is correct |
14 |
Correct |
685 ms |
1096 KB |
Output is correct |
15 |
Correct |
741 ms |
944 KB |
Output is correct |
16 |
Correct |
396 ms |
852 KB |
Output is correct |
17 |
Correct |
364 ms |
728 KB |
Output is correct |
18 |
Correct |
821 ms |
708 KB |
Output is correct |
19 |
Correct |
372 ms |
868 KB |
Output is correct |
20 |
Correct |
787 ms |
816 KB |
Output is correct |
21 |
Correct |
770 ms |
592 KB |
Output is correct |
22 |
Correct |
822 ms |
1204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1223 ms |
1016 KB |
Output is correct |
2 |
Correct |
868 ms |
1252 KB |
Output is correct |
3 |
Correct |
1141 ms |
1012 KB |
Output is correct |
4 |
Correct |
765 ms |
1404 KB |
Output is correct |
5 |
Correct |
584 ms |
1480 KB |
Output is correct |
6 |
Correct |
1181 ms |
1164 KB |
Output is correct |
7 |
Correct |
595 ms |
1228 KB |
Output is correct |
8 |
Correct |
1178 ms |
1552 KB |
Output is correct |
9 |
Correct |
1268 ms |
1244 KB |
Output is correct |
10 |
Correct |
1103 ms |
1104 KB |
Output is correct |
11 |
Correct |
575 ms |
1268 KB |
Output is correct |
12 |
Correct |
608 ms |
960 KB |
Output is correct |
13 |
Correct |
1192 ms |
1104 KB |
Output is correct |
14 |
Correct |
1272 ms |
1276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
600 KB |
Output is correct |
2 |
Correct |
70 ms |
448 KB |
Output is correct |
3 |
Correct |
77 ms |
612 KB |
Output is correct |
4 |
Correct |
75 ms |
344 KB |
Output is correct |
5 |
Correct |
85 ms |
856 KB |
Output is correct |
6 |
Correct |
72 ms |
692 KB |
Output is correct |
7 |
Correct |
39 ms |
452 KB |
Output is correct |
8 |
Correct |
89 ms |
600 KB |
Output is correct |
9 |
Correct |
65 ms |
344 KB |
Output is correct |
10 |
Correct |
69 ms |
600 KB |
Output is correct |
11 |
Correct |
748 ms |
696 KB |
Output is correct |
12 |
Correct |
810 ms |
1232 KB |
Output is correct |
13 |
Correct |
822 ms |
972 KB |
Output is correct |
14 |
Correct |
685 ms |
1096 KB |
Output is correct |
15 |
Correct |
741 ms |
944 KB |
Output is correct |
16 |
Correct |
396 ms |
852 KB |
Output is correct |
17 |
Correct |
364 ms |
728 KB |
Output is correct |
18 |
Correct |
821 ms |
708 KB |
Output is correct |
19 |
Correct |
372 ms |
868 KB |
Output is correct |
20 |
Correct |
787 ms |
816 KB |
Output is correct |
21 |
Correct |
770 ms |
592 KB |
Output is correct |
22 |
Correct |
822 ms |
1204 KB |
Output is correct |
23 |
Correct |
1223 ms |
1016 KB |
Output is correct |
24 |
Correct |
868 ms |
1252 KB |
Output is correct |
25 |
Correct |
1141 ms |
1012 KB |
Output is correct |
26 |
Correct |
765 ms |
1404 KB |
Output is correct |
27 |
Correct |
584 ms |
1480 KB |
Output is correct |
28 |
Correct |
1181 ms |
1164 KB |
Output is correct |
29 |
Correct |
595 ms |
1228 KB |
Output is correct |
30 |
Correct |
1178 ms |
1552 KB |
Output is correct |
31 |
Correct |
1268 ms |
1244 KB |
Output is correct |
32 |
Correct |
1103 ms |
1104 KB |
Output is correct |
33 |
Correct |
575 ms |
1268 KB |
Output is correct |
34 |
Correct |
608 ms |
960 KB |
Output is correct |
35 |
Correct |
1192 ms |
1104 KB |
Output is correct |
36 |
Correct |
1272 ms |
1276 KB |
Output is correct |
37 |
Correct |
1297 ms |
1300 KB |
Output is correct |
38 |
Correct |
1233 ms |
1336 KB |
Output is correct |
39 |
Correct |
1121 ms |
972 KB |
Output is correct |
40 |
Correct |
1092 ms |
1520 KB |
Output is correct |
41 |
Correct |
1180 ms |
992 KB |
Output is correct |
42 |
Correct |
786 ms |
1104 KB |
Output is correct |
43 |
Correct |
607 ms |
992 KB |
Output is correct |
44 |
Correct |
1209 ms |
1252 KB |
Output is correct |
45 |
Correct |
612 ms |
1244 KB |
Output is correct |
46 |
Correct |
1223 ms |
1520 KB |
Output is correct |
47 |
Correct |
1151 ms |
1372 KB |
Output is correct |
48 |
Correct |
1064 ms |
1176 KB |
Output is correct |
49 |
Correct |
577 ms |
1008 KB |
Output is correct |
50 |
Correct |
1221 ms |
1532 KB |
Output is correct |
51 |
Correct |
1293 ms |
1352 KB |
Output is correct |
52 |
Correct |
1277 ms |
1260 KB |
Output is correct |