QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#189676 | #6134. Soldier Game | qzez | WA | 1187ms | 25920kb | C++14 | 2.2kb | 2023-09-27 19:25:48 | 2023-09-27 19:25:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=1e5+10,M=2;
struct matrix{
int a[M][M];
matrix(){
memset(a,0,sizeof a);
}
matrix operator * (const matrix &x)const{
matrix b;
for(int k=0;k<M;k++){
for(int i=0;i<M;i++){
for(int j=0;j<M;j++){
b.a[i][j]|=a[i][k]&x.a[k][j];
}
}
}
return b;
}
};
int T,n,m,a[N],b[N*2];
matrix t[N<<2],p[N];
void pushup(int rt){
t[rt]=t[rt<<1]*t[rt<<1|1];
}
void build(int l=1,int r=n,int rt=1){
if(l==r){
p[l]=matrix(),p[l].a[0][1]=1;
t[rt]=p[l];return;
}
int mid=(l+r)>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
pushup(rt);
}
void update(int x,int l=1,int r=n,int rt=1){
if(l==r){
t[rt]=p[l];return;
}
int mid=(l+r)>>1;
if(x<=mid)update(x,l,mid,rt<<1);
else update(x,mid+1,r,rt<<1|1);
pushup(rt);
}
int query(){
return t[1].a[0][0];
}
void modify(int x,int y,int z){
if(y-x==1){
p[y].a[0][0]=z,update(y);
if(y<n)p[y+1].a[1][1]=z,update(y+1);
}else{
p[y].a[1][0]=z,update(y);
}
}
vector<pair<int,int> >o[N*2];
void get(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]),b[++m]=a[i];
for(int i=1;i<n;i++)b[++m]=a[i]+a[i+1];
sort(b+1,b+1+m),m=unique(b+1,b+1+m)-b-1;
for(int i=1;i<=n;i++){
o[lower_bound(b+1,b+1+m,a[i])-b].push_back({i-1,i});
}
for(int i=1;i<n;i++){
o[lower_bound(b+1,b+1+m,a[i]+a[i+1])-b].push_back({i-1,i+1});
}
int ans=2e9;
build();
for(int l=1,r=1;l<=m;l++){
for(;r<=m&&!query();r++){
for(auto t:o[r])modify(t.first,t.second,1);
}
if(query())ans=min(ans,b[r-1]-b[l]);
for(auto t:o[l])modify(t.first,t.second,0);
}
printf("%d\n",ans);
}
void clr(){
for(int i=1;i<=m;i++)o[i].clear();
m=0;
}
int main(){
for(scanf("%d",&T);T--;clr())get();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 17284kb
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: 1187ms
memory: 25920kb
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'