Codeforces 1221 F Choose a Square

Face questions

 

    Bigwigs do not know how to think, anyway, I saw this interval contains only the nature and score and included a section of questions linked with the interrogation zone, immediately thought of the scan line 23333

    Although the revolution direction very correct, but because SB wrong to pay five times before A.

    WA first hair: Taking into account if we scan line is to coordinate discrete, but this practice is the default has at least one point in the square. All rights are negative points can be embarrassing, and this time need to find an empty spot to replace the answers to zero. While I consider this situation, but the first time point is not only written Zhaokong trouble (I is num [i] +1 <num [i + 1] to determine whether there is a gap between the two coordinates), and behind the biggest leak of coordinates. . . . But if you look at the problem surface description carefully, you will find the output requirements of the coordinates is> 1e9, which is the pit ratio between these questions, the answer is <0 can directly output 0 \ n 1000000001 1000000001 1000000001 1000000001 up. .

    WA Second hair: I drive a vector subscript after discrete coordinates, apparently to open twice as much space, forgot to open. . .

    WA third issue: the coordinates discovered after the index segment tree is also discrete, obviously space is to open n eight times, wori

    WA fourth rounds: operating segment tree when there is a long long int the written, gan

 

#include <. bits / STDC H ++> 
#define LL Long Long 
the using namespace STD; 
#define LC (O <<. 1) 
#define MID (L + R & lt >>. 1) 
#define RC ((O <<. 1) |. 1 ) 
#define Pb push_back 
const int N = 500 005; 

inline int Read () { 
	int X = 0, F =. 1; char CH = getchar (); 
	for (;! isdigit (CH); CH = getchar ()) IF ( == CH '-') F = -1; 
	for (; isdigit (CH); CH = getchar ()) * 10 + X X = CH-'0 '; 
	return F * X; 
} 

/ * 
    NOTE array space ah ! 
	Although only n points, but relates to the 2n discrete coordinate values after a maximum of 
	G [i] is used to keep the right end of the list of point i, 2n open space so that 
	an indexing segment tree is the order of the discrete coordinates, so space to open 8n instead of 4N 
* / 

Vector <int> G [N * 2]; 
int n-, A [N], B [N], NUM [N * 2], KY, C [N], L, R & lt, POS [N *. 8], W, Le =. 1, RI, P; 
LL = -1e18 ANS, MX [N *. 8],

inline void maintain(int o){
	pos[o]=mx[rc]>mx[lc]?pos[rc]:pos[lc];
	mx[o]=max(mx[lc],mx[rc]);
}

inline void Get(int o,ll w){
	ad[o]+=w,mx[o]+=w;
}

inline void pushdown(int o){
	if(ad[o]) Get(lc,ad[o]),Get(rc,ad[o]),ad[o]=0;
}

void build(int o,int l,int r){
	if(l==r){ pos[o]=mx[o]=num[l]; return;}
	build(lc,l,mid),build(rc,mid+1,r);
	maintain(o);
}

void update(int o,int l,int r){
	if(l>=le&&r<=ri){ Get(o,w); return;}
	
	pushdown(o);
	
	if(le<=mid) update(lc,l,mid);
	if(ri>mid) update(rc,mid+1,r);
	
	maintain(o);
}

void query(int o,int l,int r){
	IF (L> = Le && R & lt <= RI) {IF (MX [O]> MX [P]) P = O; return;} 
	// P after the query is the largest segment tree nodes need to switch to a specific number axis point 
	pushdown (O); 
	
	IF (Le <= MID) Query (LC, L, MID); 
	IF (RI> MID) Query (RC, MID +. 1, R & lt); 
} 

inline void Solve () { 
	Build (1,1, KY), MX [0] = - 1e18; 
	for (int I =. 1; I <= KY; I ++) { 
		for (int J: G [I]) A RI = [J], W = C [J], Update (1,1, KY); 
		P = 0, RI = I, Query (1,1, KY); 
		IF (MX [P] -num [I]> ANS) MX ANS = [P ] -num [I], R & lt NUM = [I], L POS = [P]; 
	} 
} 

int main () { 
	n-= Read (), NUM [0] = -. 1; 
	for (int I =. 1; I <= n-; I ++) { 
	    A [I] = Read (), B [I] = Read (), C [I] = Read (); 
		[KY ++] = A [I] NUM, NUM [++ KY] = B [I]; 
		IF (A [I]> B [I]) the swap (A [I], B [I]); 
	}
	
	sort(num+1,num+ky+1),ky=unique(num+1,num+ky+1)-num-1;
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(num+1,num+ky+1,a[i])-num;
		b[i]=lower_bound(num+1,num+ky+1,b[i])-num;
		g[b[i]].pb(i);
	}
	
	solve();
	if(ans<=0) ans=0,L=R=1e9+1;
	
	cout<<ans<<endl;
	printf("%d %d %d %d\n",L,L,R,R);
	
	return 0;
}

/*
    Σc[] + j - i 
*/

  

Guess you like

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