QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#132348 | #6626. Real Mountains | AFewSuns | 0 | 8ms | 34456kb | C++14 | 2.8kb | 2023-07-29 17:05:48 | 2023-07-29 17:05:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
set<ll> s1,s2;
vector<ll> vec[1000010];
ll n,a[1000010],lsh[1000010],cnt=0,pre[1000010],suf[1000010],st[1000010],top=0,ans=0;
int main(){
n=read();
fr(i,1,n) lsh[++cnt]=a[i]=read();
sort(lsh+1,lsh+cnt+1);
cnt=unique(lsh+1,lsh+cnt+1)-lsh-1;
fr(i,1,n) vec[lower_bound(lsh+1,lsh+cnt+1,a[i])-lsh].push_back(i);
fr(i,1,cnt) sort(vec[i].begin(),vec[i].end());
pfr(i,cnt,1){
pfr(j,(ll)vec[i].size()-1,0){
ll pos=vec[i][j];
while(top&&pos<st[top]) top--;
pre[pos]=st[top];
st[++top]=pos;
}
}
top=0;
st[top]=n+1;
pfr(i,cnt,1){
fr(j,0,(ll)vec[i].size()-1){
ll pos=vec[i][j];
while(top&&pos>st[top]) top--;
suf[pos]=st[top];
st[++top]=pos;
}
}
fr(i,1,n) s2.insert(i);
fr(i,1,cnt){
fr(j,0,(ll)vec[i].size()-1){
s1.insert(vec[i][j]);
s2.erase(vec[i][j]);
}
ll l=n+1,r=0;
if(!s2.empty()){
l=*s2.begin();
r=*(--s2.end());
}
while(!s1.empty()&&(*s1.begin())<=l) s1.erase(*s1.begin());
while(!s1.empty()&&(*(--s1.end()))>=r) s1.erase(*(--s1.end()));
if(s1.empty()) continue;
l=*s1.begin();
r=*(--s1.end());
ll siz=s1.size();
if(siz==1){
ans+=(a[pre[l]]+a[suf[l]])*(lsh[i+1]-lsh[i]);
ans+=(lsh[i]+lsh[i+1]-1)*(lsh[i+1]-lsh[i])/2;
continue;
}
else if((pre[l]+suf[l]+suf[r])<=(pre[l]+pre[r]+suf[r])){
ans+=(pre[l]+suf[l]+suf[r]+2*siz-3)*(lsh[i+1]-lsh[i]);
ans+=(3*siz-3)*(lsh[i]+lsh[i+1]-1)*(lsh[i+1]-lsh[i])/2;
}
else{
ans+=(pre[l]+pre[r]+suf[r]+2*siz-3)*(lsh[i+1]-lsh[i]);
ans+=(3*siz-3)*(lsh[i]+lsh[i+1]-1)*(lsh[i+1]-lsh[i])/2;
}
}
write(ans);
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 3ms
memory: 34300kb
input:
3 29 9 9
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 34456kb
input:
3 62 20 71
output:
7287
result:
ok 1 number(s): "7287"
Test #3:
score: -3
Wrong Answer
time: 8ms
memory: 33624kb
input:
10 72 33 22 22 13 49 53 57 72 85
output:
32244
result:
wrong answer 1st numbers differ - expected: '40403', found: '32244'
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%