QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#138242 | #6626. Real Mountains | blackyuki# | 0 | 2ms | 4136kb | C++14 | 2.0kb | 2023-08-11 10:53:07 | 2024-07-04 01:36:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define pb emplace_back
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
const ll inf=1001001001001001001;
int main(){
ll n,ans=0;cin>>n;
vi v(n);rep(i,n)cin>>v[i];
vi srt=v;dupli(srt);
vvi g(srt.size());
rep(i,n)g[lb(srt,v[i])].pb(i);
P rng(1,n-2);
set<ll> idx;
rep(i,srt.size()-1){
ll x=srt[i],y=srt[i+1];
while(rng.fi<=rng.se&&v[rng.fi-1]<=max(x,v[rng.fi])){
idx.erase(rng.fi);
chmax(v[rng.fi],x);
rng.fi++;
}
while(rng.fi<=rng.se&&v[rng.se+1]<=max(x,v[rng.se])){
idx.erase(rng.se);
chmax(v[rng.se],x);
rng.se--;
}
// cout<<x<<' '<<rng.fi<<' '<<rng.se<<endl;
if(rng.fi>rng.se)break;
for(ll j:g[i])if(rng.fi<=j&&j<=rng.se){
idx.insert(j);
}
ll cnt=idx.size();
if(cnt==0)continue;
ll s1=y-x,s2=(x+y-1)*(y-x)/2;
ll l=inf,r=inf;
ll a=*idx.begin(),b;
auto itr=idx.end();itr--;b=*itr;
rep(j,a)if(v[j]>x)chmin(l,v[j]);
REP(j,b+1,n)if(v[j]>x)chmin(r,v[j]);
if(cnt==1){
ans+=(l+r)*s1+s2;
}
if(cnt>=2){
ans+=(2*cnt-3+l+r+y)*s1+(2*cnt-3+cnt)*s2;
}
}
out(ans);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 0ms
memory: 3584kb
input:
3 29 9 9
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
3 62 20 71
output:
7287
result:
ok 1 number(s): "7287"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3580kb
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: 2ms
memory: 4136kb
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%