QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370818 | #6394. Turn on the Light | ricofx# | AC ✓ | 2ms | 5892kb | C++17 | 1.3kb | 2024-03-29 16:51:33 | 2024-03-29 16:51:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int n, tr[N];
void add(int x) {
for (; x <= n; x += x & -x) tr[x] += 1;
}
int qry(int x) {
int res = 0;
for (; x; x -= x & -x) res += tr[x];
return res;
}
int qry(int l, int r) {
if (l > r) return 0;
return qry(r) - qry(l - 1);
}
int query(int x) {
cout << "? " << x << endl;
int res;
cin >> res;
return res;
}
int main() {
cin >> n;
int l = 1, r = n, ans = -1;
while (l <= r) {
int mid = (l + r) >> 1;
int res = query(mid);
int left = qry(1, l - 1), right = qry(r + 1, n);
add(mid);
if (res == abs(left - right)) return cout << "! " << mid << endl, 0;
if (left == right) {
if (l == mid) l = mid + 1;
else if (r == mid) r = mid - 1;
else {
int rr = query(l);
add(l);
if (rr == 1) return cout << "! " << l << endl, 0;
else if (rr == 0) l = l + 1, r = mid - 1;
else if (rr == 2) l = mid + 1;
}
} else {
if (abs(left + 1 - right) == res) l = mid + 1;
else if (abs(left - right - 1) == res) r = mid - 1;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3560kb
input:
3 1 2 2
output:
? 2 ? 1 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
10 1 2 3 3
output:
? 5 ? 1 ? 8 ? 9 ! 9
result:
ok Correct position at 9
Test #3:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
9 1 2 3 3
output:
? 5 ? 1 ? 7 ? 8 ! 8
result:
ok Correct position at 8
Test #4:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
8 1 2 3 3
output:
? 4 ? 1 ? 6 ? 7 ! 7
result:
ok Correct position at 7
Test #5:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
7 1 2 3 3
output:
? 4 ? 1 ? 6 ? 7 ! 7
result:
ok Correct position at 7
Test #6:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
6 1 2 3 3
output:
? 3 ? 1 ? 5 ? 6 ! 6
result:
ok Correct position at 6
Test #7:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
5 1 2 3 3
output:
? 3 ? 1 ? 4 ? 5 ! 5
result:
ok Correct position at 5
Test #8:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
4 1 2 3 3
output:
? 2 ? 1 ? 3 ? 4 ! 4
result:
ok Correct position at 4
Test #9:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3 1 1
output:
? 2 ? 1 ! 1
result:
ok Correct position at 1
Test #10:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
2 1 1
output:
? 1 ? 2 ! 2
result:
ok Correct position at 2
Test #11:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
1 0
output:
? 1 ! 1
result:
ok Correct position at 1
Test #12:
score: 0
Accepted
time: 0ms
memory: 5800kb
input:
1000000 1 2 3 4 5 6 7 6 7 8 7 8 9 10 11 12 13 14 15 16 16
output:
? 500000 ? 1 ? 750000 ? 875000 ? 937500 ? 968750 ? 984375 ? 992188 ? 988281 ? 990234 ? 991211 ? 990722 ? 990966 ? 991088 ? 991149 ? 991180 ? 991195 ? 991203 ? 991207 ? 991209 ? 991210 ! 991210
result:
ok Correct position at 991210
Test #13:
score: 0
Accepted
time: 1ms
memory: 5796kb
input:
999999 1 2 3 2 3 2 1 2 3 4 3 4 5 6 7 8 9 10 11 12 12
output:
? 500000 ? 1 ? 750000 ? 875000 ? 812500 ? 843750 ? 828125 ? 820312 ? 824218 ? 826171 ? 827148 ? 826659 ? 826903 ? 827025 ? 827086 ? 827117 ? 827132 ? 827140 ? 827144 ? 827146 ? 827147 ! 827147
result:
ok Correct position at 827147
Test #14:
score: 0
Accepted
time: 2ms
memory: 5832kb
input:
999998 1 2 3 2 3 2 1 2 3 4 3 4 5 6 7 8 9 10 11 12 12
output:
? 499999 ? 1 ? 749999 ? 874999 ? 812499 ? 843749 ? 828124 ? 820311 ? 824217 ? 826170 ? 827147 ? 826658 ? 826902 ? 827024 ? 827085 ? 827116 ? 827131 ? 827139 ? 827143 ? 827145 ? 827146 ! 827146
result:
ok Correct position at 827146
Test #15:
score: 0
Accepted
time: 1ms
memory: 3808kb
input:
999997 1 2 3 2 3 2 1 2 3 4 3 4 5 6 7 8 9 10 11 12 12
output:
? 499999 ? 1 ? 749998 ? 874998 ? 812498 ? 843748 ? 828123 ? 820310 ? 824216 ? 826169 ? 827146 ? 826657 ? 826901 ? 827023 ? 827084 ? 827115 ? 827130 ? 827138 ? 827142 ? 827144 ? 827145 ! 827145
result:
ok Correct position at 827145
Test #16:
score: 0
Accepted
time: 2ms
memory: 5720kb
input:
999996 1 2 3 2 3 2 1 2 3 4 3 4 5 6 7 8 9 10 11 12 12
output:
? 499998 ? 1 ? 749997 ? 874997 ? 812497 ? 843747 ? 828122 ? 820309 ? 824215 ? 826168 ? 827145 ? 826656 ? 826900 ? 827022 ? 827083 ? 827114 ? 827129 ? 827137 ? 827141 ? 827143 ? 827144 ! 827144
result:
ok Correct position at 827144
Test #17:
score: 0
Accepted
time: 2ms
memory: 5740kb
input:
999995 1 2 3 4 5 4 3 4 5 6 5 6 7 8 9 10 11 12 13 14 14
output:
? 499998 ? 1 ? 749997 ? 874996 ? 937496 ? 968746 ? 953121 ? 945308 ? 949214 ? 951167 ? 952144 ? 951655 ? 951899 ? 952021 ? 952082 ? 952113 ? 952128 ? 952136 ? 952140 ? 952142 ? 952143 ! 952143
result:
ok Correct position at 952143
Test #18:
score: 0
Accepted
time: 2ms
memory: 5732kb
input:
999994 1 2 3 4 5 4 3 4 5 6 5 6 7 8 9 10 11 12 13 14 14
output:
? 499997 ? 1 ? 749996 ? 874995 ? 937495 ? 968745 ? 953120 ? 945307 ? 949213 ? 951166 ? 952143 ? 951654 ? 951898 ? 952020 ? 952081 ? 952112 ? 952127 ? 952135 ? 952139 ? 952141 ? 952142 ! 952142
result:
ok Correct position at 952142
Test #19:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
999993 1 2 3 4 5 4 3 4 5 6 5 6 7 8 9 10 11 12 13 14 14
output:
? 499997 ? 1 ? 749995 ? 874994 ? 937494 ? 968744 ? 953119 ? 945306 ? 949212 ? 951165 ? 952142 ? 951653 ? 951897 ? 952019 ? 952080 ? 952111 ? 952126 ? 952134 ? 952138 ? 952140 ? 952141 ! 952141
result:
ok Correct position at 952141
Test #20:
score: 0
Accepted
time: 1ms
memory: 5868kb
input:
999992 1 2 3 4 5 4 3 4 5 6 5 6 7 8 9 10 11 12 13 14 14
output:
? 499996 ? 1 ? 749994 ? 874993 ? 937493 ? 968743 ? 953118 ? 945305 ? 949211 ? 951164 ? 952141 ? 951652 ? 951896 ? 952018 ? 952079 ? 952110 ? 952125 ? 952133 ? 952137 ? 952139 ? 952140 ! 952140
result:
ok Correct position at 952140
Test #21:
score: 0
Accepted
time: 2ms
memory: 5820kb
input:
999991 1 2 3 2 3 2 1 2 3 4 3 4 5 6 7 8 9 10 11 12 12
output:
? 499996 ? 1 ? 749994 ? 874993 ? 812493 ? 843743 ? 828118 ? 820305 ? 824211 ? 826164 ? 827141 ? 826652 ? 826896 ? 827018 ? 827079 ? 827110 ? 827125 ? 827133 ? 827137 ? 827139 ? 827140 ! 827140
result:
ok Correct position at 827140
Test #22:
score: 0
Accepted
time: 1ms
memory: 5812kb
input:
1000000 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0
output:
? 500000 ? 1 ? 250000 ? 2 ? 125001 ? 3 ? 62502 ? 4 ? 31253 ? 5 ? 15629 ? 6 ? 7817 ? 7 ? 3912 ? 8 ? 1960 ? 9 ? 984 ? 10 ? 497 ? 11 ? 254 ? 12 ? 133 ? 13 ? 73 ? 14 ? 43 ! 43
result:
ok Correct position at 43
Test #23:
score: 0
Accepted
time: 1ms
memory: 5708kb
input:
999999 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 2 1 2 1 0 0
output:
? 500000 ? 1 ? 250000 ? 2 ? 125001 ? 3 ? 62502 ? 4 ? 31253 ? 5 ? 15629 ? 6 ? 7817 ? 7 ? 3912 ? 8 ? 1960 ? 9 ? 984 ? 10 ? 497 ? 11 ? 254 ? 12 ? 133 ? 13 ? 73 ? 14 ? 43 ? 15 ? 58 ? 50 ? 54 ? 52 ? 51 ! 51
result:
ok Correct position at 51
Test #24:
score: 0
Accepted
time: 1ms
memory: 5828kb
input:
999998 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 2 1 2 1 0 0
output:
? 499999 ? 1 ? 250000 ? 2 ? 125001 ? 3 ? 62502 ? 4 ? 31253 ? 5 ? 15629 ? 6 ? 7817 ? 7 ? 3912 ? 8 ? 1960 ? 9 ? 984 ? 10 ? 497 ? 11 ? 254 ? 12 ? 133 ? 13 ? 73 ? 14 ? 43 ? 15 ? 58 ? 50 ? 54 ? 52 ? 51 ! 51
result:
ok Correct position at 51
Test #25:
score: 0
Accepted
time: 0ms
memory: 5736kb
input:
999997 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 2 1 2 1 0 0
output:
? 499999 ? 1 ? 250000 ? 2 ? 125001 ? 3 ? 62502 ? 4 ? 31253 ? 5 ? 15629 ? 6 ? 7817 ? 7 ? 3912 ? 8 ? 1960 ? 9 ? 984 ? 10 ? 497 ? 11 ? 254 ? 12 ? 133 ? 13 ? 73 ? 14 ? 43 ? 15 ? 58 ? 50 ? 54 ? 52 ? 51 ! 51
result:
ok Correct position at 51
Test #26:
score: 0
Accepted
time: 1ms
memory: 5696kb
input:
1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 12 11 10 11 12 11 12 12
output:
? 500000 ? 1 ? 750000 ? 875000 ? 937500 ? 968750 ? 984375 ? 992188 ? 996094 ? 998047 ? 999024 ? 999512 ? 999756 ? 999878 ? 999817 ? 999786 ? 999771 ? 999778 ? 999782 ? 999780 ? 999781 ! 999781
result:
ok Correct position at 999781
Test #27:
score: 0
Accepted
time: 1ms
memory: 5892kb
input:
999999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 15 16 16
output:
? 500000 ? 1 ? 750000 ? 875000 ? 937500 ? 968750 ? 984375 ? 992187 ? 996093 ? 998046 ? 999023 ? 999511 ? 999755 ? 999877 ? 999938 ? 999969 ? 999984 ? 999976 ? 999980 ! 999980
result:
ok Correct position at 999980
Test #28:
score: 0
Accepted
time: 1ms
memory: 5780kb
input:
999998 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 15 16 16
output:
? 499999 ? 1 ? 749999 ? 874999 ? 937499 ? 968749 ? 984374 ? 992186 ? 996092 ? 998045 ? 999022 ? 999510 ? 999754 ? 999876 ? 999937 ? 999968 ? 999983 ? 999975 ? 999979 ! 999979
result:
ok Correct position at 999979
Test #29:
score: 0
Accepted
time: 0ms
memory: 5856kb
input:
999997 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 15 16 16
output:
? 499999 ? 1 ? 749998 ? 874998 ? 937498 ? 968748 ? 984373 ? 992185 ? 996091 ? 998044 ? 999021 ? 999509 ? 999753 ? 999875 ? 999936 ? 999967 ? 999982 ? 999974 ? 999978 ! 999978
result:
ok Correct position at 999978
Test #30:
score: 0
Accepted
time: 1ms
memory: 5592kb
input:
1000000 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 13 12 13 12 12
output:
? 500000 ? 1 ? 250000 ? 2 ? 375000 ? 437500 ? 468750 ? 484375 ? 492187 ? 496093 ? 498046 ? 499023 ? 499511 ? 499755 ? 499877 ? 499938 ? 499969 ? 499953 ? 499945 ? 499949 ? 499947 ! 499947
result:
ok Correct position at 499947
Test #31:
score: 0
Accepted
time: 1ms
memory: 5668kb
input:
999999 1 2 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0
output:
? 500000 ? 1 ? 750000 ? 625000 ? 562500 ? 500001 ? 531250 ? 500002 ? 515626 ? 500003 ? 507814 ? 500004 ? 503909 ? 500005 ? 501957 ? 500006 ? 500981 ? 500007 ? 500494 ? 500008 ? 500251 ? 500009 ? 500130 ? 500010 ? 500070 ! 500070
result:
ok Correct position at 500070
Test #32:
score: 0
Accepted
time: 0ms
memory: 5700kb
input:
999998 1 2 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 2 1 0 0
output:
? 499999 ? 1 ? 749999 ? 624999 ? 562499 ? 500000 ? 531249 ? 500001 ? 515625 ? 500002 ? 507813 ? 500003 ? 503908 ? 500004 ? 501956 ? 500005 ? 500980 ? 500006 ? 500493 ? 500007 ? 500250 ? 500008 ? 500129 ? 500009 ? 500069 ? 500010 ? 500099 ? 500084 ? 500076 ! 500076
result:
ok Correct position at 500076
Test #33:
score: 0
Accepted
time: 1ms
memory: 5716kb
input:
999997 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 13 14 15 16 15 15
output:
? 499999 ? 1 ? 250000 ? 2 ? 374999 ? 437499 ? 468749 ? 484374 ? 492186 ? 496092 ? 498045 ? 499022 ? 499510 ? 499754 ? 499876 ? 499937 ? 499968 ? 499952 ? 499960 ? 499964 ? 499966 ? 499965 ! 499965
result:
ok Correct position at 499965
Test #34:
score: 0
Accepted
time: 0ms
memory: 5636kb
input:
1000000 1 2 3 4 5 6 7 6 7 8 7 8 9 10 11 10 11 10 9 8 8
output:
? 500000 ? 1 ? 750000 ? 875000 ? 937500 ? 968750 ? 984375 ? 992188 ? 988281 ? 990234 ? 991211 ? 990722 ? 990966 ? 991088 ? 991149 ? 991180 ? 991164 ? 991172 ? 991168 ? 991166 ? 991165 ! 991165
result:
ok Correct position at 991165
Test #35:
score: 0
Accepted
time: 1ms
memory: 5680kb
input:
999999 1 2 1 0 1 2 1 0 1 2 3 4 3 4 5 6 7 6 7 6 5 4 4
output:
? 500000 ? 1 ? 750000 ? 625000 ? 562500 ? 500001 ? 593750 ? 578125 ? 570312 ? 562501 ? 574218 ? 576171 ? 577148 ? 576659 ? 576903 ? 577025 ? 577086 ? 577117 ? 577101 ? 577109 ? 577105 ? 577103 ? 577102 ! 577102
result:
ok Correct position at 577102
Test #36:
score: 0
Accepted
time: 1ms
memory: 5624kb
input:
999998 1 2 1 0 1 2 1 0 1 2 3 4 3 4 5 6 7 6 7 6 5 4 4
output:
? 499999 ? 1 ? 749999 ? 624999 ? 562499 ? 500000 ? 593749 ? 578124 ? 570311 ? 562500 ? 574217 ? 576170 ? 577147 ? 576658 ? 576902 ? 577024 ? 577085 ? 577116 ? 577100 ? 577108 ? 577104 ? 577102 ? 577101 ! 577101
result:
ok Correct position at 577101
Test #37:
score: 0
Accepted
time: 1ms
memory: 5812kb
input:
999997 1 2 3 2 1 0 1 2 3 4 5 4 5 6 7 8 7 8 7 6 5 5
output:
? 499999 ? 1 ? 749998 ? 874998 ? 812498 ? 781248 ? 765623 ? 749999 ? 773435 ? 777341 ? 779294 ? 780271 ? 779782 ? 780026 ? 780148 ? 780209 ? 780240 ? 780224 ? 780232 ? 780228 ? 780226 ? 780225 ! 780225
result:
ok Correct position at 780225
Test #38:
score: 0
Accepted
time: 1ms
memory: 3724kb
input:
1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 20
output:
? 500000 ? 1 ? 750000 ? 875000 ? 937500 ? 968750 ? 984375 ? 992188 ? 996094 ? 998047 ? 999024 ? 999512 ? 999756 ? 999878 ? 999939 ? 999970 ? 999985 ? 999993 ? 999997 ? 999999 ? 1000000 ! 1000000
result:
ok Correct position at 1000000
Test #39:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
999999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 20
output:
? 500000 ? 1 ? 750000 ? 875000 ? 937500 ? 968750 ? 984375 ? 992187 ? 996093 ? 998046 ? 999023 ? 999511 ? 999755 ? 999877 ? 999938 ? 999969 ? 999984 ? 999992 ? 999996 ? 999998 ? 999999 ! 999999
result:
ok Correct position at 999999
Test #40:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
999998 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 20
output:
? 499999 ? 1 ? 749999 ? 874999 ? 937499 ? 968749 ? 984374 ? 992186 ? 996092 ? 998045 ? 999022 ? 999510 ? 999754 ? 999876 ? 999937 ? 999968 ? 999983 ? 999991 ? 999995 ? 999997 ? 999998 ! 999998
result:
ok Correct position at 999998
Test #41:
score: 0
Accepted
time: 1ms
memory: 5820kb
input:
999997 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 20
output:
? 499999 ? 1 ? 749998 ? 874998 ? 937498 ? 968748 ? 984373 ? 992185 ? 996091 ? 998044 ? 999021 ? 999509 ? 999753 ? 999875 ? 999936 ? 999967 ? 999982 ? 999990 ? 999994 ? 999996 ? 999997 ! 999997
result:
ok Correct position at 999997
Test #42:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 20
output:
? 500000 ? 1 ? 750000 ? 875000 ? 937500 ? 968750 ? 984375 ? 992188 ? 996094 ? 998047 ? 999024 ? 999512 ? 999756 ? 999878 ? 999939 ? 999970 ? 999985 ? 999993 ? 999997 ? 999999 ? 1000000 ! 1000000
result:
ok Correct position at 1000000
Test #43:
score: 0
Accepted
time: 1ms
memory: 5636kb
input:
1000000 1 1
output:
? 500000 ? 1 ! 1
result:
ok Correct position at 1