# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135986 | onjo0127 | Tri (CEOI09_tri) | C++11 | 202 ms | 14284 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define X first
#define Y second
#define sz(V) ((int)V.size())
struct query { int id; pll A, B; };
int CCW(pll A, pll B, pll C) {
long long tmp = A.X*B.Y + B.X*C.Y + C.X*A.Y - A.Y*B.X - B.Y*C.X - C.Y*A.X;
if(tmp < 0LL) return -1;
if(tmp == 0LL) return 0;
if(tmp > 0LL) return +1;
}
bool operator <(pll A, pll B) { return CCW({0, 0}, A, B) == 1; }
bool operator <=(pll A, pll B) { return CCW({0, 0}, A, B) >= 0; }
pll add(pll A, pll B, pll C) {
return {A.X + C.X - B.X, A.Y + C.Y - B.Y};
}
bool chk(vector<pll> &H, pll A, pll B) {
if(B < A) swap(A, B);
bool f = 0;
int l = 0, r = sz(H) - 1;
while(l <= r) {
int m = l+r >> 1;
if(CCW(A, B, H[m]) == 1) f = 1;
if(m+1 == sz(H) || CCW(A, B, add(B, H[m], H[m+1])) == -1) r = m-1;
else l = m+1;
}
return f;
}
pll P[100009];
bool ans[100009];
vector<query> S[300009];
void go(int idx, int s, int e, pll A, pll B, int id) {
if(e < s || B <= P[s] || P[e] <= A) return;
int m = s+e >> 1;
if(A < P[m] && P[m] < B) {
S[idx].push_back({id, A, B});
return;
}
go(idx*2, s, m-1, A, B, id);
go(idx*2+1, m+1, e, A, B, id);
}
void dnc(int idx, int s, int e) {
if(e < s) return;
int m = s+e >> 1;
{
sort(S[idx].begin(), S[idx].end(), [&](query PP, query QQ) { return PP.B < QQ.B; });
vector<pll> H;
int i = m;
for(auto& it: S[idx]) {
while(i <= e && P[i] < it.B) {
while(sz(H) >= 2 && CCW(H[sz(H) - 2], H[sz(H) - 1], P[i]) >= 0) H.pop_back();
H.push_back(P[i]);
++i;
}
ans[it.id] |= chk(H, it.A, it.B);
}
}
{
sort(S[idx].begin(), S[idx].end(), [&](query PP, query QQ) { return QQ.A < PP.A; });
vector<pll> H;
int i = m;
for(auto& it: S[idx]) {
while(i >= s && it.A < P[i]) {
while(sz(H) >= 2 && CCW(H[sz(H) - 2], H[sz(H) - 1], P[i]) <= 0) H.pop_back();
H.push_back(P[i]);
--i;
}
ans[it.id] |= chk(H, it.A, it.B);
}
}
dnc(idx*2, s, m-1);
dnc(idx*2+1, m+1, e);
}
int main() {
int K, M; scanf("%d%d",&K,&M);
for(int i=1; i<=K; i++) scanf("%lld%lld", &P[i].X, &P[i].Y);
sort(P+1, P+K+1, [&](pll PP, pll QQ) { return PP < QQ; });
for(int i=1; i<=M; i++) {
pll A, B; scanf("%lld%lld%lld%lld", &A.X, &A.Y, &B.X, &B.Y);
if(B < A) swap(A, B);
go(1, 1, K, A, B, i);
}
dnc(1, 1, K);
for(int i=1; i<=M; i++) puts(ans[i] ? "Y" : "N");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |