QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#378673 | #6394. Turn on the Light | Aprilend# | WA | 1ms | 3728kb | C++14 | 2.0kb | 2024-04-06 14:07:31 | 2024-04-06 14:07:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define edl '\n'
#define re return
#define gcd __gcd
#define db double
#define fir first
#define sec second
#define MAX 1000006
#define ll long long
#define i64 __int128
#define inf 2147483647
#define MAXN 100000009
#define pll pair<ll,ll>
#define pb push_back
#define vint vector<int>
#define pii pair<int,int>
#define ANS cout<<ans<<edl
#define No cout<<"No"<<edl
#define NO cout<<"NO"<<edl
#define hhh cout<<"hhh"<<edl
#define Yes cout<<"Yes"<<edl
#define YES cout<<"YES"<<edl
#define all(a,l,r) a+l,a+1+r
#define ull unsigned long long
#define INF 9223372036854775807
#define vpii vector<pair<int,int>>
#define sp(x) fixed << setprecision(x)
#define FOR(i,l,r) for(auto(i)=(l);(i)<=(r);++(i))
const ll mod = 1000000007;
ll qpow(ll n,ll m,ll mod)
{
ll ans=1;if(n>mod) n%=mod;
while(m>0){if(m&1) {ans*=n;ans%=mod;}
n*=n; n%=mod; m>>=1;} return ans;
}
int n, pre, now, l, r, ans;
int a[MAX];
int ck(int mid) {
cout<<"? "<<mid<<endl;
cin>>pre;
a[mid]=pre;
cout<<"? "<<l<<endl;
cin>>now;
a[now]=pre;
if(now>pre) re 1;
else if(now==pre) re 2;
else if(now<pre) re 3;
}
void Solve(void)
{
cin>>n;
l=1, r=n;
if(n==2) {
cout<<1<<endl;
cin>>ans;
if(ans==0) {
cout<<"! "<<1<<endl;
}
else cout<<"! "<<2<<endl;
re;
}
while(l <= r) {
ll mid = l + r >> 1;
if(l+1==r) {
if(l!=1) {
cout<<"? "<<l<<endl;
cin>>ans;
a[l]=ans;
if(a[l-1]<a[l]) cout<<"! "<<l+1<<endl;
else if(a[l-1]==a[l]) cout<<"! "<<l<<endl;
}
else if(r!=n) {
cout<<"? "<<r<<endl;
cin>>ans;
a[r]=ans;
if(a[r]>a[r+1]) cout<<"! "<<r-1<<endl;
else if(a[r]==a[r+1]) cout<<"! "<<r<<endl;
}
re;
}
int t=ck(mid);
if(t==1) l=mid+1;
else if(t==2) {
cout<<"! "<<l<<endl;
re;
}
else {
l++; r=mid-1;
}
}
// cout.flush();
}
int main(void)
{
std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int _=1;
// cin>>_;
while(_--)
Solve ();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3672kb
input:
3 1 2 2 2
output:
? 2 ? 1 ? 3 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
10 1 2 3 4 5
output:
? 5 ? 1 ? 8 ? 6 ? 9 ! 10
result:
ok Correct position at 10
Test #3:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
9 1 2 3 4 5
output:
? 5 ? 1 ? 7 ? 6 ? 8 ! 9
result:
ok Correct position at 9
Test #4:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
8 1 2 3 4 5
output:
? 4 ? 1 ? 6 ? 5 ? 7 ! 8
result:
ok Correct position at 8
Test #5:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
7 1 2 3 4 4 4
output:
? 4 ? 1 ? 6 ? 5 ? 7 ? 7 ! 7
result:
ok Correct position at 7
Test #6:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
6 1 2 3 4 4 4
output:
? 3 ? 1 ? 5 ? 4 ? 6 ? 6 ! 6
result:
ok Correct position at 6
Test #7:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
5 1 2 3
output:
? 3 ? 1 ? 4 ! 5
result:
ok Correct position at 5
Test #8:
score: 0
Accepted
time: 1ms
memory: 3728kb
input:
4 1 2 3
output:
? 2 ? 1 ? 3 ! 4
result:
ok Correct position at 4
Test #9:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
3 1 1
output:
? 2 ? 1 ! 1
result:
ok Correct position at 1
Test #10:
score: -100
Wrong Answer
time: 1ms
memory: 3716kb
input:
2
output:
1
result:
wrong answer Token parameter [name=type] equals to "1", doesn't correspond to pattern "?|!"