QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#113737 | #6626. Real Mountains | 1kri# | 0 | 1ms | 5816kb | C++14 | 1.3kb | 2023-06-19 09:22:19 | 2024-05-31 14:06:14 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define inf 2000000000
#define mod 1000003
using namespace std;
int n,h[1000005];
int p,_h[1000005];
int qwq[1000005];
ll ans;
int gs(int l,int r){
return 1ll*(l+r)*(r-l+1)/2%mod;
}
int main(){
cin>>n;
for (int i=1;i<=n;i++)scanf("%d",&h[i]);
for (int i=1;i<=n;i++)
if (p==0||h[i]>h[p])p=i;
for (int i=1;i<=p;i++)_h[i]=max(h[i],_h[i-1]);
for (int i=n;i>=p;i--)_h[i]=max(h[i],_h[i+1]);
for (int i=1;i<=n;i++)qwq[i]=h[i];
sort(qwq+1,qwq+1+n);
for (int t=1;t<n;t++){
if (qwq[t]==qwq[t+1])continue;
int mn=qwq[t],nxt=qwq[t+1],l=-1,r=-1,cnt=0;
for (int i=1;i<=n;i++)
if (h[i]!=_h[i]&&h[i]==mn){
if (l==-1)l=i;
r=i;
cnt++;
}
if (cnt==0)continue;
int vl=inf,vr=inf,xl=inf,xr=inf;
for (int i=1;i<l;i++)
if (h[i]>mn)vl=min(vl,h[i]);
for (int i=l+1;i<=n;i++)
if (h[i]>mn)xl=min(xl,h[i]);
for (int i=n;i>r;i--)
if (h[i]>mn)vr=min(vr,h[i]);
for (int i=r-1;i>=1;i--)
if (h[i]>mn)xr=min(xr,h[i]);
if (l==r){
ans=(ans+gs(mn,nxt-1)+1ll*(nxt-mn)*(vl+vr))%mod;
h[l]=nxt;
continue;
}
ans=(ans+1ll*(nxt-mn)*(1ll+vl+vr+min(xl,xr))+2ll*(cnt-2)+3ll*(cnt-1)*gs(mn,nxt-1))%mod;
for (int i=1;i<=n;i++)
if (h[i]!=_h[i]&&h[i]==mn)h[i]=nxt;
}
cout<<ans<<endl;
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 1ms
memory: 5780kb
input:
3 29 9 9
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
3 62 20 71
output:
7287
result:
ok 1 number(s): "7287"
Test #3:
score: -3
Wrong Answer
time: 1ms
memory: 5816kb
input:
10 72 33 22 22 13 49 53 57 72 85
output:
40141
result:
wrong answer 1st numbers differ - expected: '40403', found: '40141'
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%