QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#209415#6134. Soldier GameQZJ123456WA 456ms19540kbC++142.1kb2023-10-10 14:55:392023-10-10 14:55:39

Judging History

你现在查看的是最新测评结果

  • [2023-10-10 14:55:39]
  • 评测
  • 测评结果:WA
  • 用时:456ms
  • 内存:19540kb
  • [2023-10-10 14:55:39]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int T,n;
const ll inf=1e18;
struct matrix{
	ll a[2][2];
	void init(){
		a[0][0]=a[0][1]=a[1][0]=a[1][1]=inf;
	}
}c;
matrix mul(matrix a,matrix b){
	c.a[0][0]=min(max(a.a[0][0],b.a[0][0]),max(a.a[0][1],b.a[1][0]));
	c.a[1][0]=min(max(a.a[1][0],b.a[0][0]),max(a.a[1][1],b.a[1][0]));
	c.a[0][1]=min(max(a.a[0][0],b.a[0][1]),max(a.a[0][1],b.a[1][1]));
	c.a[1][1]=min(max(a.a[1][0],b.a[0][1]),max(a.a[1][1],b.a[1][1]));
	return c;
}
struct Seg{
	int l,r;
	matrix val;
}Tree[400005];
ll a[100005];
void out(matrix a){
	cout<<a.a[0][0]<<" "<<a.a[0][1]<<endl;
	cout<<a.a[1][0]<<" "<<a.a[1][1]<<endl;
}
void ztree(int p,int l,int r){
	Tree[p].l=l,Tree[p].r=r;
	if(l==r){
		Tree[p].val.a[0][0]=inf,Tree[p].val.a[1][0]=0;
		Tree[p].val.a[1][1]=a[l];
		if(l>1)Tree[p].val.a[0][1]=a[l-1]+a[l];
		else Tree[p].val.a[0][1]=inf;
		return;
	}
	int mid=l+r>>1;
	ztree(p*2,l,mid);
	ztree(p*2+1,mid+1,r);
	Tree[p].val=mul(Tree[p*2].val,Tree[p*2+1].val);
}
void upd(int p,int x,int op,ll val){
	if(Tree[p].l==Tree[p].r){
		if(op==0)Tree[p].val.a[1][1]=val;
		else Tree[p].val.a[0][1]=val;
//		cout<<p<<" "<<Tree[p].l<<" "<<Tree[p].r<<":";
//		out(Tree[p].val);
		return;
	}
	int mid=Tree[p].l+Tree[p].r>>1;
	if(x<=mid)upd(p*2,x,op,val);
	else upd(p*2+1,x,op,val);
	Tree[p].val=mul(Tree[p*2].val,Tree[p*2+1].val);
//	cout<<p<<" "<<Tree[p].l<<" "<<Tree[p].r<<":";
//	out(Tree[p].val);
}
struct node{
	int op,id;
	ll val;
	node(){}
	node(int op_,int id_,ll val_){
		op=op_,id=id_,val=val_;
	}
}arr[200005];
int tot;
bool cmp(node x,node y){
	return x.val<y.val;
}
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
		if(n<=2){
			puts("0");
			continue;
		}
		ll ans=inf;tot=0;
		for(int i=1;i<=n;i++){
			if(i>1)arr[++tot]=node(1,i,a[i]+a[i-1]);
			arr[++tot]=node(0,i,a[i]);
		}
		sort(arr+1,arr+1+tot,cmp);
		ztree(1,1,n);
		for(int i=1;i<=tot;i++){
			ans=min(ans,Tree[1].val.a[1][1]-arr[i].val);
			upd(1,arr[i].id,arr[i].op,inf);
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5904kb

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: 456ms
memory: 19540kb

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
2000000000
100
135
103
181
189
84
100
164
176
0
147
135
152
100
200
131
134
0
136
0
72
171
146
0
183
77
176
100
200
135
38
109
119
126
158
189
70
0
38
999867614
188
161
0
116
116
200
0
101
200
50
0
183
139
0
183
107
139
0
178
85993
126
153
168
163
96
100
96
52
126
71
130
79
0
123
188
173
33
0
...

result:

wrong answer 11th numbers differ - expected: '63', found: '100'