Submission #736151

#TimeUsernameProblemLanguageResultExecution timeMemory
736151marvinthangZvijezda (COCI19_zvijezda)C++17
110 / 110
123 ms8008 KiB
/*************************************
*    author: marvinthang             *
*    created: 05.08.2022 15:46:01    *
*************************************/

#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                 div  ___div
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define             FULL(i)  (MASK(i) - 1)
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#define          file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }

template <class T>             scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class T>            print_op(vector <T>)  { out << '{'; for (size_t i = 0; i + 1 < u.size(); ++i) out << u[i] << ", "; if (!u.empty()) out << u.back(); return out << '}'; }
template <class U, class V>   scan_op(pair <U, V>)  { return in >> u.fi >> u.se; }
template <class U, class V>  print_op(pair <U, V>)  { return out << '(' << u.fi << ", " << u.se << ')'; }

const double PI = 3.1415926535897932384626433832795; // acos(-1.0); atan(-1.0);
const int dir[] = {1, 0, -1, 0, 1, 1, -1, -1, 1}; // {2, 1, -2, -1, -2, 1, 2, -1, 2};
const int MAX = 1e5 + 5;

struct Point {
	long long x, y;
	Point(long long x = 0, long long y = 0): x(x), y(y) {}
	friend scan_op(Point) { return in >> u.x >> u.y; }
};

bool ccw(Point a, Point b, Point c) {
	return (long double) a.x * (b.y - c.y) +
		   (long double) b.x * (c.y - a.y) + 
		   (long double) c.x * (a.y - b.y) >= -1e-9;
}

int N, T, Q;
Point poly[MAX];

void init(void) {
	cin >> T >> N;
	for (int i = 0; i < N; ++i) cin >> poly[i];
}

inline int nxt(int i) { return (i + 1) % N; }

int countOne(bool parity, int left, int right, Point p) {
	int l = left, r = right;
	while (l <= r) {
		int m = l + r >> 1;
		if (ccw(poly[m], poly[nxt(m)], p) == parity) l = m + 1;
		else r = m - 1;
	}
	return parity ? r - left + 1 : right - r;
}

void process(void) {
	int cnt = 0;
	cin >> Q;
	while (Q--) {
		Point p; cin >> p;
		p.x ^= 1LL * T * cnt * cnt * cnt;
		p.y ^= 1LL * T * cnt * cnt * cnt;
		bool res = false;
		bool a = ccw(poly[0], poly[nxt(0)], p);
		bool b = ccw(poly[N / 2], poly[nxt(N / 2)], p);
		if (a == b) res = a;
		else res = countOne(a, 0, N / 2 - 1, p) + countOne(b, N / 2, N - 1, p) > N / 2;
		cout << (res ? "DA" : "NE") << '\n';
		cnt += res;
	}
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr);
	file("coci1920_r2_zvijezda");
	init();
	process();
	// cerr << "Time elapsed: " << TIME << " s.\n";
	return (0^0);
}

Compilation message (stderr)

zvijezda.cpp: In function 'int countOne(bool, int, int, Point)':
zvijezda.cpp:58:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |   int m = l + r >> 1;
      |           ~~^~~
zvijezda.cpp: In function 'int main()':
zvijezda.cpp:22:69: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 | #define          file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                             ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
zvijezda.cpp:84:2: note: in expansion of macro 'file'
   84 |  file("coci1920_r2_zvijezda");
      |  ^~~~
zvijezda.cpp:22:103: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 | #define          file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                               ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
zvijezda.cpp:84:2: note: in expansion of macro 'file'
   84 |  file("coci1920_r2_zvijezda");
      |  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...