QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#388792 | #4884. Battleship: New Rules | unputdownable | WA | 3ms | 3696kb | C++17 | 3.0kb | 2024-04-13 19:46:26 | 2024-04-13 19:46:26 |
Judging History
answer
#include <bits/stdc++.h>
// #define int long long
#define i64 long long
#define pii pair <int, int>
using namespace std;
int n,Ax,Ay,Bx,By;
inline void Answer(int x,int y) {
cout<<"! "<<x<<' '<<y<<endl;
int res; cin>>res;
if(res==-1) exit(0);
}
inline int qry(int x,int y) {
cout<<"? "<<x<<' '<<y<<endl;
int res; cin>>res;
if(res==-1) exit(0);
return res;
}
#define lch (x<<1)
#define rch (x<<1|1)
inline void chkmin(int&x,int y) { x=min(x,y); }
inline void chkmax(int&x,int y) { x=max(x,y); }
struct segtree {
int lzy[2003];
void init(int n,int v) { for(int i=0; i<=4*n; ++i) lzy[i]=v; }
void upd(int x,int l,int r,const int ql,const int qr,const int v,const auto f) {
if(ql<=l&&r<=qr) return f(lzy[x],v),void();
int mid=(l+r)>>1;
if(ql<=mid) upd(lch,l,mid,ql,qr,v,f);
if(qr> mid) upd(rch,mid+1,r,ql,qr,v,f);
}
int qry(int x,int l,int r,const int q,const auto f) {
if(l==r) return assert(l==q),lzy[x];
int mid=(l+r)>>1;
if(q<=mid) return f(lzy[x],qry(lch,l,mid,q,f));
else return f(lzy[x],qry(rch,mid+1,r,q,f));
}
} L,R;
mt19937 rnd(191182396859681231);
int rev[4003];
pii pos[1000006];
inline void dfs(int x,int l,int r) {
int mid=(l+r)>>1; rev[x]=mid;
if(l<mid) dfs(lch,l,mid-1);
if(r>mid) dfs(rch,mid+1,r);
}
inline void work() {
int lim;
cin>>n; lim=6*n;
if(n&1) return Answer(-1,-1),void();
n=n/2-1;
int cnt=0;
auto Max=[&](int x,int y){return x>y ? x : y;};
auto Min=[&](int x,int y){return x<y ? x : y;};
dfs(1,1,n);
int ccc=0;
for(int i=1; i<=4*n; ++i) if(rev[i]) rev[++ccc]=rev[i];
for(int i=1; i<=n; ++i) {
pos[++cnt]=make_pair(rev[i],rev[i]);
for(int u=1; u<i; ++u) {
pos[++cnt]=make_pair(rev[i],rev[u]);
pos[++cnt]=make_pair(rev[u],rev[i]);
}
}
// for(int i=1; i<=n; ++i) {
// for(int u=1; u<=n; ++u) {
// pos[++cnt]=make_pair(i,u);
// }
// }
// for(int i=2; i<=cnt; ++i) swap(pos[i],pos[rnd()%i+1]);
assert(cnt==n*n);
L.init(n,0);
R.init(n,n+1);
int cntq=0;
for(int i=1; i<=cnt; ++i) {
int A,B,C,D,x=pos[i].first,y=pos[i].second;
if(L.qry(1,1,n,x,Max)>=y&&y>=R.qry(1,1,n,x,Min)) continue;
if(cntq==lim) return Answer(x<<1,y<<1),void();
A=qry(x*2,y*2),B=qry(x*2,y*2+1);
C=qry(x*2+1,y*2),D=qry(x*2+1,y*2+1); cntq+=4;
if(A==0&&B==0&&C==0&&D==0) return Answer(x<<1,y<<1),void();
if(A&&x!=n) R.upd(1,1,n,x+1,n,y+1,chkmin);
if(B&&x!=n) L.upd(1,1,n,x+1,n,y-1,chkmax);
if(C&&x!=1) R.upd(1,1,n,1,x-1,y+1,chkmin);
if(D&&x!=1) L.upd(1,1,n,1,x-1,y-1,chkmax);
}
exit(-1);
}
signed main() {
// freopen("localinput","r",stdin);
// freopen("localoutput","w",stdout);
ios::sync_with_stdio(0);
int T; cin>>T;
while(T--) work();
// fprintf(stderr,"%.4lf\n",1.0*clock()/CLOCKS_PER_SEC);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3696kb
input:
2 3 1 4 0 0 0 0 1
output:
! -1 -1 ? 2 2 ? 2 3 ? 3 2 ? 3 3 ! 2 2
result:
ok max_C=1.00, avg_C=0.50 (2 test cases)
Test #2:
score: 0
Accepted
time: 3ms
memory: 3672kb
input:
100 4 0 0 0 0 1 4 0 0 0 0 1 4 0 0 0 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