QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#876157 | #9734. Identify Chord | Lulu | TL | 0ms | 3712kb | C++14 | 2.4kb | 2025-01-30 17:51:06 | 2025-01-30 17:51:15 |
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 query(int x,int y){
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(){
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
2 6 2 3 2 1 2 1 1 1 4 2 1 1 1 1 1
output:
? 1 3 ? 3 6 ? 1 4 ? 2 4 ? 1 5 ? 2 4 ? 3 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
Time Limit Exceeded
input:
1000 15 4 3 3 2 5 4 6 2 2 3 1 19 4 7 4 2 2 2 5 4 4 5 3 4 1 17 3 2 6 7 7 4 4 5 1 15 4 7 3 2 3 1 1 2 1 14 4 4 5 6 6 3 5 6 1 15 7 3 2 2 4 2 3 1 17 5 4 4 3 2 4 6 3 2 1 20 2 3 1 3 4 3 1 13 3 3 5 2 3 1 4 5 4 3 1 18 8 5 4 7 4 4 6 6 5 5 3 4 3 2 1 13 3 5 3 2 5 6 5 2 1 2 1 14 3 2 4 2 3 1 4 5 4 3 1 17 4 3 5 2 ...
output:
? 9 13 ? 6 9 ? 4 7 ? 2 4 ? 2 9 ? 3 9 ? 2 10 ? 5 9 ? 7 9 ? 6 9 ! 5 8 ? 7 11 ? 7 14 ? 11 15 ? 1 18 ? 9 11 ? 1 18 ? 1 10 ? 2 10 ? 1 11 ? 5 10 ? 3 10 ? 4 10 ! 3 12 ? 1 15 ? 4 6 ? 5 14 ? 6 14 ? 5 15 ? 1 14 ? 3 14 ? 2 14 ! 3 11 ? 7 11 ? 5 12 ? 1 13 ? 3 15 ? 4 15 ? 3 1 ? 1 15 ? 2 15 ! 3 1 ? 4 14 ? 5 9 ? 2 ...