yupeishan2012 @ 2024-10-11 19:28:47
#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[100005],b[100005],c[100005];
long long ans;
inline void read(register long long &a){
a = 0;
char c;
while((c = getchar()) < 48);
do a = (a << 3) + (a << 1) + (c ^ 48);
while((c = getchar()) > 47);
}
void write(register long long v){
if(v < 10) putchar(v|48);
else write(v / 10),putchar(v % 10 | 48);
}
long long cmp(long long j,long long k){
if(a[j] == a[k]) return j > k;
return a[j] > a[k];
}
long long lowbit(int k){
return k & -k;
}
void x(long long k){
while(k <= n){
b[k] ++;
k += lowbit(k);
}
return ;
}
long long sum;
long long y(int k){
sum = 0;
while(k >= 1){
sum += b[k];
k -= lowbit(k);
}
return sum;
}
int main(){
read(n);
for(long long i = 1; i <= n; i++){
read(a[i]);
c[i] = i;
}
sort(c + 1,c + 1 + n,cmp);
for(long long i = 1; i <= n; i++){
x(c[i]);
ans += y(c[i] - 1);
}
write(ans);
return 0;
}
by ggpw_XNW @ 2024-10-11 19:58:12
@yupeishan2012 因为你的答案是负数
by yupeishan2012 @ 2024-10-11 19:58:15
@YAOhc2012 就是结构体改好之后吗
by yupeishan2012 @ 2024-10-11 19:58:51
但我改的结构体样例都过不了
by yupeishan2012 @ 2024-10-11 19:59:57
@User1025109 不 是0
by YAOhc2012 @ 2024-10-11 20:00:53
@yupeishan2012 代码发出来
by ggpw_XNW @ 2024-10-11 20:01:07
@yupeishan2012 代码发出来
by yupeishan2012 @ 2024-10-11 20:02:33
#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[100005],b[100005],c[100005];
long long ans;
inline void read(register long long &a){
a = 0;
char c;
while((c = getchar()) < 48);
do a = (a << 3) + (a << 1) + (c ^ 48);
while((c = getchar()) > 47);
}
void write(register long long v){
if(v < 10) putchar(v|48);
else write(v / 10),putchar(v % 10 | 48);
}
long long cmp(long long j,long long k){
if(a[j] == a[k]) return j > k;
return a[j] > a[k];
}
long long lowbit(int k){
return k & -k;
}
void x(long long k){
while(k <= n){
b[k] ++;
k += lowbit(k);
}
return ;
}
long long sum;
long long y(int k){
sum = 0;
while(k >= 1){
sum += b[k];
k -= lowbit(k);
}
return sum;
}
int main(){
read(n);
for(long long i = 1; i <= n; i++){
read(a[i]);
c[i] = i;
}
sort(c + 1,c + 1 + n,cmp);
for(long long i = 1; i <= n; i++){
x(c[i]);
ans += y(c[i] - 1);
}
write(ans);
return 0;
}
by yupeishan2012 @ 2024-10-11 20:02:56
别嘲讽我 我知道我很菜
by ggpw_XNW @ 2024-10-11 20:04:27
@yupeishan2012 RE?是不是数组开小了
by yupeishan2012 @ 2024-10-11 20:04:56
不对 发错了