寒冰大大 @ 2019-09-12 20:13:11
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#define lson i<<1,l,mid
#define rson i<<1|1,mid+1,r
#define ls i<<1
#define rs i<<1|1
using namespace std;
int n,a[500500],b[500500];
long long s;
struct tree{
int sum;
}t[2002000];
struct orztree{
inline void pushup(int i)
{
t[i].sum=t[ls].sum+t[rs].sum;
}
void change_tree(int i,int l,int r,int x)
{
if(l==r&&l==x)
{
t[i].sum++;
return ;
}
int mid=(l+r)>>1;
if(x<=mid) change_tree(lson,x);
else change_tree(rson,x);
pushup(i);
}
int ask_sum_tree(int i,int l,int r,int x,int y)
{
if(x>y) return 0;
if(l>=x&&r<=y) return t[i].sum;
int mid=(l+r)>>1;
int ans=0;
if(x<=mid) ans+=ask_sum_tree(lson,x,y);
if(y>mid) ans+=ask_sum_tree(rson,x,y);
return ans;
}
}st;
inline int getplace(int tar)
{
register int mid,l=1,r=n;
while(l<=r)
{
mid=(l+r)>>1;
if(a[mid]<tar) l=mid+1;
if(a[mid]>tar) r=mid-1;
if(a[mid]==tar) return mid;
}
}
int main()
{
register int i,j;
ios::sync_with_stdio(false);
cin>>n;
for(i=1;i<=n;i++) cin>>a[i],b[i]=a[i];
sort(a+1,a+n+1);
for(i=1;i<=n;i++) b[i]=getplace(b[i]);
for(i=n;i>=1;i--) s+=st.ask_sum_tree(1,1,n,1,b[i]-1),st.change_tree(1,1,n,b[i]);
cout<<s;
return 0;
}
https://www.luogu.org/record/23881334
by NaCly_Fish @ 2019-09-12 20:14:30
@寒冰大大 复杂度都是
by Reaepita @ 2019-09-12 20:17:18
@寒冰大大 这是啥操作啊,用线段树写黄题%%%
by 寒冰大大 @ 2019-09-12 20:17:20
@NaCly_Fish 一般来说线段树极限在3*1e5 左右吧 50万还可以就有点毒瘤了吧
by Reaepita @ 2019-09-12 20:18:49
@寒冰大大 线段树1e6都可以过
by EternalAlexander @ 2019-09-12 20:19:42
线段树咋就只能跑3e5了...
by NaCly_Fish @ 2019-09-12 20:20:44
@EternalAlexander orzylhtql
by skydogli @ 2019-09-12 20:25:15
@寒冰大大 哥,3e5是分块极限(光速逃
by muyang_233 @ 2019-09-12 20:29:09
orz lhy tql deco最阔耐
by 冷梦233 @ 2019-09-12 20:30:35
@寒冰大大 线段树什么时候只能跑3e5了?我学了假的线段树?
by Null_Cat @ 2019-09-12 20:41:01
@冷梦233 线段树常数太大(