Submission #848483

# Submission time Handle Problem Language Result Execution time Memory
848483 2023-09-12T18:38:43 Z lovrot Tri (CEOI09_tri) C++17
0 / 100
120 ms 42172 KB
#include <cstdio> 
#include <cassert>
#include <vector>
#include <algorithm> 

#define X first
#define Y second
#define EB emplace_back

using namespace std;

typedef long long ll;

struct dot {
	ll x, y;
	dot() {}
	dot(ll x, ll y) : x(x), y(y) {}
	bool operator< (dot p) { return (p.x - x) * (-y) - (p.y - y) * (-x) > 0; }
	ll operator* (dot p) { return p.x * x + p.y * y; }
};

ll ccw(dot a, dot b, dot c) { return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); }

const int LOG = 17; 
const int N = 1 << LOG;

dot D[N][2], INV[N];
int L[N], R[N], ANS[N];
vector<int> Q[2 * N], I[N]; 
vector<dot> CH, CIR;

int query(const dot &d) {
	int lo = 0, hi = (int) CH.size() - 1;
	while(hi - lo > 1) {
		int mi = (lo + hi) / 2;
		if(CH[mi] * d < CH[mi + 1] * d) hi = mi;
		else lo = mi;
	}
	return CH[lo] * d < CH[hi] * d ? lo : hi;
}

void divcon(int lo, int hi, int x = 1) {
	assert(x == 1);
	if(lo >= hi || Q[x].empty()) return;
	if(lo + 1 == hi) {
		for(int i : Q[x]) ANS[i] |= ccw(D[i][1], D[i][0], CIR[i]) > 1;
		return;
	}
	int mi = (lo + hi) / 2;
	for(int i : Q[x]) {
		if(L[i] < mi && R[i] < mi) Q[2 * x].EB(i); 
		else if(L[i] >= mi && R[i] >= mi) Q[2 * x + 1].EB(i); 
		else I[L[i]].EB(i), I[R[i]].EB(i); 
	}
	CH.clear();	
	for(int i = mi - 1; i >= lo; --i) {
		dot d = CIR[i]; 
		while(CH.size() > 1 && ccw(end(CH)[-2], end(CH)[-1], d) > 0) CH.pop_back(); 
		CH.EB(d); 
		for(int j : I[i])
			if(ccw(D[j][1], D[j][0], CH[query(INV[j])]) > 0) ANS[j] = 1;
	}
	CH.clear();
	for(int i = mi; i < hi; ++i) {
		dot d = CIR[i]; 
		while(CH.size() > 1 && ccw(end(CH)[-2], end(CH)[-1], d) > 0) CH.pop_back(); 
		CH.EB(d); 
		for(int j : I[i])
			if(ccw(D[j][1], D[j][0], CH[query(INV[j])]) > 0) ANS[j] = 1;
	}
	for(int i = lo; i < hi; ++i) I[i].clear();
	divcon(lo, mi, 2 * x); 
	divcon(mi, hi, 2 * x + 1);
}

int search(const dot &d) {
	int lo = -1, hi = (int) CIR.size();
	while(hi - lo > 1) {
		int mi = (lo + hi) / 2;
		if(CIR[mi] < d) lo = mi;
		else hi = mi;
	}
	return hi;
}
int main() {
	int n, m;
	scanf("%d%d", &n, &m); 
	for(int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y); 
		CIR.EB(dot(x, y)); 
	}
	sort(CIR.begin(), CIR.end()); 
//	for(int i = 0; i < n; ++i) printf("%d %d\n", (int) CIR[i].x, (int) CIR[i].y);
	for(int i = 0; i < m; ++i) {
		int x, y, _x, _y;
		scanf("%d%d%d%d", &x, &y, &_x, &_y); 
		D[i][0] = dot(x, y); 
		D[i][1] = dot(_x, _y); 
		INV[i] = dot(- (D[i][1].y - D[i][0].y), D[i][1].x - D[i][0].x);

		L[i] = search(D[i][1]); 
		R[i] = search(D[i][0]) - 1;
//		printf("%d: %d %d\n", i, L[i], R[i]);
		if(L[i] <= R[i]) Q[1].EB(i);
	}
	divcon(0, n);
	for(int i = 0; i < m; ++i) printf("%c\n", ANS[i] ? 'Y' : 'N');
	return 0;
}

Compilation message

tri.cpp: In function 'int main()':
tri.cpp:87:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
tri.cpp:90:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |   scanf("%d%d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~
tri.cpp:97:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |   scanf("%d%d%d%d", &x, &y, &_x, &_y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 27480 KB Execution killed with signal 6
2 Runtime error 14 ms 27484 KB Execution killed with signal 6
3 Runtime error 47 ms 33736 KB Execution killed with signal 6
4 Runtime error 57 ms 35660 KB Execution killed with signal 6
5 Runtime error 117 ms 40616 KB Execution killed with signal 6
6 Runtime error 96 ms 39348 KB Execution killed with signal 6
7 Runtime error 120 ms 42172 KB Execution killed with signal 6
8 Runtime error 85 ms 36852 KB Execution killed with signal 6
9 Runtime error 97 ms 37824 KB Execution killed with signal 6
10 Runtime error 101 ms 38844 KB Execution killed with signal 6