QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#339117#8218. 水镜linrui0 1ms8012kbC++142.4kb2024-02-26 19:31:322024-02-26 19:31:33

Judging History

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

  • [2024-02-26 19:31:33]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:8012kb
  • [2024-02-26 19:31:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using u64=unsigned long long;
using u32=unsigned;
using i128=__int128;
using lf=long double;
#define pb push_back
#define fi first
#define se second
#define F(i,l,r) for(int i=l,R_F=r;i<=R_F;++i)
#define G(i,r,l) for(int i=r,L_F=l;i>=L_F;--i)
#define il inline
#define ct const
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define CUT dbg("**********\n")
ct int INF=1.02e9;
//ct ll INF=4e18L;
ct lf PI=acos(-1L),EPS=1e-9L;
il int dcmp(lf x){return fabs(x)<=EPS?0:(x<0?-1:1);}
template<class T>
il void tomx(T&x,T y){x<y?x=y,0:0;}
template<class T>
il void tomn(T&x,T y){y<x?x=y,0:0;}
ct ll P=998244353;
il ll qpow(ll x,ll y){
	ll r=1;for(;y;y>>=1,x=x*x%P)y&1?(r=r*x%P):0;return r;
}
il ll inv(ll x){return qpow(x,P-2);}
il void add(int&x,int y){x+=y,x-=(x>=P)*P;}

struct Seg{ll l,r;};
ct Seg A[2]={Seg{INF,-INF},Seg{-INF,INF}};
il bool ept(Seg x){return x.l>=x.r;}
il Seg operator*(Seg x,Seg y){return Seg{max(x.l,y.l),min(x.r,y.r)};}
il Seg operator+(Seg x,Seg y){
	if(ept(x))return y;
	if(ept(y))return x;
//	dbg("Seg+Seg:\n");
//	dbg(" %lld %lld\n",x.l,x.r);
//	dbg(" %lld %lld\n",y.l,y.r);
	return Seg{min(x.l,y.l),max(x.r,y.r)};
}
struct Mat{Seg a[2][2];};
ct Mat UNIT={{{A[1],A[0]},{A[0],A[1]}}};
il Mat operator*(Mat x,Mat y){
	Mat z{};
	F(i,0,1)F(j,0,1)
		z.a[i][j]=x.a[i][0]*y.a[0][j]+x.a[i][1]*y.a[1][j];
	return z;
}
ct int N=500500;
Mat pre[N],suf[N];
int n,l,r,m;
ll a[N];
il Mat mkmat(int i){
	ll x=a[i],y=a[i+1];
	return Mat{{
		{A[x<y],Seg{x+y,INF}},
		{Seg{-INF,x+y},A[x>y]},
	}};
}
il void del(){
	if(l==m){
		m=r,pre[m]=suf[m]=UNIT;
		G(i,m-1,l)suf[i]=mkmat(i)*suf[i+1];
	}++l;
}
il void ins(){++r,pre[r]=pre[r-1]*mkmat(r-1);}
il bool qry(){
	Mat res=suf[l]*pre[r];
//	Mat res=UNIT;
//	F(i,l,r-1)res=res*mkmat(i);
//	dbg("qry:l=%d r=%d\n",l,r);
//	F(i,0,1){
//		F(j,0,1){
//			dbg("(%lld,%lld) ",res.a[i][j].l,res.a[i][j].r);
//		}
//		puts("");
//	}
	return 
		!ept(res.a[0][0])||
		!ept(res.a[0][1])||
		!ept(res.a[1][0])||
		!ept(res.a[1][1]);
}
int main(){
#ifdef LOCAL
	freopen("B.in","r",stdin);
//	freopen(".out","w",stdout);
#endif
	scanf("%d",&n),l=r=m=1,pre[m]=suf[m]=UNIT;
	F(i,1,n)scanf("%lld",a+i);
	ll ans=0;
	F(i,1,n){
		while(r<n&&qry())ins();
//		dbg("ans:%d %d %d\n",l,r,qry());
		ans+=r-l+qry()-1,del();
	}printf("%lld\n",ans);
}


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 1ms
memory: 8012kb

input:

2
2 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7928kb

input:

10
2 2 2 2 1 4 5 3 3 2

output:

20

result:

ok 1 number(s): "20"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7968kb

input:

10
2 2 1 2 2 2 1 4 1 4

output:

17

result:

ok 1 number(s): "17"

Test #4:

score: 0
Accepted
time: 0ms
memory: 7980kb

input:

10
1 5 2 2 5 4 4 4 1 3

output:

20

result:

ok 1 number(s): "20"

Test #5:

score: -7
Wrong Answer
time: 0ms
memory: 7888kb

input:

10
904418845477 67070474418 839309493679 528132965435 512894488193 602880026087 180594485896 804608714469 235337679831 584564033737

output:

15

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%