QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#829534 | #8939. Permutation | OIer2008 | WA | 161ms | 3688kb | C++14 | 2.4kb | 2024-12-24 10:45:01 | 2024-12-24 10:45:04 |
Judging History
answer
#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;++i)
#define fu(i,l,r) for(int i=l;i<r;++i)
#define fd(i,r,l) for(int i=r;i>=l;--i)
#define ll long long
#define I inline int
#define V inline void
#define B inline bool
#define L inline ll
#define pi pair<int,int>
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vii vector<pi>
#define popc __builtin_popcount
using namespace std;
const int N=1e6+10,mod=998244353;
char St;
I read() {
int x=0,y=1;char c=getchar();
while(c<48||c>57) {if(c==45)y=-y;c=getchar();}
while(c>=48&&c<=57) x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*y;
}
L ksm(ll x,int y) {ll t(1);for(;y;y>>=1,x=x*x%mod)if(y&1)t=t*x%mod;return t;}
int s1(0),s2(0);
I ask(int l,int r) {
if(l==r) return 0;
cout<<"? "<<l<<" "<<r<<endl;
s1++;s2+=r-l+1;
int x;
cin>>x;return x;
}
I solve(int l,int r) {
// if(l>r) {
// cerr<<"WA"<<endl;
// exit(0);
// }
// cerr<<l<<" "<<r<<endl;
if(l==r) return l;
int mid=l+r>>1,se=ask(l,r);
if(se<=mid) {
if(l==mid) return solve(mid+1,r);
int se2=ask(l,mid);
if(se==se2) {//[l,mid]
r=mid;
mid=l+r>>1;
if(l==r) return l;
int se3;
if(se2<=mid) {
se3=ask(l,mid);
if(se3==se2) return solve(l,mid);
else return solve(mid+1,r);
}
else {
se3=ask(mid+1,r);
if(se3==se2) return solve(mid+1,r);
else return solve(l,mid);
}
}
else {
l=mid+1;mid=l+r>>1;
if(l==r) return l;
int se3=ask(se,mid);
if(se3==se) return solve(l,mid);
else return solve(mid+1,r);
}
}
else {
if(mid+1==r) return solve(l,mid);
int se2=ask(mid+1,r);
if(se==se2) {
l=mid+1;
mid=l+r>>1;
if(l==r) return l;
int se3;
if(se2<=mid) {
se3=ask(l,mid);
if(se3==se2) return solve(l,mid);
else return solve(mid+1,r);
}
else {
se3=ask(mid+1,r);
if(se3==se2) return solve(mid+1,r);
else return solve(l,mid);
}
}
else {
r=mid;mid=l+r>>1;
if(l==r) return l;
int se3=ask(mid+1,se);
if(se3==se) return solve(mid+1,r);
else return solve(l,mid);
}
}
}
int n;
V solve() {
s1=s2=0;
cin>>n;
int t=solve(1,n);
cout<<"! "<<t<<endl;
}
char Ed;
int main() {
// cerr<<"memory:"<<(&St-&Ed)/1024.0<<endl;
int T;cin>>T;
while(T--) solve();
// cerr<<"time:"<<clock()<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3688kb
input:
3 5 3 2 3 6 6 5 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 3 4 ! 4 ? 1 6 ? 4 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 95ms
memory: 3684kb
input:
10000 10 2 2 3 5 10 10 10 9 7 7 10 5 1 5 6 6 10 4 4 5 2 1 10 10 6 6 3 2 10 3 3 3 3 2 10 1 5 1 6 7 10 1 3 1 8 6 10 2 4 4 9 10 3 3 1 5 10 4 1 7 9 10 8 7 7 1 2 10 4 1 5 9 10 7 8 7 4 10 5 1 7 10 10 8 8 6 9 10 2 1 2 7 7 10 6 6 8 10 10 1 3 1 8 6 10 7 9 5 1 2 10 7 8 4 1 2 10 3 4 4 10 10 4 4 4 4 10 8 7 7 2 ...
output:
? 1 10 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 6 10 ? 9 10 ? 6 8 ? 6 7 ! 6 ? 1 10 ? 1 5 ? 5 8 ? 6 8 ? 6 7 ! 7 ? 1 10 ? 1 5 ? 4 5 ? 1 3 ? 1 2 ! 3 ? 1 10 ? 6 10 ? 4 10 ? 1 3 ? 1 2 ! 1 ? 1 10 ? 1 5 ? 1 3 ? 1 3 ? 1 2 ! 1 ? 1 10 ? 1 5 ? 1 8 ? 6 8 ? 6 7 ! 8 ? 1 10 ? 1 5 ? 1 8 ? 6 8 ? 6 7 ! 7 ? 1 10 ? 1 5 ? 2 8 ? 9...
result:
ok Correct (10000 test cases)
Test #3:
score: 0
Accepted
time: 76ms
memory: 3624kb
input:
10000 3 1 2 11 5 5 5 5 4 2 2 19 3 3 4 6 8 8 7 5 7 5 4 3 3 1 19 6 6 10 1 1 2 2 2 15 11 11 11 11 12 10 14 1 1 1 1 2 3 16 4 4 1 8 7 8 3 3 2 19 13 17 6 5 4 5 2 2 4 1 2 3 7 2 2 2 2 3 2 2 17 1 1 1 1 2 2 14 9 9 9 9 8 9 20 9 3 9 13 13 11 6 4 4 5 18 7 7 7 7 6 7 8 8 6 8 3 8 6 7 6 3 16 10 10 10 10 10 6 1 3 1 5...
output:
? 1 3 ? 1 2 ! 3 ? 1 11 ? 1 6 ? 4 6 ? 4 6 ? 4 5 ! 6 ? 1 2 ! 1 ? 1 19 ? 1 10 ? 1 5 ? 6 10 ? 6 8 ? 6 9 ! 10 ? 1 7 ? 5 7 ? 3 5 ? 3 4 ! 3 ? 1 3 ? 1 2 ! 2 ? 1 19 ? 1 10 ? 6 10 ? 1 5 ? 1 3 ? 1 2 ! 3 ? 1 2 ! 1 ? 1 15 ? 9 15 ? 9 12 ? 9 12 ? 11 12 ? 10 11 ! 9 ? 1 14 ? 1 7 ? 1 4 ? 1 4 ? 1 2 ? 1 3 ! 4 ? 1 16 ? ...
result:
ok Correct (10000 test cases)
Test #4:
score: 0
Accepted
time: 100ms
memory: 3640kb
input:
10000 47 23 23 24 11 9 11 5 5 14 8 8 8 8 9 8 25 6 13 6 18 17 17 15 7 4 2 4 6 9 2 2 2 2 2 27 27 27 27 27 26 24 23 21 7 7 10 5 5 5 5 43 41 37 21 7 8 5 3 1 22 6 4 14 20 19 21 34 29 25 29 17 17 16 14 42 20 20 20 20 20 21 17 17 47 21 21 21 21 19 21 16 17 41 25 25 30 33 34 33 39 38 19 17 17 16 12 12 12 12...
output:
? 1 47 ? 1 24 ? 13 24 ? 1 12 ? 7 12 ? 4 11 ? 4 6 ? 4 5 ! 4 ? 1 14 ? 8 14 ? 8 11 ? 8 11 ? 8 9 ? 8 10 ! 10 ? 1 25 ? 1 13 ? 6 19 ? 14 19 ? 17 19 ? 16 18 ? 14 15 ! 14 ? 1 7 ? 1 4 ? 4 6 ? 5 6 ! 5 ? 1 9 ? 1 5 ? 1 3 ? 1 3 ? 1 2 ! 1 ? 1 27 ? 15 27 ? 22 27 ? 22 27 ? 25 27 ? 24 27 ? 22 23 ! 22 ? 1 21 ? 1 11 ?...
result:
ok Correct (10000 test cases)
Test #5:
score: 0
Accepted
time: 122ms
memory: 3628kb
input:
10000 100 47 5 47 61 53 68 71 71 71 71 9 2 2 2 2 1 53 46 35 15 6 6 6 6 6 33 3 16 16 31 31 30 32 82 60 42 60 29 29 28 23 24 23 88 39 8 39 59 59 59 59 61 59 71 24 29 29 59 59 56 60 61 60 92 52 52 56 88 88 88 88 88 89 24 11 11 9 5 5 5 5 66 51 51 66 45 43 45 39 40 39 92 43 43 38 20 20 21 17 17 16 48 1 1...
output:
? 1 100 ? 1 50 ? 47 75 ? 51 75 ? 51 63 ? 61 69 ? 70 75 ? 70 72 ? 70 71 ? 70 71 ! 70 ? 1 9 ? 1 5 ? 1 3 ? 1 3 ? 1 2 ! 3 ? 1 53 ? 28 53 ? 15 46 ? 1 14 ? 1 7 ? 5 7 ? 5 7 ? 5 6 ! 5 ? 1 33 ? 1 17 ? 3 25 ? 26 33 ? 30 33 ? 30 31 ? 32 33 ! 33 ? 1 82 ? 42 82 ? 22 60 ? 22 41 ? 22 31 ? 27 31 ? 22 26 ? 22 24 ? 2...
result:
ok Correct (10000 test cases)
Test #6:
score: 0
Accepted
time: 161ms
memory: 3660kb
input:
10000 50 10 10 10 10 11 6 2 1 3 50 11 11 9 18 16 22 23 23 50 44 40 44 20 20 21 25 23 50 24 14 29 45 45 45 45 46 50 50 50 50 50 50 49 47 45 50 36 39 23 12 12 11 8 8 50 29 36 20 13 12 6 3 3 50 30 42 22 1 1 1 1 2 1 50 25 15 25 30 30 31 29 29 50 18 20 18 30 27 34 37 36 50 9 9 9 9 9 8 13 11 50 26 43 26 1...
output:
? 1 50 ? 1 25 ? 1 13 ? 1 13 ? 8 13 ? 5 10 ? 1 4 ? 1 2 ? 2 3 ! 4 ? 1 50 ? 1 25 ? 1 13 ? 14 25 ? 14 19 ? 18 22 ? 23 25 ? 23 24 ! 24 ? 1 50 ? 26 50 ? 14 44 ? 14 25 ? 20 25 ? 20 22 ? 23 25 ? 23 24 ! 24 ? 1 50 ? 1 25 ? 24 38 ? 39 50 ? 45 50 ? 45 47 ? 45 47 ? 45 46 ! 47 ? 1 50 ? 26 50 ? 39 50 ? 39 50 ? 45...
result:
ok Correct (10000 test cases)
Test #7:
score: 0
Accepted
time: 142ms
memory: 3612kb
input:
10000 100 76 78 35 5 5 3 9 9 8 100 29 29 50 20 20 20 20 22 22 100 64 64 69 88 88 86 78 76 80 100 51 51 57 98 92 92 79 77 81 100 44 44 50 13 13 13 13 12 12 9 100 64 92 64 41 44 41 33 35 35 100 93 56 93 40 40 44 49 50 47 45 100 37 2 37 57 54 57 68 68 67 100 76 76 76 76 76 80 86 88 85 83 100 32 32 32 3...
output:
? 1 100 ? 51 100 ? 26 76 ? 1 25 ? 1 13 ? 1 7 ? 8 13 ? 8 10 ? 8 9 ! 10 ? 1 100 ? 1 50 ? 26 50 ? 1 25 ? 14 25 ? 20 25 ? 20 25 ? 20 22 ? 20 24 ! 25 ? 1 100 ? 51 100 ? 51 75 ? 76 100 ? 76 88 ? 83 88 ? 76 82 ? 76 79 ? 78 81 ! 82 ? 1 100 ? 51 100 ? 51 75 ? 76 100 ? 89 100 ? 83 98 ? 76 82 ? 76 79 ? 79 81 !...
result:
ok Correct (10000 test cases)
Test #8:
score: 0
Accepted
time: 11ms
memory: 3680kb
input:
1000 1000 475 426 728 896 974 896 867 867 869 858 860 851 847 848 847 1000 278 17 278 598 534 598 679 665 679 652 655 647 645 645 1000 75 128 75 607 604 644 713 695 732 749 745 749 742 743 741 1000 239 239 45 432 432 429 442 442 451 458 459 458 463 463 1000 978 978 978 978 978 997 914 914 920 932 93...
output:
? 1 1000 ? 1 500 ? 475 750 ? 751 1000 ? 876 1000 ? 814 896 ? 814 875 ? 845 875 ? 861 875 ? 845 860 ? 853 860 ? 849 858 ? 845 848 ? 847 848 ? 846 847 ! 846 ? 1 1000 ? 1 500 ? 278 750 ? 501 750 ? 501 625 ? 598 688 ? 626 688 ? 658 688 ? 642 679 ? 642 657 ? 650 657 ? 646 652 ? 642 645 ? 644 645 ! 644 ? ...
result:
ok Correct (1000 test cases)
Test #9:
score: 0
Accepted
time: 30ms
memory: 3628kb
input:
1017 272 246 186 246 111 110 110 73 73 71 77 76 75 114 105 91 91 2 2 2 2 2 2 2 910 173 173 173 173 127 127 14 29 29 56 51 56 48 48 726 229 229 201 118 149 63 28 28 28 28 28 29 24 24 861 315 104 315 491 528 593 632 641 614 602 605 599 597 596 597 1984 133 133 406 571 571 512 724 704 704 650 650 650 6...
output:
? 1 272 ? 137 272 ? 69 246 ? 69 136 ? 103 136 ? 86 111 ? 69 85 ? 69 77 ? 69 73 ? 74 77 ? 76 77 ? 75 77 ! 74 ? 1 114 ? 58 114 ? 30 105 ? 1 29 ? 1 15 ? 1 8 ? 1 8 ? 1 4 ? 1 2 ? 1 2 ! 1 ? 1 910 ? 1 455 ? 1 228 ? 1 228 ? 115 228 ? 58 173 ? 1 57 ? 1 29 ? 14 43 ? 44 57 ? 51 57 ? 48 56 ? 48 50 ? 48 49 ! 49 ...
result:
ok Correct (1017 test cases)
Test #10:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
10 100000 3893 3893 3505 30673 33920 30673 43582 43582 43582 43582 43582 43470 43242 43242 43197 43289 43289 43298 43268 43268 43267 43273 43273 43272 100000 32066 19090 54928 88585 88585 88585 88585 89959 88585 91599 91474 91599 91257 91257 91225 91398 91383 91398 91339 91337 91339 91348 91349 9134...
output:
? 1 100000 ? 1 50000 ? 1 25000 ? 25001 50000 ? 25001 37500 ? 30673 43750 ? 37501 43750 ? 40626 43750 ? 42189 43750 ? 42189 43750 ? 42970 43750 ? 43361 43750 ? 42970 43360 ? 43166 43360 ? 43166 43263 ? 43264 43360 ? 43264 43312 ? 43289 43312 ? 43264 43288 ? 43264 43276 ? 43264 43270 ? 43271 43276 ? 4...
result:
ok Correct (10 test cases)
Test #11:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
21 84335 47947 60969 22445 9296 1509 11772 20931 19830 20931 17510 17510 17606 17352 17352 17352 17352 17346 17352 17338 17337 17328 17320 17318 17320 17321 159962 128177 145530 128177 54814 54814 59035 49869 48003 49869 43214 43214 43214 43214 43231 43550 43675 43675 43675 43675 43670 43675 43689 4...
output:
? 1 84335 ? 42169 84335 ? 21085 47947 ? 1 21084 ? 1 10542 ? 9296 15813 ? 15814 21084 ? 18450 21084 ? 17132 20931 ? 17132 18449 ? 17132 17790 ? 17462 17790 ? 17132 17461 ? 17297 17461 ? 17297 17379 ? 17297 17379 ? 17339 17379 ? 17318 17352 ? 17318 17338 ? 17329 17338 ? 17324 17338 ? 17318 17323 ? 173...
result:
ok Correct (21 test cases)
Test #12:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
1 1000000 641602 641602 561698 783270 783270 783270 783270 783270 783270 783270 786055 786055 794273 794682 794682 796734 796734 796734 796734 796686 796788 796850 796850 796851 796864 796864 796864 796864 796863 796864
output:
? 1 1000000 ? 500001 1000000 ? 500001 750000 ? 750001 1000000 ? 750001 875000 ? 750001 812500 ? 750001 812500 ? 781251 812500 ? 781251 796875 ? 781251 796875 ? 781251 789063 ? 783270 792969 ? 792970 796875 ? 792970 794922 ? 794273 795899 ? 795900 796875 ? 796388 796875 ? 796632 796875 ? 796632 79687...
result:
ok Correct (1 test case)
Test #13:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
16 232936 229707 229707 229707 229707 229707 229707 229707 231039 229707 223556 223533 224031 225261 225261 225261 225261 225290 225290 225375 225395 225407 225417 225419 225417 225425 225425 8676 6498 6498 6498 6498 5867 4978 4731 4731 4731 4731 4731 4717 4684 4684 4681 4692 4692 4693 4695 221085 1...
output:
? 1 232936 ? 116469 232936 ? 174703 232936 ? 174703 232936 ? 203820 232936 ? 218379 232936 ? 218379 232936 ? 225658 232936 ? 222019 229707 ? 222019 225657 ? 222019 223838 ? 223556 224748 ? 224749 225657 ? 225204 225657 ? 225204 225430 ? 225204 225430 ? 225204 225317 ? 225261 225374 ? 225375 225430 ?...
result:
ok Correct (16 test cases)
Test #14:
score: 0
Accepted
time: 51ms
memory: 3564kb
input:
1994 667 666 667 665 167 166 166 42 41 41 11 10 10 3 2 374 373 374 372 94 93 93 24 23 23 6 5 5 2 488 486 488 485 122 121 121 31 30 30 8 7 7 2 922 921 922 920 231 230 230 58 57 57 15 14 14 4 3 3 639 637 639 636 160 159 159 40 39 39 10 9 9 3 2 353 350 353 349 89 88 88 23 22 22 6 5 5 2 71 66 71 65 18 1...
output:
? 1 667 ? 335 667 ? 168 666 ? 1 167 ? 85 167 ? 43 167 ? 1 42 ? 22 42 ? 12 42 ? 1 11 ? 7 11 ? 4 11 ? 1 3 ? 1 2 ! 1 ? 1 374 ? 188 374 ? 95 373 ? 1 94 ? 48 94 ? 25 94 ? 1 24 ? 13 24 ? 7 24 ? 1 6 ? 4 6 ? 3 6 ? 1 2 ! 1 ? 1 488 ? 245 488 ? 123 486 ? 1 122 ? 62 122 ? 32 122 ? 1 31 ? 17 31 ? 9 31 ? 1 8 ? 5 ...
result:
ok Correct (1994 test cases)
Test #15:
score: -100
Wrong Answer
time: 1ms
memory: 3636kb
input:
18 153667 153667 153666 153666 38417 38416 38416 9605 9604 9604 2402 2401 2401 601 600 600 151 150 150 38 37 37 10 9 9 3
output:
? 1 153667 ? 76835 153667 ? 38418 153667 ? 1 38417 ? 19210 38417 ? 9606 38417 ? 1 9605 ? 4804 9605 ? 2403 9605 ? 1 2402 ? 1202 2402 ? 602 2402 ? 1 601 ? 302 601 ? 152 601 ? 1 151 ? 77 151 ? 39 151 ? 1 38 ? 20 38 ? 11 38 ? 1 10 ? 6 10 ? 4 10 ? 1 3 ? 1 2
result:
wrong answer Too long queries, n = 153667, now length 461003 (test case 1)