记录编号 |
582488 |
评测结果 |
AAAAAAAAAA |
题目名称 |
楼兰图腾 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.212 s |
提交时间 |
2023-09-14 17:15:04 |
内存使用 |
7.44 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
typedef long long ll;
ll n,s1,s2;
ll a[N],c[N];
struct made{
ll lmax,rmax;
ll lmin,rmin;
#define lmax(x) ans[x].lmax
#define rmax(x) ans[x].rmax
#define lmin(x) ans[x].lmin
#define rmin(x) ans[x].rmin
}ans[N];
void add(ll x,ll z){
while(x <= n){
c[x] += z;
x += x&-x;
}
return;
}
ll ask(ll x){
ll ans = 0;
while(x > 0){
ans += c[x];
x -= x&-x;
}
return ans;
}
int main(){
freopen("totem.in","r",stdin);
freopen("totem.out","w",stdout);
scanf("%lld",&n);
for(ll i = 1;i <= n;i++)
scanf("%lld",&a[i]);
for(ll i = 1;i <= n;i++){
lmax(i) = ask(n-a[i]);
add(n+1-a[i],1);
}
memset(c,0,sizeof(c));
for(ll i = n;i >= 1;i--){
rmax(i) = ask(n-a[i]);
add(n+1-a[i],1);
}
memset(c,0,sizeof(c));
for(ll i = 1;i <= n;i++){
lmin(i) = ask(a[i]-1);
add(a[i],1);
}
memset(c,0,sizeof(c));
for(int i = n;i >= 1;i--){
rmin(i) = ask(a[i]-1);
add(a[i],1);
}
for(int i = 1;i <= n;i++){
s1 += lmax(i) * rmax(i);
s2 += lmin(i) * rmin(i);
}
printf("%lld %lld\n",s1,s2);
return 0;
}