Link: https: //codeforces.com/problemset/problem/1284/D
The meaning of problems: there are n lectures, there are two sites a and b, if the site is open talks in a need to occupy [SAI, EAI], lectures need to occupy the space in the b [sbi, ebi] this time, if the open two sessions, if a site does not open in the conflict, and b venues open conflict, claimed it as sensitive, empathy and a and b and vice versa, if the two are ab conflict is not a sensitive, seek first n lectures given any pairwise whether to open sensitive.
Ideas: violence enumeration is O (n ^ 2) complexity, will time-out, where you can use ST segment tree or table to do, achieve a complexity of nlogn. For any x lectures, seminars and find all sites x lecture in a conflict, then it is determined whether the conflict in site B, if not directly output "NO"
Interval after the first all lectures sa and ea ascending, such as a time slice lecture i is [x, y], in its time slice and i lecture a space conflict with the method of two points can be enumerated a discretization then we sb maximum and minimum maintenance b eb site with tree line, every check out this section
Sb maximum and minimum values of eb, at this time if the maximum sb> y or the minimum value eb <x, then the presence of these performances must be b i and performing space does not conflict, then direct output "NO", the All lectures will check it again, and then check the order ab exchange to the test only in a certain field of conflict in the b field of conflict situations, but not in the b field conflict is not a conflict in a venue to consider the situation.
The overall time complexity nlogn.
AC Code:
1 #include<iostream> 2 #include<vector> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<algorithm> 6 #include<cmath> 7 #include<cstring> 8 #include<queue> 9 #include<map> 10 using namespace std; 11 typedef long long ll; 12 const int maxn = 1e5+200; 13 struct node{ 14 int sa,ea,sb,eb; 15 node(){}; 16 node(int a,int b,int c,int d){ 17 sa = a,ea = b,sb = c,eb = d; 18 } 19 bool operator<(node cur)const{ 20 if(sa == cur.sa ) return ea<cur.ea ; 21 return sa < cur.sa ; 22 } 23 }point[maxn]; 24 int segt_max[4*maxn],segt_min[4*maxn]; 25 void build(intL, int R & lt, int K) { // build two segment tree maximum and minimum maintenance interval 26 is IF (L == R & lt) { 27 segt_max [K] = Point [L] .sb; 28 segt_min [K] = Point [L] .eb; 29 return ; 30 } 31 is int MID = (L + R & lt) / 2 ; 32 Build (L, MID, 2 * K); 33 is Build (MID + . 1 , R & lt, 2 * K + . 1 ); 34 is segt_max [K] = max (segt_max [ 2 * K], segt_max [ 2* K + . 1 ]); 35 segt_min [K] = min (segt_min [ 2 * K], segt_min [ 2 * K + . 1 ]); 36 } 37 [ int queryMin ( int L, int R & lt, int Al, int Ar, int K ) { // query minimum interval 38 is IF (L> = R & lt && Al <= Ar) return segt_min [K]; 39 int MID = (L + R & lt) / 2 ; 40 IF (Ar <= MID) return queryMin ( L, MID, Al, Ar, 2 * K); 41 is else if(al>mid){ 42 return queryMin(mid+1,r,al,ar,2*k+1); 43 } 44 else { 45 return min(queryMin(l,mid,al,mid,2*k),queryMin(mid+1,r,mid+1,ar,2*k+1)); 46 } 47 } 48 int queryMax(int l,int r,int al,int ar,int k){//查询区间最大值 49 if(l >= al && r <= ar) return segt_max[k]; 50 int mid = (l+r)/2; 51 if(ar<=mid) return queryMax(l,mid,al,ar,2*k); 52 else if(al>mid){ 53 return queryMax(mid+1,r,al,ar,2*k+1); 54 } 55 else { 56 return max(queryMax(l,mid,al,mid,2*k),queryMax(mid+1,r,mid+1,ar,2*k+1)); 57 } 58 } 59 bool check(int n){ 60 sort(point+1,point+1+n); 61 build(1,n,1); 62 for(int i = 1;i<=n;i++){ 63 int pos = lower_bound(point+1,point+1+n,node(point[i].ea ,1e9+5000,0,0))-point-1; 64 // Find the i-th set of speeches conflict 65 IF (i + 1 > POS) the Continue ; // no conflict skip 66 // the Check to see if all the other performance venues are conflict 67 IF (queryMin ( 1 , n-, I + . 1 , POS, . 1 ) <Point [I] .sb queryMax || ( . 1 , n-, I + . 1 , POS, . 1 )> Point [I] .eb) { 68 return to false ; 69 } 70 } 71 is return to true ; 72 } 73 is int main() 74 { 75 int n; 76 cin>>n; 77 int f = 0; 78 for(int i = 1;i<=n;i++){ 79 cin>>point[i].sa>>point[i].ea>>point[i].sb>>point[i].eb; 80 } 81 if(check(n)) f++; 82 for(int i = 1;i<=n;i++){ 83 swap(point[i].sa,point[i].sb); 84 swap(point[i].ea,point[i].eb); 85 } 86 if(check(n)) f++; 87 if(f == 2) cout<<"YES"; 88 else cout<<"NO"; 89 return 0; 90 }