QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212931#6134. Soldier GameRDFZchenyyWA 0ms7912kbC++141.8kb2023-10-13 23:13:302023-10-13 23:13:31

Judging History

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

  • [2023-10-13 23:13:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:7912kb
  • [2023-10-13 23:13:30]
  • 提交

answer

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

#define MAXN 100005
#define ls (id<<1)
#define rs (id<<1)|1

#define MOD 998244353

struct Mat{
	long long a[2][2];
	
	Mat operator*(const Mat& y)const{
		Mat ret;
		ret.a[0][0]=(a[0][0]*y.a[0][0]+a[0][1]*y.a[1][0])%MOD;
		ret.a[0][1]=(a[0][0]*y.a[0][1]+a[0][1]*y.a[1][1])%MOD;
		ret.a[1][0]=(a[1][0]*y.a[0][0]+a[1][1]*y.a[1][0])%MOD;
		ret.a[1][1]=(a[1][0]*y.a[0][1]+a[1][1]*y.a[1][1])%MOD;
		return ret;		
	} 
};
Mat t[MAXN<<2];

struct Cat{
	int typ;
	int num,sum;
};
Cat c[MAXN<<1];

int n,ans=0x3f3f3f3f;
int a[MAXN];
int cnt[MAXN][2]; // 0-single 1-double

bool cmp(Cat a,Cat b){
	return a.sum<b.sum;
}

void update(int id){
	t[id]=t[ls]*t[rs];
	
	return;
}

void build(int id,int l,int r){
	if(l==r){
		t[id].a[0][1]=1;
		return;
	}
	
	int mid=(l+r)>>1;
	build(ls,l,mid);
	build(rs,mid+1,r);
	update(id);
	
	return;
}

void change(int id,int l,int r,int ti,int typ,int val){
	if(l==r){
		t[id].a[typ][0]+=val;
		return;
	}
	
	int mid=(l+r)>>1;
	if(ti<=mid){
		change(ls,l,mid,ti,typ,val);
	}else{
		change(rs,mid+1,r,ti,typ,val);
	}
	update(id);
	
	return;
}

long long query(){
	return t[1].a[0][0];
}

bool ok(){
	return query()!=0;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		c[i].typ=0;
		c[i].num=i;
		c[i].sum=a[i];
		if(i!=1){
			c[i+n-1].typ=1;
			c[i+n-1].num=i;
			c[i+n-1].sum=a[i]+a[i-1];
		}
	}	
	stable_sort(c+1,c+n*2,cmp);
	build(1,1,n);
	for(int nl=1,nr=0;nl<=n;nl++){
		while((!ok())&&(nr<=2*n-2)){
			nr++;
			change(1,1,n,c[nr].num,c[nr].typ,1);
		}
		if(ok()){
			// cntans
			ans=min(ans,c[nr].sum-c[nl].sum);
		}
		change(1,1,n,c[nl].num,c[nl].typ,-1);
	}
	printf("%d\n",ans);
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 7912kb

input:

3
5
-1 4 2 1 1
4
1 3 2 4
1
7

output:

0

result:

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