답안 #414183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
414183 2021-05-30T08:38:09 Z hhhhaura 새 집 (APIO18_new_home) C++14
47 / 100
5000 ms 92260 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define INF 2e9
using namespace std;
#define pii pair<int, int>
namespace seg {
	int n;
	vector<int> seg;
	void init_(int _n) {
		n = _n;
		seg.assign(2 * n + 1, INF);
	}
	inline int get(int L, int R) {
		return (L + R) | (L != R);
	}
	void pull(int L, int R) {
		int nd = get(L, R), mid = (L + R) / 2;
		seg[nd] = min(seg[get(L, mid)], seg[get(mid + 1, R)]);
	}
	void modify(int L, int R, int id, int v) {
		int nd = get(L, R), mid = (L + R) / 2;
		if(L == R) seg[nd] = v;
		else {
			if(id <= mid) modify(L, mid, id, v);
			else modify(mid + 1, R, id, v);
			pull(L, R);
		}
	}
	int query(int L, int R, int l, int r) {
		int nd = get(L, R), mid = (L + R) / 2;
		if(l > R || r < L) return INF;
		else if(l <= L && r >= R) return seg[nd];
		else return min(query(L, mid, l, r), query(mid + 1, R, l, r));
	}
	void change(int x, int v) {modify(1, n, x, v);}
	int ask(int x) { return query(1, n, x, n); }
};
namespace solver {
	int n, k, q;
	struct query {
		int x, tp, id;
		bool operator<(query b) {
			if(x != b.x) return x < b.x;
			else return tp < b.tp;
		}
	};
	vector<map<int, int>> s;
	vector<multiset<pii>> cur;
	vector<pii> ans, stores;
	vector<query> qq;
	vector<int> v;
	void init_(int _n, int _k, int _q) {
		n = _n, k = _k, q = _q;
		s.assign(k + 1, map<int, int>());
		cur.assign(n + q + 2, multiset<pii>());
		ans.assign(q + 1, {0, 0});
		stores.assign(n + k + 1, {0, 0});
		qq.clear(), v.clear();
		seg::init_(n + q + 1);	
	}
	void add_store(int id, int l, int tp, int a, int b) {
		stores[id] = {l, tp};
		v.push_back(l);
		qq.push_back({a, 1, id});
		qq.push_back({b + 1, 2, id});
	}
	void add_query(int id, int l, int y) {
		ans[id].first = l;
		v.push_back(l);
		qq.push_back({y, 3, id});
	}
	void update(int x) {
		auto it = cur[x].begin();
		if(it == cur[x].end()) seg::change(x, INF);
		else seg::change(x, it -> first);
	}
	void add(int id) {
		int tp = stores[id].second, l = stores[id].first;
		s[tp][l] ++;
		if(s[tp][l] > 1) return; 
		int pre, nxt = 0;
		auto it1 = s[tp].upper_bound(l);
		auto it2 = s[tp].lower_bound(l);
		if(it2 == s[tp].begin()) pre = 0;
		else pre = prev(it2) -> first;
		if(it1 != s[tp].end()) {
			nxt = it1 -> first;
			cur[nxt].erase(cur[nxt].find({pre, tp}));
			cur[nxt].insert({l, tp});
			update(nxt);
		} 
		cur[l].insert({pre, tp});
		update(l);
	}
	void remove(int id) {
		int tp = stores[id].second, l = stores[id].first;
		s[tp][l] --;
		if(s[tp][l] > 0) return;
		int pre, nxt;
		s[tp].erase(s[tp].find(l));
		auto it1 = s[tp].upper_bound(l);
		auto it2 = s[tp].lower_bound(l);
		if(it2 == s[tp].begin()) pre = 0;
		else pre = prev(it2) -> first;
		if(it1 != s[tp].end()) {
			nxt = it1 -> first;
			cur[nxt].erase(cur[nxt].find({l, tp}));
			cur[nxt].insert({pre, tp});
			update(nxt);
		} 
		cur[l].erase({pre, tp});
		update(l);
	}
	int query(int x) {
		int L = -1, R = 1e9;
		while(R - L > 1) {
			int mid = (L + R) / 2;
			int l = lower_bound(all(v), v[x] - mid) - v.begin();
			int r = upper_bound(all(v), v[x] + mid) - v.begin() - 1;
			int val = seg::ask(r + 1);
			if(val < l) L = mid;
			else R = mid;
		}
		if(R == 1e9) return -1;
		else return R;
	}
	void solve() {
		rep(i, 1, k) add_store(n + i, INF, i, -INF, INF);
		v.push_back(-INF);
		sort(all(v)), v.resize(unique(all(v)) - v.begin());
		rep(i, 1, n + k) stores[i].first = lower_bound(all(v), stores[i].first) - v.begin();
		rep(i, 1, q) ans[i].first = lower_bound(all(v), ans[i].first) - v.begin();
		sort(all(qq));
		for(auto i : qq) {
			if(i.tp == 1) add(i.id); 
			else if(i.tp == 2) remove(i.id);
			else ans[i.id].second = query(ans[i.id].first);
		}
		rep(i, 1, q) cout << ans[i].second << "\n";
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, k, q; cin >> n >> k >> q;
	init_(n, k, q);
	rep(i ,1, n) {
		int x, t, a, b;
		cin >> x >> t >> a >> b;
		add_store(i, x, t, a, b);
	}
	rep(i, 1, q) {
		int l, y; cin >> l >> y;
		add_query(i, l, y);
	}
	solve();
	return 0;

}

Compilation message

new_home.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 4 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 3 ms 412 KB Output is correct
21 Correct 4 ms 460 KB Output is correct
22 Correct 3 ms 460 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 3 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 3 ms 332 KB Output is correct
30 Correct 3 ms 400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 4 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 3 ms 412 KB Output is correct
21 Correct 4 ms 460 KB Output is correct
22 Correct 3 ms 460 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 3 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 3 ms 332 KB Output is correct
30 Correct 3 ms 400 KB Output is correct
31 Correct 897 ms 16520 KB Output is correct
32 Correct 314 ms 11640 KB Output is correct
33 Correct 900 ms 12928 KB Output is correct
34 Correct 832 ms 12972 KB Output is correct
35 Correct 969 ms 16472 KB Output is correct
36 Correct 958 ms 16356 KB Output is correct
37 Correct 826 ms 11648 KB Output is correct
38 Correct 849 ms 11640 KB Output is correct
39 Correct 767 ms 11640 KB Output is correct
40 Correct 783 ms 11640 KB Output is correct
41 Correct 627 ms 11624 KB Output is correct
42 Correct 658 ms 11768 KB Output is correct
43 Correct 358 ms 11640 KB Output is correct
44 Correct 649 ms 11716 KB Output is correct
45 Correct 659 ms 11640 KB Output is correct
46 Correct 697 ms 11640 KB Output is correct
47 Correct 616 ms 11512 KB Output is correct
48 Correct 664 ms 11512 KB Output is correct
49 Correct 643 ms 11512 KB Output is correct
50 Correct 629 ms 11692 KB Output is correct
51 Correct 678 ms 11512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4290 ms 92260 KB Output is correct
2 Execution timed out 5046 ms 78984 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5038 ms 80088 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 4 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 3 ms 412 KB Output is correct
21 Correct 4 ms 460 KB Output is correct
22 Correct 3 ms 460 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 3 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 3 ms 332 KB Output is correct
30 Correct 3 ms 400 KB Output is correct
31 Correct 897 ms 16520 KB Output is correct
32 Correct 314 ms 11640 KB Output is correct
33 Correct 900 ms 12928 KB Output is correct
34 Correct 832 ms 12972 KB Output is correct
35 Correct 969 ms 16472 KB Output is correct
36 Correct 958 ms 16356 KB Output is correct
37 Correct 826 ms 11648 KB Output is correct
38 Correct 849 ms 11640 KB Output is correct
39 Correct 767 ms 11640 KB Output is correct
40 Correct 783 ms 11640 KB Output is correct
41 Correct 627 ms 11624 KB Output is correct
42 Correct 658 ms 11768 KB Output is correct
43 Correct 358 ms 11640 KB Output is correct
44 Correct 649 ms 11716 KB Output is correct
45 Correct 659 ms 11640 KB Output is correct
46 Correct 697 ms 11640 KB Output is correct
47 Correct 616 ms 11512 KB Output is correct
48 Correct 664 ms 11512 KB Output is correct
49 Correct 643 ms 11512 KB Output is correct
50 Correct 629 ms 11692 KB Output is correct
51 Correct 678 ms 11512 KB Output is correct
52 Correct 764 ms 26760 KB Output is correct
53 Correct 720 ms 23140 KB Output is correct
54 Correct 657 ms 19700 KB Output is correct
55 Correct 707 ms 16416 KB Output is correct
56 Correct 716 ms 19100 KB Output is correct
57 Correct 668 ms 12640 KB Output is correct
58 Correct 649 ms 16316 KB Output is correct
59 Correct 646 ms 18924 KB Output is correct
60 Correct 619 ms 12580 KB Output is correct
61 Correct 590 ms 27144 KB Output is correct
62 Correct 786 ms 26944 KB Output is correct
63 Correct 699 ms 20596 KB Output is correct
64 Correct 639 ms 17964 KB Output is correct
65 Correct 598 ms 13204 KB Output is correct
66 Correct 637 ms 11712 KB Output is correct
67 Correct 598 ms 13052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 4 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 3 ms 412 KB Output is correct
21 Correct 4 ms 460 KB Output is correct
22 Correct 3 ms 460 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 3 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 3 ms 332 KB Output is correct
30 Correct 3 ms 400 KB Output is correct
31 Correct 897 ms 16520 KB Output is correct
32 Correct 314 ms 11640 KB Output is correct
33 Correct 900 ms 12928 KB Output is correct
34 Correct 832 ms 12972 KB Output is correct
35 Correct 969 ms 16472 KB Output is correct
36 Correct 958 ms 16356 KB Output is correct
37 Correct 826 ms 11648 KB Output is correct
38 Correct 849 ms 11640 KB Output is correct
39 Correct 767 ms 11640 KB Output is correct
40 Correct 783 ms 11640 KB Output is correct
41 Correct 627 ms 11624 KB Output is correct
42 Correct 658 ms 11768 KB Output is correct
43 Correct 358 ms 11640 KB Output is correct
44 Correct 649 ms 11716 KB Output is correct
45 Correct 659 ms 11640 KB Output is correct
46 Correct 697 ms 11640 KB Output is correct
47 Correct 616 ms 11512 KB Output is correct
48 Correct 664 ms 11512 KB Output is correct
49 Correct 643 ms 11512 KB Output is correct
50 Correct 629 ms 11692 KB Output is correct
51 Correct 678 ms 11512 KB Output is correct
52 Correct 4290 ms 92260 KB Output is correct
53 Execution timed out 5046 ms 78984 KB Time limit exceeded
54 Halted 0 ms 0 KB -