#include <cstdio> #include <vector> #include <algorithm> #include <stack> using namespace std; bool broken_v[500001]; bool broken_h[500001]; struct line{ int id; // rect id int c; // distance from edge bool start; // is it closer or further from the edge bool operator<(line& otherLine){ return c < otherLine.c; } }; vector<line> hlines; vector<line> vlines; struct layer{ int id; // element on the top int val; // aggregate size int b; // brokens when last aggregated }; stack<layer> layers; int n; int xa, ya, xb, yb, tx, ty; int hmax, vmax; int main(){ scanf("%d %d %d", &n, &tx, &ty); for (int i = 0; i < n; ++i) { line h_s, h_e, v_s, v_e; scanf("%d %d %d %d", &xa, &ya, &xb, &yb); h_s.id = h_e.id = v_s.id = v_e.id = i+1; h_s.start = v_s.start = true; h_e.start = v_e.start = false; if (xa < xb) { h_s.c = xa; h_e.c = xb; } else { h_s.c = xb; h_e.c = xa; } if (ya < yb) { v_s.c = ya; v_e.c = yb; } else { v_s.c = yb; v_e.c = ya; } hlines.push_back(h_s); hlines.push_back(h_e); vlines.push_back(v_s); vlines.push_back(v_e); } line hstart, hend, vstart, vend; hstart.id = hend.id = vstart.id = vend.id = 0; hstart.c = vstart.c = 0; hend.c = tx; vend.c = ty; hstart.start = vstart.start = true; hend.start = vend.start = false; hlines.push_back(hstart); hlines.push_back(hend); vlines.push_back(vstart); vlines.push_back(vend); sort(hlines.begin(), hlines.end()); sort(vlines.begin(), vlines.end()); /* printf("HORIZONTALS:\n"); for(int j = 0; j < 2*(n+1); ++j){ line l = hlines[j]; char c; if(l.start){ c = 's'; } else { c = 'e'; } printf("%d %d %c\n", l.id, l.c, c); } printf("\nVERTICALS:\n"); for(int j = 0; j < 2*(n+1); ++j){ line l = vlines[j]; char c; if(l.start){ c = 's'; } else { c = 'e'; } printf("%d %d %c\n", l.id, l.c, c); } * */ int totalLines = 2*(n+1); stack<layer> hlayers; int brokens = 0; for (int i = 0; i < totalLines - 1; ++i){ line l = hlines[i]; int cur_size = hlines[i+1].c - l.c; if(l.start){ layer r; r.id = l.id; r.val = cur_size; r.b = brokens; hlayers.push(r); } else { broken_h[l.id] = true; brokens++; while(broken_h[hlayers.top().id]){ //layer m = hlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (hlayers.top().val > hmax) { hmax = hlayers.top().val; } hlayers.pop(); brokens--; } if(hlayers.top().b == brokens){ hlayers.top().val += cur_size; } else { //layer m = hlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (hlayers.top().val > hmax) { hmax = hlayers.top().val; } hlayers.top().val = cur_size; hlayers.top().b = brokens; } } } //layer m = hlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (hlayers.top().val > hmax) { hmax = hlayers.top().val; } stack<layer> vlayers; brokens = 0; for (int i = 0; i < totalLines - 1; ++i){ line l = vlines[i]; int cur_size = vlines[i+1].c - l.c; if(l.start){ layer r; r.id = l.id; r.val = cur_size; r.b = brokens; vlayers.push(r); } else { broken_v[l.id] = true; brokens++; while(broken_v[vlayers.top().id]){ //m = vlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (vlayers.top().val > vmax) { vmax = vlayers.top().val; } vlayers.pop(); brokens--; } if(vlayers.top().b == brokens){ vlayers.top().val += cur_size; } else { //m = vlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (vlayers.top().val > vmax) { vmax = vlayers.top().val; } vlayers.top().val = cur_size; vlayers.top().b = brokens; } } } //m = vlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (vlayers.top().val > vmax) { vmax = vlayers.top().val; } long long int g = (long long int)hmax * (long long int)vmax; printf("%lld\n", g); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | #include <cstdio> #include <vector> #include <algorithm> #include <stack> using namespace std; bool broken_v[500001]; bool broken_h[500001]; struct line{ int id; // rect id int c; // distance from edge bool start; // is it closer or further from the edge bool operator<(line& otherLine){ return c < otherLine.c; } }; vector<line> hlines; vector<line> vlines; struct layer{ int id; // element on the top int val; // aggregate size int b; // brokens when last aggregated }; stack<layer> layers; int n; int xa, ya, xb, yb, tx, ty; int hmax, vmax; int main(){ scanf("%d %d %d", &n, &tx, &ty); for (int i = 0; i < n; ++i) { line h_s, h_e, v_s, v_e; scanf("%d %d %d %d", &xa, &ya, &xb, &yb); h_s.id = h_e.id = v_s.id = v_e.id = i+1; h_s.start = v_s.start = true; h_e.start = v_e.start = false; if (xa < xb) { h_s.c = xa; h_e.c = xb; } else { h_s.c = xb; h_e.c = xa; } if (ya < yb) { v_s.c = ya; v_e.c = yb; } else { v_s.c = yb; v_e.c = ya; } hlines.push_back(h_s); hlines.push_back(h_e); vlines.push_back(v_s); vlines.push_back(v_e); } line hstart, hend, vstart, vend; hstart.id = hend.id = vstart.id = vend.id = 0; hstart.c = vstart.c = 0; hend.c = tx; vend.c = ty; hstart.start = vstart.start = true; hend.start = vend.start = false; hlines.push_back(hstart); hlines.push_back(hend); vlines.push_back(vstart); vlines.push_back(vend); sort(hlines.begin(), hlines.end()); sort(vlines.begin(), vlines.end()); /* printf("HORIZONTALS:\n"); for(int j = 0; j < 2*(n+1); ++j){ line l = hlines[j]; char c; if(l.start){ c = 's'; } else { c = 'e'; } printf("%d %d %c\n", l.id, l.c, c); } printf("\nVERTICALS:\n"); for(int j = 0; j < 2*(n+1); ++j){ line l = vlines[j]; char c; if(l.start){ c = 's'; } else { c = 'e'; } printf("%d %d %c\n", l.id, l.c, c); } * */ int totalLines = 2*(n+1); stack<layer> hlayers; int brokens = 0; for (int i = 0; i < totalLines - 1; ++i){ line l = hlines[i]; int cur_size = hlines[i+1].c - l.c; if(l.start){ layer r; r.id = l.id; r.val = cur_size; r.b = brokens; hlayers.push(r); } else { broken_h[l.id] = true; brokens++; while(broken_h[hlayers.top().id]){ //layer m = hlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (hlayers.top().val > hmax) { hmax = hlayers.top().val; } hlayers.pop(); brokens--; } if(hlayers.top().b == brokens){ hlayers.top().val += cur_size; } else { //layer m = hlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (hlayers.top().val > hmax) { hmax = hlayers.top().val; } hlayers.top().val = cur_size; hlayers.top().b = brokens; } } } //layer m = hlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (hlayers.top().val > hmax) { hmax = hlayers.top().val; } stack<layer> vlayers; brokens = 0; for (int i = 0; i < totalLines - 1; ++i){ line l = vlines[i]; int cur_size = vlines[i+1].c - l.c; if(l.start){ layer r; r.id = l.id; r.val = cur_size; r.b = brokens; vlayers.push(r); } else { broken_v[l.id] = true; brokens++; while(broken_v[vlayers.top().id]){ //m = vlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (vlayers.top().val > vmax) { vmax = vlayers.top().val; } vlayers.pop(); brokens--; } if(vlayers.top().b == brokens){ vlayers.top().val += cur_size; } else { //m = vlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (vlayers.top().val > vmax) { vmax = vlayers.top().val; } vlayers.top().val = cur_size; vlayers.top().b = brokens; } } } //m = vlayers.top(); //printf("%d %d %d\n", m.id, m.val, m.b); if (vlayers.top().val > vmax) { vmax = vlayers.top().val; } long long int g = (long long int)hmax * (long long int)vmax; printf("%lld\n", g); return 0; } |