clown__ @ 2023-03-13 19:34:50
#include"iostream"
// #define ls (i<<1)
// #define rs (ls|1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long ll;
const ll N=1e6+10;
ll tree[N<<3],ls[N<<3],rs[N<<3],n,cnt,root,ans;
void add(ll &i,ll l,ll r,ll k)
{
if(i==0) i=++cnt;
tree[i]++;
if(l==r) return ;
else if(k<=mid) add(ls[i],l,mid,k);
else add(rs[i],mid+1,r,k);
}
ll sum(ll &i,ll l,ll r,ll k)
{
if(k<l) return tree[i];
else if(k>=r) return 0;
else return sum(ls[i],l,mid,k)+sum(rs[i],mid+1,r,k);
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)
{
ll x;
cin>>x;
add(root,0,1e9+10,x);
ans+=sum(root,0,1e9+10,x);
}
cout<<ans<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
by ragwort @ 2023-03-13 19:41:59
为什么要用珂爱的线段树
by _zzzzzzy_ @ 2023-03-13 19:42:34
@error_Aumn 估计是数组开的太大了
by ragwort @ 2023-03-13 19:44:20
@error_Aumn
by clown__ @ 2023-03-13 19:45:02
@wind_kaka 专项刷线段树搞到的QAQ
by clown__ @ 2023-03-13 19:46:40
@zhangzhengyan0831 确实是,开大了,QAQ把ll 换成int,只把ans开ll就好了QAQ,感谢您
by clown__ @ 2023-03-13 19:46:54
@wind_kaka 确实是,开大了,QAQ把ll 换成int,只把ans开ll就好了QAQ,感谢您
by ragwort @ 2023-03-13 19:47:28
@error_Aumn 数组开
by clown__ @ 2023-03-13 19:48:14
等下,好像发错题了