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
| #include <bits/stdc++.h> #define int long long #define maxn 800005 #define lson(x) (x << 1) #define rson(x) (x << 1) + 1 #define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std; int n, d;
template<typename T> void Print(T value){ std::cout << value << '\n'; } template<typename Head, typename... Rail> void Print(Head head, Rail... rail){ std::cout << head << ", "; Print(rail...); } int read(){ int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') ch == '-' ? f = -1, ch = getchar() : ch = getchar(); while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * f; }
struct Line { int x, y1, y2; int mark; bool operator < (const Line &A){ return x < A.x;; } }; struct SegTree { int lf, rt; int len; int lazy; } tree[maxn]; void Build(int now, int lf, int rt) { tree[now].lf = lf; tree[now].rt = rt; tree[now].len = 0; if(lf == rt) return; int mid = (lf + rt) >> 1; Build(lson(now), lf, mid); Build(rson(now), mid + 1, rt); } void Pushdown(int now) { if(tree[now].lazy != 0) { tree[lson(now)].len += tree[now].lazy; tree[rson(now)].len += tree[now].lazy; tree[lson(now)].lazy += tree[now].lazy; tree[rson(now)].lazy += tree[now].lazy; tree[now].lazy = 0; } } void Update(int now, int L, int R, int v) { int nowlf = tree[now].lf, nowrt = tree[now].rt; if(nowlf >= L && nowrt <= R) { tree[now].len += v; tree[now].lazy += v; return; } Pushdown(now); int mid = (nowlf + nowrt) >> 1; if(L <= mid) Update(lson(now), L, R, v); if(R > mid) Update(rson(now), L, R, v); tree[now].len = min(tree[lson(now)].len, tree[rson(now)].len); } int ask(int now, int L, int R) { if(tree[now].lf >= L && tree[now].rt <= R) { return tree[now].len; } Pushdown(now); int mid = (tree[now].lf + tree[now].rt) >> 1; int res = (1LL << 30); if(L <= mid) res = min(res, ask(lson(now), L, R)); if(R > mid) res = min(res, ask(rson(now), L, R)); return res; } vector<Line> SL[maxn]; void add(int x1, int y1, int x2, int y2) { SL[x1].push_back({x1, y1, y2, 1}); SL[x2 + 1].push_back({x2 + 1, y1, y2, -1}); } signed main() { IO; cin >> n >> d; for(int i = 1; i <= n; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; x2--, y2--; if(x2 - x1 + 1 >= d) x1 = 0, x2 = d - 1; if(y2 - y1 + 1 >= d) y1 = 0, y2 = d - 1; x1 = (x1 % d + d) % d, x2 = (x2 % d + d) % d, y1 = (y1 % d + d) % d, y2 = (y2 % d + d) % d; if(x2 >= x1) { if(y2 >= y1) { add(x1, y1, x2, y2); } else { add(x1, y1, x2 ,d - 1); add(x1, 0, x2 ,y2); } } else { if(y2 >= y1) { add(x1, y1, d - 1, y2); add(0, y1, x2, y2); } else { add(x1, y1, d - 1, d - 1); add(0, y1, x2, d - 1); add(x1, 0, d - 1, y2); add(0, 0, x2, y2); } } } Build(1, 0, d - 1); int ansx = -1, ansy = -1; for(int i = 0; i < d; i++) { if(ansx != -1) break; for(auto l : SL[i]) { Update(1, l.y1, l.y2, l.mark); } if(ask(1, 0, d - 1) == 0) { for(int j = 0; j <= d - 1; j++) { if(ask(1, j, j) == 0) { ansx = i, ansy = j; break; } } } } if(ansx != -1) { cout << "YES\n"; cout << ansx << " " << ansy << endl; } else { cout << "NO\n"; } return 0; }
|