思维误区:扫描线
扫描线模板里面有两个变量一个是 c o v e r 和 l e n g t h cover和length cover和length
- c o v e r cover cover是标记下面是否覆盖满了,但是 c o v e r cover cover等于 0 0 0也有可能覆盖满的
- 所以只能通过 l e n g t h length length去判断
代码:
#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define sfx(x) scanf("%lf",&x)
#define sfxy(x,y) scanf("%lf%lf",&x,&y)
#define sdx(x) scanf("%d",&x)
#define sdxy(x,y) scanf("%d%d",&x,&y)
#define pfx(x) printf("%.0f\n",x)
#define pfxy(x,y) printf("%.6f %.6f\n",x,y)
#define pdx(x) printf("%d\n",x)
#define pdxy(x,y) printf("%d %d\n",x,y)
#define _for(i,a,b) for( int i = (a); i < (b); ++i)
#define _rep(i,a,b) for( int i = (a); i <= (b); ++i)
#define for_(i,a,b) for( int i = (a); i >= (b); -- i)
#define rep_(i,a,b) for( int i = (a); i > (b); -- i)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define hash Hash
#define next Next
#define f first
#define s second
using namespace std;
const int N = 5e5, eps = 1e-10;
typedef long long LL;
typedef unsigned long long ULL;
int n, d;
struct ScanLine {
int x;
int upy, downy;
int inout;
bool operator < (const ScanLine & t) const {
return x < t.x;
}
ScanLine(){}
ScanLine(int x, int y1, int y2, int oi):x(x),upy(y1),downy(y2),inout(oi){}
}line[N << 3];
struct Node {
int cover;
int length;
}tr[N << 3];
inline void pushup(int rt, int l, int r)
{
if(tr[rt].cover) tr[rt].length = r - l;
else if(l + 1 == r) tr[rt].length = 0;
else tr[rt].length = tr[rt << 1].length + tr[rt << 1|1].length;
}
inline void update(int rt, int l, int r, int posl, int posr, int io)
{
if(posl <= l && posr >= r)
{
tr[rt].cover += io;
pushup(rt,l,r);
return;
}
if(l + 1 == r) return;
if(posl <= mid)
update(rt << 1,l,mid,posl,posr,io);
if(posr > mid)
update(rt << 1|1,mid,r,posl,posr,io);
pushup(rt,l,r);
return;
}
inline int ask(int rt, int l, int r) {
if(l + 1 == r) return l;
if(tr[rt << 1].length != mid - l) return ask(rt << 1,l,mid);
else return ask(rt<<1|1,mid,r);
}
int main()
{
scanf("%d%d",&n,&d);
int cnt = 0;
_for(i,0,n)
{
int x1, y1, x2, y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int x1mod = (x1%(d)+(d))%(d);
int x2mod = (x2%(d)+(d))%(d);
int y1mod = (y1%(d)+(d))%(d);
int y2mod = (y2%(d)+(d))%(d);
if(x2 - x1 >= d && y2 - y1 >= d) {
printf("NO");
return 0;
} else {
int epsx = (x1mod - x1);
int epsy = (y1mod - y1);
line[++ cnt] = ScanLine(x1mod, min(d,y2 + epsy), y1mod, 1);
line[++ cnt] = ScanLine(min(d,x2 + epsx), min(d,y2 + epsy), y1mod, -1);
epsx = (x2mod - x2);
epsy = (y2mod - y2);
if(x2mod != 0 && y2mod != 0) {
line[++ cnt] = ScanLine(max(0,x1+epsx), y2mod, max(0,y1+epsy), 1);
line[++ cnt] = ScanLine(x2mod, y2mod, max(0,y1+epsy), -1);
}
epsx = (x1mod - x1);
epsy = (y2mod - y2);
if(y2mod != 0) {
line[++ cnt] = ScanLine(x1mod, y2mod, max(0,y1+epsy), 1);
line[++ cnt] = ScanLine(min(d,x2+epsx), y2mod, max(0,y1+epsy), -1);
}
epsx = (x2mod - x2);
epsy = (y1mod - y1);
if(x2mod != 0) {
line[++ cnt] = ScanLine(max(0,x1+epsx), min(d,y2 + epsy), y1mod, 1);
line[++ cnt] = ScanLine(x2mod, min(d,y2 + epsy), y1mod, -1);
}
}
}
// cout << cnt <<endl;
sort(line + 1,line + cnt + 1);
int i = 1;
_for(j,0,d+1)
{
if(j == d) {
printf("NO");
return 0;
}
int b = 0;
while(i+b <= cnt && line[i+b].x == j) {
update(1,1,d+1,line[i+b].downy+1,line[i+b].upy+1,line[i+b].inout);
b ++;
}
i = b + i;
if(tr[1].length != d) {
printf("YES\n");
printf("%d %d",j,ask(1,1,d+1)-1);
return 0;
}
}
return 0;
}
/*
3 5
-1 -1 1 1
0 3 2 5
0 2 1 3
*/