QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#876167 | #9734. Identify Chord | Lulu | WA | 4ms | 3712kb | C++14 | 2.5kb | 2025-01-30 17:57:14 | 2025-01-30 17:57:16 |
Judging History
answer
/*
Author:
Homework:QH01
Problem:identify
Time:2025 - 1 - 30
Calm down!
Think twice and type.
*/
#include<bits/stdc++.h>
#define REP(i,l,r) for(int i=(l);i<=(r);i++)
#define PER(i,r,l) for(int i=(r);i>=(l);i--)
#define pi pair<int,int>
#define mkp(x,y) make_pair(x,y)
#define fi first
#define se second
#define ll long long
#define lc tr[i].ch[0]
#define rc tr[i].ch[1]
#define Lc tr[j].ch[0]
#define Rc tr[j].ch[1]
#define lowbit(i) (i&(-i))
using namespace std;
inline int read(){
int x=0,f=1;
char c=getchar();
while(!isdigit(c)){
if(c=='-')f=-1;
c=getchar();
}
while(isdigit(c)){
x=(x<<3)+(x<<1)+c-'0';
c=getchar();
}
return x*f;
}
void write(int x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
}
int getrand(int mod){
ll x=0;
x<<=15,x+=rand();
x<<=15,x+=rand();
x<<=15,x+=rand();
return x%mod+1;
}
int cnt;
int query(int x,int y){
if(++cnt>40)exit(0);
putchar('?'),putchar(' ');
write(x),putchar(' ');
write(y),putchar('\n');
fflush(stdout);
return read();
}
void print(int x,int y){
putchar('!'),putchar(' ');
write(x),putchar(' ');
write(y),putchar('\n');
fflush(stdout);
int res=read();
if(res==-1)exit(0);
}
int n,ans;
bool check(int x,int y){
if(y<x)swap(x,y);
int dis=min(y-x,x+n-y);
ans=query(x,y);
return ans!=dis;
}
void solve(){
cnt=0;
n=read();
int x=getrand(n),y=x+1+getrand(n-3);if(y>n)y-=n;
while(!check(x,y)){
x=getrand(n),y=x+1+getrand(n-3);
if(y>n)y-=n;
}
if(x>y)swap(x,y);
bool dirx=0,diry=0;
if(query(x%n+1,y)==ans-1)dirx=1;
if(query(x,y%n+1)==ans-1)diry=1;
if(dirx){
int l=x+1,r=y-1,res=x;
while(l<=r){
int mid=(l+r)/2;
if(query(mid,y)==ans-(mid-x))res=mid,l=mid+1;
else r=mid-1;
}
ans-=res-x+1,x=res;
}else{
int l=y+1,r=n+x-1,res=n+x;
while(l<=r){
int mid=(l+r)/2;int v=mid;if(v>n)v-=n;
if(query(v,y)==ans-(n+x-mid))res=mid,r=mid-1;
else l=mid+1;
}
ans-=(n+x)-res+1,x=res;
}
if(diry)y+=ans;
else y+=n-ans;
if(x>n)x-=n;
if(y>n)y-=n;
print(x,y);
}
int main(){
srand(time(0));
// freopen("identify.in","r",stdin);
// freopen("identify.out","w",stdout);
int T=read();
while(T--)solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
2 6 2 2 2 2 2 1 2 1 4 2 2 1 1 1 1 1
output:
? 3 5 ? 1 3 ? 2 5 ? 3 5 ? 2 6 ? 6 5 ? 1 5 ! 2 4 ? 2 4 ? 2 4 ? 1 3 ? 2 3 ? 1 4 ? 4 3 ! 1 3
result:
ok ok (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 3712kb
input:
1000 15 6 6 5 4 6 7 1 19 5 4 4 4 5 4 1 17 3 2 4 5 3 2 1 15 4 2 5 6 7 5 3 5 6 1 14 3 4 2 1 3 2 1 1 15 5 4 4 3 4 4 1 17 6 5 3 5 6 6 4 2 3 1 20 3 7 8 6 5 6 5 1 13 4 3 5 6 5 2 4 4 5 2 2 1 1 18 4 6 5 5 3 4 3 2 1 13 4 5 3 3 2 3 1 14 2 3 4 4 3 3 2 1 17 6 5 6 1 3 2 1 12 4 4 2 3 4 4 3 3 2 1 10 2 2 3 3 2 3 2 ...
output:
? 8 15 ? 9 15 ? 8 1 ? 4 15 ? 6 15 ? 7 15 ! 8 5 ? 11 19 ? 12 19 ? 11 1 ? 15 19 ? 13 19 ? 12 19 ! 12 3 ? 2 12 ? 3 12 ? 2 13 ? 7 12 ? 4 12 ? 3 12 ! 3 11 ? 3 7 ? 6 8 ? 8 13 ? 3 11 ? 4 11 ? 3 12 ? 14 11 ? 1 11 ? 2 11 ! 3 1 ? 10 13 ? 1 11 ? 1 5 ? 2 5 ? 1 6 ? 3 5 ? 2 5 ! 2 5 ? 8 14 ? 9 14 ? 8 15 ? 11 14 ? ...
result:
wrong answer format Unexpected end of file - token expected (test case 404)