QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#121313 | #6626. Real Mountains | lmeowdn | 0 | 4ms | 38412kb | C++14 | 3.5kb | 2023-07-07 22:24:24 | 2023-07-07 22:24:26 |
Judging History
answer
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
return x*w;
}
const int N=1e6+5,inf=0x3f3f3f3f3f3f3f3f;
int n,a[N],b[N],c,s[N],t[N],ans,rt[N];
vi p[N];
struct priority_deque {
int del[N],sz;
priority_queue<int,vi,greater<int>> q1;
priority_queue<int> q2;
int front() {
while(!q1.empty()) {
int u=q1.top();
if(!del[u]) return u;
else q1.pop();
} return -1;
}
int back() {
while(!q2.empty()) {
int u=q2.top();
if(!del[u]) return u;
else q2.pop();
} return -1;
}
void erase(int x) {del[x]=1, --sz;}
void insert(int x) {q1.push(x),q2.push(x),++sz;}
int size() {return sz;}
} Q;
namespace SegT {
int ls[N<<1],rs[N<<1],s[N<<1],tot=1;
void build(int p,int l,int r) {
if(l==r) {s[p]=a[l]; return;} int mid=l+r>>1;
build(ls[p]=++tot,l,mid), build(rs[p]=++tot,mid+1,r);
s[p]=min(s[ls[p]],s[rs[p]]);
}
void del(int p,int l,int r,int x) {
if(l==r) {s[p]=inf; return;} int mid=l+r>>1;
if(x<=mid) del(ls[p],l,mid,x); else del(rs[p],mid+1,r,x);
s[p]=min(s[ls[p]],s[rs[p]]);
}
int qry(int p,int l,int r,int x,int y) {
if(l==x&&r==y) return s[p]; int mid=l+r>>1;
if(y<=mid) return qry(ls[p],l,mid,x,mid);
else if(x>mid) return qry(rs[p],mid+1,r,mid+1,y);
else return min(qry(ls[p],l,mid,x,mid),qry(rs[p],mid+1,r,mid+1,y));
}
}
int sum(int x,int y) {return (x+y)*(y-x+1)/2;}
signed main() {
n=read();
rep(i,1,n) a[i]=read(), b[i]=a[i];
sort(b+1,b+n+1); c=unique(b+1,b+n+1)-b-1;
rep(i,1,n) {
int x=lower_bound(b+1,b+c+1,a[i])-b;
p[x].eb(i);
}
SegT::build(1,1,n);
rep(i,1,n) s[i]=max(s[i-1],a[i]);
per(i,n,1) t[i]=max(t[i+1],a[i]);
rep(u,1,c-1) {
int x=b[u], y=b[u+1];
for(int i:p[u]) Q.insert(i);
while(Q.size()) {
int i=Q.front();
if(s[Q.front()]<=x) Q.erase(i);
else break;
}
while(Q.size()) {
int i=Q.back();
if(t[i]<=x) Q.erase(i);
else break;
}
int m=Q.size();
for(int i:p[u]) SegT::del(1,1,n,i);
if(m>=1) {
int l=Q.front(), r=Q.back();
int A=SegT::qry(1,1,n,1,l-1);
int B=SegT::qry(1,1,n,r+1,n);
if(m==1) ans+=sum(x,y-1)+(A+B)*(y-x);
else ans+=m*sum(x,y-1)+(m-2)*2*sum(x+1,y)+(A+B+2*y)*(y-x);
}
}
printf("%lld\n",ans);
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 1ms
memory: 38404kb
input:
3 29 9 9
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 4ms
memory: 38412kb
input:
3 62 20 71
output:
7287
result:
ok 1 number(s): "7287"
Test #3:
score: -3
Wrong Answer
time: 0ms
memory: 36392kb
input:
10 72 33 22 22 13 49 53 57 72 85
output:
40695
result:
wrong answer 1st numbers differ - expected: '40403', found: '40695'
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%