Submission #474210

# Submission time Handle Problem Language Result Execution time Memory
474210 2021-09-17T11:31:52 Z nonsensenonsense1 New Home (APIO18_new_home) C++17
0 / 100
282 ms 40064 KB
#include <cstdio>
#include <set>
#include <algorithm>

const int N = 300000;

struct data {
	int x, t, tm;
	bool open;
	bool operator<(data arg) {
		return tm < arg.tm;
	}
} s[N << 1];

struct query {
	int x, tm, ind;
	bool operator<(query arg) {
		return tm < arg.tm;
	}
} q[N];

int n, k, m, size, ans[N];

int main() 
{
	scanf("%d%d%d", &n, &k, &m);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d%d%d", &s[i << 1].x, &s[i << 1].t, &s[i << 1].tm, &s[i << 1 | 1].tm);
		s[i << 1 | 1].x = s[i << 1].x;
		s[i << 1 | 1].t = --s[i << 1].t;
		s[i << 1].open = true;
		s[i << 1 | 1].open = false;
		--s[i << 1].tm;
	}
	std::sort(s, s + (n << 1));
	for (int i = 0; i < m; ++i) {
		scanf("%d%d", &q[i].x, &q[i].tm);
		q[i].ind = i;
		--q[i].tm;
	}
	std::sort(q, q + m);
	std::multiset<int> cur[5];
	std::multiset<int>::iterator it;
	for (int i = 0, j = 0; i < m; ++i) {
		while (j < n << 1 && s[j].tm <= q[i].tm) {
			if (s[j].open) cur[s[j].t].insert(s[j].x);
			else cur[s[j].t].erase(cur[s[j].t].find(s[j].x));
			++j;
		}
		for (int j = 0; j < k; ++j) {
			it = cur[j].lower_bound(q[i].x);
			int dist = ~(1 << 31);
			if (it != cur[j].end()) dist = std::min(dist, *it - q[i].x);
			if (it != cur[j].begin()) dist = std::min(dist, q[i].x - *prev(it));
			ans[q[i].ind] = std::max(ans[q[i].ind], dist);
		}
	}
	for (int i = 0; i < m; ++i) {
		if (ans[i] == ~(1 << 31)) printf("-1\n");
		else printf("%d\n", ans[i]);
	}
	return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  scanf("%d%d%d", &n, &k, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   scanf("%d%d%d%d", &s[i << 1].x, &s[i << 1].t, &s[i << 1].tm, &s[i << 1 | 1].tm);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d%d", &q[i].x, &q[i].tm);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 360 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 360 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 265 ms 40064 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 282 ms 39480 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 360 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 360 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -