QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#282498 | #6134. Soldier Game | ship2077 | WA | 548ms | 19896kb | C++14 | 1.9kb | 2023-12-12 10:56:54 | 2023-12-12 10:56:54 |
Judging History
answer
#include<bits/stdc++.h>
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
using namespace std;
constexpr int M=1e5+5;
vector<pair<int,int>>pos[M<<1];
int n,m,ans,num,a[M],lsh[M<<1];
struct matrix{bool mat00,mat01,mat10,mat11;}tr[M<<2];
matrix operator * (matrix a,matrix b){
return {a.mat00&&b.mat00||a.mat01&&b.mat10,a.mat00&&b.mat01||a.mat01&&b.mat11,
a.mat10&&b.mat00||a.mat11&&b.mat10,a.mat10&&b.mat01||a.mat11&&b.mat11};
}
int read(){
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x*f;
}
void build(int l,int r,int x){
tr[x].mat00=tr[x].mat01=tr[x].mat10=tr[x].mat11=0;
if (l==r) return tr[x].mat10=1,void();int mid=l+r>>1;
build(l,mid,ls(x));build(mid+1,r,rs(x));tr[x]=tr[ls(x)]*tr[rs(x)];
}
void update(int u,int c,int l=1,int r=n,int x=1){
if (l==r){
if (!c) tr[x].mat00^=1;
else if (c==1) tr[x].mat01^=1;
else tr[x].mat11^=1;
return ;
}
int mid=l+r>>1;
if (u<=mid) update(u,c,l,mid,ls(x));
else update(u,c,mid+1,r,rs(x));
tr[x]=tr[ls(x)]*tr[rs(x)];
}
void modify(int now){
for (auto [x,y]:pos[now])
if (y) update(x,1);
else {
update(x,2);
if (x<n) update(x+1,0);
}
}
void solve(){
n=read();num=0;
for (int i=1;i<=n;i++){
a[i]=read();lsh[++num]=a[i];
if (i>1) lsh[++num]=a[i-1]+a[i];
}
sort(lsh+1,lsh+num+1);num=unique(lsh+1,lsh+num+1)-lsh-1;
for (int i=1;i<=num;i++) pos[i].clear();
for (int i=1;i<=n;i++){
pos[lower_bound(lsh+1,lsh+num+1,a[i])-lsh].push_back({i,0});
if (i>1) pos[lower_bound(lsh+1,lsh+num+1,a[i-1]+a[i])-lsh].push_back({i,1});
} ans=INT_MAX;build(1,n,1);
for (int l=1,r=1;r<=num;r++){
modify(r);
while (tr[1].mat11&&l<=r){
ans=min(ans,lsh[r]-lsh[l]);
modify(l++);
}
}
printf("%d\n",ans);
}
int main(){int T=read();
while (T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 10348kb
input:
3 5 -1 4 2 1 1 4 1 3 2 4 1 7
output:
1 2 0
result:
ok 3 number(s): "1 2 0"
Test #2:
score: -100
Wrong Answer
time: 548ms
memory: 19896kb
input:
10010 1 1000000000 1 -1000000000 2 1000000000 -1000000000 4 1000000000 1000000000 -1000000000 -1000000000 3 100 -100 100 16 -17 91 -19 66 100 -70 -71 76 -58 99 52 19 25 -67 -63 -32 7 -95 -26 63 -55 -19 77 -100 17 -100 72 -53 -32 8 -100 53 44 -100 -65 -81 -59 100 100 57 -47 1 11 99 10 -100 3 32 2 -26...
output:
0 0 0 -1294967296 100 135 103 181 189 84 63 164 176 0 147 135 152 36 200 131 134 0 136 0 72 171 146 0 183 77 176 89 200 135 38 109 119 126 158 189 70 0 38 999804364 188 161 0 116 116 200 0 101 200 39 0 183 139 0 183 107 139 0 178 85993 126 153 168 163 96 53 96 52 126 47 130 79 0 123 188 173 33 0 83 ...
result:
wrong answer 4th numbers differ - expected: '2000000000', found: '-1294967296'