QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#114217 | #6626. Real Mountains | ruizhangj | 0 | 2ms | 6120kb | C++14 | 1.9kb | 2023-06-21 15:46:24 | 2023-06-21 15:46:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
int a[N],n,p=-1;
map<int,pair<vector<int>,vector<int>>> b;
int tr[4*N];
void build(int x,int l,int r){
if (l==r){
tr[x]=a[l];
return;
}
int mid=(l+r)>>1;
build(x<<1,l,mid);
build(x<<1|1,mid+1,r);
tr[x]=min(tr[x<<1],tr[x<<1|1]);
}
int query(int x,int l,int r,int L,int R){
if (L<=l && r<=R) return tr[x];
int mid=(l+r)>>1;
if (R<=mid) return query(x<<1,l,mid,L,R);
if (L>mid) return query(x<<1|1,mid+1,r,L,R);
return min(query(x<<1,l,mid,L,R),query(x<<1|1,mid+1,r,L,R));
}
void modify(int x,int l,int r,int p,int v){
if (l==r){
tr[x]=v;
return;
}
int mid=(l+r)>>1;
if (p<=mid) modify(x<<1,l,mid,p,v);
else modify(x<<1|1,mid+1,r,p,v);
tr[x]=min(tr[x<<1],tr[x<<1|1]);
}
set<int> s;
int main(){
// freopen("a.in","r",stdin);
scanf("%d",&n);
for (int i=1;i<=n;++i){
scanf("%d",&a[i]);
if (p==-1 || a[i]>a[p]) p=i;
b[a[i]].first.emplace_back(i);
}
for (int i=1,mx=0;i<=p;++i){
mx=max(mx,a[i]);
b[mx].second.emplace_back(i);
}
for (int i=n,mx=0;i>p;--i){
mx=max(mx,a[i]);
b[mx].second.emplace_back(i);
}
build(1,1,n);
ll ans=0;
for (auto it=b.begin();it!=b.end();++it){
auto obj=*it;
ll h=obj.first;
for (auto x:obj.second.first) s.emplace(x);
for (auto x:obj.second.second) s.erase(x),modify(1,1,n,x,1e9);
if (next(it)==b.end()) break;
ll v=next(it)->first;
if (!s.size()) continue;
ll x=query(1,1,n,1,*s.begin()-1),y=query(1,1,n,*prev(s.end())+1,n);
if (s.size()==1) ans+=(v-h)*(x+y)+(h+v-1)*(v-h)/2;
else ans+=(v-h)*(max(x,y)+2*min(x,y)+1+2*(s.size()-2))+(3+3*(s.size()-2))*(h+v-1)*(v-h)/2;
}
printf("%lld\n",ans);
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 2ms
memory: 5672kb
input:
3 29 9 9
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5788kb
input:
3 62 20 71
output:
7287
result:
ok 1 number(s): "7287"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5740kb
input:
10 72 33 22 22 13 49 53 57 72 85
output:
40403
result:
ok 1 number(s): "40403"
Test #4:
score: -3
Wrong Answer
time: 1ms
memory: 6120kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 97 97 97 97 9...
output:
49481200
result:
wrong answer 1st numbers differ - expected: '481053', found: '49481200'
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%