输出一样但WA了
查看原帖
输出一样但WA了
750524
Tmbcan楼主2024/8/7 11:45

第二个测试点本地输出一样,但锣鼓提交WA了

蒟蒻求调

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<climits>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template <typename T>
inline void read(T&x){
	int w=0;x=0;
	char ch = getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') w=1;
		ch = getchar();
	}
	while(ch>='0'&&ch<='9'){
		x = (x<<1)+(x<<3)+(ch^48);
		ch = getchar();
	}
	if(w) x=-x;
}
template <typename T,typename...Args>
inline void read(T&t,Args&...args){
	read(t);read(args...);
}
#define int long long
const int N = 2e4;
int n;
int qty[N+10],sum[N+10],ans;
struct node{
	int v,x;
	const bool operator < (const node &G) const{
		return v < G.v;
	}
}g[N];
#define lowbit(x) (x & -x)
inline void qty_(int x){
	while(x<=N){
		qty[x]++;
		x += lowbit(x);
	}
}
inline void sum_(int x,int v){
	while(x<=N){
		sum[x] += v;
		x += lowbit(x);
	}
}
inline int get_qty(int x){
	int num = 0;
	while(x){
		num += qty[x];
		x -= lowbit(x);
	}
	return num;
}
inline int get_sum(int x){
	int num = 0;
	while(x){
		num += sum[x];
		x -= lowbit(x);
	}
	return num;
}
signed main(){
	
	//freopen("P2345_2.in","r",stdin);
	//freopen("WA.txt","w",stdout);
	
	read(n);
	for(int i=1;i<=n;++i) read(g[i].v,g[i].x);
	sort(g+1,g+1+n);
	for(int i=1;i<=n;++i){
		ans += g[i].v*(get_qty(g[i].x-1)*g[i].x-get_sum(g[i].x-1)+get_sum(N)-get_sum(g[i].x)-(get_qty(N)-get_qty(g[i].x))*g[i].x);
		qty_(g[i].x);
		sum_(g[i].x,g[i].x);		
	} 
	printf("%lld",ans);
	return 0;
}

求调

2024/8/7 11:45
加载中...