Y15BeTa @ 2019-08-07 16:20:49
树状数组
开了longlong
用了读入优化
TLE
50pts
#include<cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#define int long long
using namespace std;
typedef long long ll;
inline void input(ll &x){
ll ans=0,f=1;
char c=getchar();
while(c>'9'||c<'0'){
if(c=='-')f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
ans=ans*10+c-48;
c=getchar();
}
x=ans*f;
}
inline void output(ll x){
if(x<0)x=-x,putchar('-');
if(x>9)output(x/10);
putchar(x%10+48);
}
inline void writeln(ll x){
output(x);
putchar('\n');
}
int a[5000005],b[5000005],c[20000005],n,cnt;
map<int,int> sign;
inline int lowbit(int x){return x&(-x);}
inline void add(int k){
while(k<=n){
c[k]++;
k+=lowbit(k);
}
}
inline int query(int k){
int ans=0;
while(k){
ans+=c[k];
k-=lowbit(k);
}
return ans;
}
signed main(){
input(n);
for(int i=1;i<=n;i++){
input(a[i]);b[i]=a[i];
}
sort(b+1,b+n+1);
for(int i=1;i<=n;i++){
sign[b[i]]=++cnt;
}
int ans=0;
for(int i=n;i>=1;i--){
ans+=query(sign[a[i]]-1);
add(sign[a[i]]);
}
writeln(ans);
}
by 7KByte @ 2019-08-07 16:28:29
sort(b+1,b+n+1);
int T=0,u[500005];
for(int i=1;i<=n;i++){
if(i==1||b[i]^b[i-1])u[++T]=b[i];
}
for(int i=1;i<=T;i++)b[i]=u[i];
by mendessy @ 2019-08-07 16:28:46
你不是汉子吗
by xyf007 @ 2019-08-07 16:28:50
归并排序
by Froshine @ 2019-08-07 16:29:37
@TwxAqu 吸氧 编译器开关 inline 快读 快输 臭氧 register
by Froshine @ 2019-08-07 16:31:51
捞贴
by 由比滨丶雪乃 @ 2019-08-07 16:34:12
QND 萌新 fAKe
哦是妹子啊,那没事了
直接归并不好吗QwQ
by Diaоsi @ 2019-08-07 16:36:14
@TwxAqu 归并排序,,,
by K0stlin @ 2019-08-07 16:38:14
离散化有问题。
for(int i=1;i<=n;i++){
input(a[i]);b[i].x=a[i];b[i].s=a[i];
}
sort(b+1,b+n+1,cmp);
for(int i=1;i<=n;i++){
sign[b[i].x]=++cnt;//改为数组
}
开结构体,cmp按s升序排序。
by K0stlin @ 2019-08-07 16:38:31
希望是对的
by K0stlin @ 2019-08-07 16:39:27
年龄和性别不对是会咕咕咕的