QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#882612 | #9734. Identify Chord | scallionsong | RE | 0ms | 0kb | C++17 | 3.6kb | 2025-02-05 09:52:34 | 2025-02-05 09:52:35 |
Judging History
answer
bool M1;
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define LL __int128
#define db double
#define LD long double
#define Pii pair<int,int>
#define Pll pair<ll,ll>
#define Pull pair<ull,ull>
#define Pdb pair<db,db>
#define fir first
#define sec second
#define vec vector<int>
#define pb push_back
#define qlr cerr<<"qlr\n"
#define dyh cerr<<"dyh\n"
#define pc(x) __builtin_popcount(x)
#define uni(x,y) uniform_int_distribution<int>(x,y)(rng)
#define unl(x,y) uniform_int_distribution<ll>(x,y)(rng)
#define unr(x,y) uniform_real_distribution<double>(x,y)(rng)
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define UF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define look_memory cerr<<'\n'<<abs(&M1-&M2)/1024.0/1024<<'\n'
#define look_time cerr<<'\n'<<clock()*1.0/CLOCKS_PER_SEC<<'\n'
mt19937 rng(time(0)^(*new int));
const ll INF=0x3f3f3f3f3f3f3f3f;
const int Mod=1e9+7;
template<typename T>
inline void inc(T &a,T b){
if(b<0) b+=Mod;
a+=b;
if(a>=Mod) a-=Mod;
}
template<typename T>
inline void dec(T &a,T b){
if(b<0) b+=Mod;
a-=b;
if(a<0) a+=Mod;
}
template<typename T>
inline void muc(T &a,T b){
a=a*b%Mod;
}
template<typename T>
inline bool chkmin(T &a,T b){
if(a<=b) return false;
a=b;
return true;
}
template<typename T>
inline bool chkmax(T &a,T b){
if(a>=b) return false;
a=b;
return true;
}
int T,n,P1,P2;
int dis(int x,int y){
int d=abs(x-y);
return min(d,n-d);
}
int ask(int x,int y){
cout<<"? "<<x<<' '<<y<<'\n';
cout.flush();
int res;
cin>>res;
return res;
}
int nxt(int x,int y){
return (x+y-1)%n+1;
}
int pre(int x,int y){
return (x-y+n-1)%n+1;
}
void solve1(){
int x=1,y=n/2+1;
bool fl=0;
while(ask(x,y)==dis(x,y)){
if(!fl) y++;
else x++;
fl^=1;
assert(y<=n);
}
int d=ask(x,y),p1,p2;
if(ask(nxt(x,1),y)==d-1){
int L=1,R=y-x,mid;
while(L<=R){
mid=(L+R)>>1;
if(ask(nxt(x,mid),y)==d-mid) L=mid+1;
else R=mid-1;
}
p1=nxt(x,R);
}
else if(ask(pre(x,1),y)==d-1){
int L=1,R=n-y+x,mid;
assert(pre(x,R)==y);
while(L<=R){
mid=(L+R)>>1;
if(ask(pre(x,mid),y)==d-mid) L=mid+1;
else R=mid-1;
}
p1=pre(x,R);
}
else p1=x;
d=ask(p1,y);
if(ask(p1,nxt(y,d-1))==1) p2=nxt(y,d-1);
else p2=pre(y,d-1);
cout<<"! "<<p1<<' '<<p2<<'\n';
cout.flush();
}
void solve2(){
int x=1,y=n/2+1;
while(ask(x,y)==dis(x,y)){
x++,y++;
assert(y<=n);
}
int d=ask(x,y),p1,p2;
if(ask(nxt(x,1),y)==d-1){
int L=1,R=y-x,mid;
while(L<=R){
mid=(L+R)>>1;
if(ask(nxt(x,mid),y)==d-mid) L=mid+1;
else R=mid-1;
}
p1=nxt(x,R);
}
else if(ask(pre(x,1),y)==d-1){
int L=1,R=n-y+x,mid;
assert(pre(x,R)==y);
while(L<=R){
mid=(L+R)>>1;
if(ask(pre(x,mid),y)==d-mid) L=mid+1;
else R=mid-1;
}
p1=pre(x,R);
}
else p1=x;
d=ask(p1,y);
if(ask(p1,nxt(y,d-1))==1) p2=nxt(y,d-1);
else p2=pre(y,d-1);
cout<<"! "<<p1<<' '<<p2<<'\n';
cout.flush();
}
void solve(){
cin>>n;
if(n<=10){
F(i,1,n){
F(j,i+2,n){
if(ask(i,j)==1){
cout<<"! "<<i<<' '<<j<<'\n';
cout.flush();
return;
}
}
}
assert(0);
}
if(n&1) solve1();
else solve2();
}
bool M2;
int main(){
// freopen("A.in","r",stdin);
// freopen("A1.out","w",stdout);
srand(time(0)^(*new int));
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>T;
while(T--) solve();
look_memory;
look_time;
return 0;
}
/*
g++ A1.cpp -o A1 -std=c++14 -O2&&./A1
1999999999 2 500 3
9123532
*/
詳細信息
Test #1:
score: 0
Runtime Error
input:
2 6 2 2 2 1 -1
output:
? 1 3 ? 1 4 ? 1 5 ? 1 6 ! 1 6