CCPC-Wannafly & Comet OJ joy summer season (2019) F

Face questions

 

F friendlier (compared to E), we found that if i and j are two subscripts satisfy the conditions, then:

a[i]-2*b[i] + a[j]-2*b[j] >=0 或者 b[i]-2*a[i] + b[j]-2*a[j] >=0。

 

And because both conditions can not be established at the same time (you left inequality left full expression to the right to try), so we can count two cases separately and finally the answer together. . . (In fact, in both cases it is symmetrical, so you can use a function to solve directly between two calls to all a [] and b [] swap it Jiuhaola)

In each case, we might as well put a small mark next to the right shift key, and then found that this is a simple two-dimensional partial order wrong with me, Fenwick tree easily over w

 

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int ha=1e9+7,N=1e5+5;

int a[N],b[N],c[N],n,m,f[N*2];
int p[N][2],num[N*2],ky,ans;

inline int add(int x,int y){ x+=y; return x>=ha?x-ha:x;}
inline void ADD(int &x,int y){ x+=y; if(x>=ha) x-=ha;}

inline int read(){
    int x=0; char ch=getchar();
    for(;!isdigit(ch);ch=getchar());
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
    return x;
}

inline void update(int x,int y){
	for(;x<=ky;x+=x&-x) ADD(f[x],y);
}

inline int query(int x){
	int an=0;
	for(;x;x-=x&-x) ADD(an,f[x]);
	return an;
}

inline void solve(){
	memset(f,0,sizeof(f)),ky=0;
	
	for(int i=1;i<=n;i++){
		p[i][0]=a[i]-2*b[i],p[i][1]=-p[i][0];
		num[++ky]=p[i][0],num[++ky]=p[i][1];
	}
	
	sort(num+1,num+ky+1),ky=unique(num+1,num+ky+1)-num-1;
	
	for(int i=1;i<=n;i++)
	    for(int j=0;j<2;j++) p[i][j]=lower_bound(num+1,num+ky+1,p[i][j])-num;
	
	for(int i=1;i<=n;i++) update(p[i][1],c[i]),ADD(ans,c[i]*(ll)query(p[i][0])%ha);
}

int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=read(),b[i]=read(),c[i]=read();
	
	solve();
	for(int i=1;i<=n;i++) swap(a[i],b[i]);
	solve();
	
	printf("%d\n",ans);
	return 0;
}

  

Guess you like

Origin www.cnblogs.com/JYYHH/p/11265788.html