QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209839#6134. Soldier GamelingyingWA 391ms19880kbC++141.5kb2023-10-10 18:12:112023-10-10 18:12:11

Judging History

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

  • [2023-10-10 18:12:11]
  • 评测
  • 测评结果:WA
  • 用时:391ms
  • 内存:19880kb
  • [2023-10-10 18:12:11]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N=2e5+5;
const int inf=1e18;

int _,n,idx,ans;
int a[N];
struct node
{
	int dat,l,r;
	
	node(){}
	node(int _dat,int _l,int _r):dat(_dat),l(_l),r(_r){}
	
	bool operator<(const node &b)const{return dat>b.dat;}
	
}val[N];
struct Matrix
{
	int a[2][2];
	
	void init(){a[0][0]=a[0][1]=a[1][0]=a[1][1]=inf;}
	
	Matrix operator*(const Matrix &b)
	{
		Matrix c;c.init();
		for(int k=0;k<2;k++)
			for(int i=0;i<2;i++)
				for(int j=0;j<2;j++)
					c.a[i][j]=min(c.a[i][j],max(a[i][k],b.a[k][j]));
		return c;	
	}
	
}dat[4*N];

void build(int p,int l,int r)
{
	if(l==r)return dat[p].a[0][0]=inf,dat[p].a[0][1]=1,dat[p].a[1][0]=inf,dat[p].a[1][1]=inf,void();
	int mid=l+r>>1;
	build(p*2,l,mid),build(p*2+1,mid+1,r);
	dat[p]=dat[p*2]*dat[p*2+1];
}

void update(int p,int lt,int rt,int x,int v,int type)
{
	if(lt==rt)return dat[p].a[type][0]=v,void();
	int mid=lt+rt>>1;
	if(x<=mid)update(p*2,lt,mid,x,v,type);
	else update(p*2+1,mid+1,rt,x,v,type);
	dat[p]=dat[p*2]*dat[p*2+1];
}

signed main()
{
	scanf("%lld",&_);
	while(_--)
	{
		idx=0,ans=inf;
		scanf("%lld",&n);
		build(1,1,n);
		for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
		for(int i=1;i<=n;i++)val[++idx]=node(a[i],i,i);
		for(int i=2;i<=n;i++)val[++idx]=node(a[i]+a[i-1],i-1,i);
		sort(val+1,val+idx+1);
		for(int i=1;i<=idx;i++)
		{
			update(1,1,n,val[i].r,val[i].dat,(val[i].l<val[i].r));
			ans=min(ans,dat[1].a[0][0]-val[i].dat);
		}
		cout<<ans<<'\n';
	}
	return 0;
}

詳細信息

Test #1:

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

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: 391ms
memory: 19880kb

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

result:

wrong answer 3rd numbers differ - expected: '0', found: '1'