QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#118145#6626. Real Mountainsxtqqwq#0 4ms35448kbC++142.4kb2023-07-03 09:17:502024-05-31 18:48:47

Judging History

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

  • [2024-05-31 18:48:47]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:35448kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-03 09:17:50]
  • 提交

answer

#include<bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int cys=1000003;
int n,m;
ll a[1000005],pre[1000005],suf[1000005],p[1000005],mina[2200000],to[1000005];
vector<ll> vec[1000005];

ll f(int x){return 1ll*x*(x+1)/2;}

void build(int id,int l,int r){
	if(l==r) return (void)(mina[id]=a[l]);
	int mid=(l+r)/2;
	build(id<<1,l,mid);
	build(id<<1|1,mid+1,r);
	mina[id]=min(mina[id<<1],mina[id<<1|1]);
}

void change(int id,int l,int r,int x){
	if(l==r) return (void)(mina[id]=1ll<<60);
	int mid=(l+r)/2;
	if(x<=mid) change(id<<1,l,mid,x);
	else change(id<<1|1,mid+1,r,x);
	mina[id]=min(mina[id<<1],mina[id<<1|1]);
}

ll query(int id,int l,int r,int ql,int qr){
	if(ql>qr) return 1ll<<60;
	if(l==ql&&r==qr) return mina[id];
	int mid=(l+r)/2;
	if(qr<=mid) return query(id<<1,l,mid,ql,qr);
	else if(ql>mid) return query(id<<1|1,mid+1,r,ql,qr);
	else return min(query(id<<1,l,mid,ql,mid),query(id<<1|1,mid+1,r,mid+1,qr));
}

int main(){
	n=readint();
	for(int i=1;i<=n;i++) a[i]=readint();
	for(int i=1;i<=n;i++) pre[i]=max(pre[i-1],a[i]);
	for(int i=n;i>=1;i--) suf[i]=max(suf[i+1],a[i]);
	for(int i=1;i<=n;i++) to[i]=min(pre[i],suf[i]);
	for(int i=1;i<=n;i++) p[i]=a[i];
	sort(p+1,p+n+1);
	m=unique(p+1,p+n+1)-p-1;
	for(int i=1;i<=n;i++) a[i]=lower_bound(p+1,p+n+1,a[i])-p;
	for(int i=1;i<=n;i++) vec[a[i]].pb(i);
	set<int> st;
	build(1,1,n);
	ll ans=0;
	for(int i=1;i<=m;i++){
		for(auto r:vec[i]) st.insert(r),change(1,1,n,r);
		while(st.size()&&to[*st.begin()]==p[i]) st.erase(st.begin());
		while(st.size()&&to[*(--st.end())]==p[i]) st.erase(--st.end());
		if(!st.size()) continue;
		int L=*st.begin(),R=*(--st.end());
		ll lmin=query(1,1,n,1,L-1);
		ll tmin=query(1,1,n,L+1,R-1);
		ll rmin=query(1,1,n,R+1,n);
		ans+=(p[i+1]-p[i])*(lmin+rmin+min(lmin,min(tmin,rmin)))+(f(p[i+1]-1)-f(p[i]-1))*(3*st.size()-3)+(p[i+1]-p[i])*(2*st.size()-3);
	}
	printf("%lld\n",ans%cys);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 4ms
memory: 34908kb

input:

3
29 9 9

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Wrong Answer
time: 3ms
memory: 35448kb

input:

3
62 20 71

output:

252

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%