답안 #414181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
414181 2021-05-30T08:35:29 Z hhhhaura 새 집 (APIO18_new_home) C++14
47 / 100
5000 ms 127936 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 ceil(a, b) ((a + b - 1) / (b))
#define all(x) x.begin(), x.end()

#define INF 1e10
#define MOD 1000000007
#define eps (1e-9)

using namespace std;

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
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)
      | 
new_home.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
new_home.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
# 결과 실행 시간 메모리 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 460 KB Output is correct
6 Correct 4 ms 456 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 4 ms 476 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 5 ms 460 KB Output is correct
13 Correct 4 ms 480 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
15 Correct 4 ms 460 KB Output is correct
16 Correct 4 ms 460 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 4 ms 460 KB Output is correct
23 Correct 4 ms 460 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 3 ms 448 KB Output is correct
28 Correct 5 ms 460 KB Output is correct
29 Correct 3 ms 460 KB Output is correct
30 Correct 3 ms 460 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 460 KB Output is correct
6 Correct 4 ms 456 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 4 ms 476 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 5 ms 460 KB Output is correct
13 Correct 4 ms 480 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
15 Correct 4 ms 460 KB Output is correct
16 Correct 4 ms 460 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 4 ms 460 KB Output is correct
23 Correct 4 ms 460 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 3 ms 448 KB Output is correct
28 Correct 5 ms 460 KB Output is correct
29 Correct 3 ms 460 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 1037 ms 23680 KB Output is correct
32 Correct 326 ms 18164 KB Output is correct
33 Correct 1083 ms 18812 KB Output is correct
34 Correct 946 ms 18972 KB Output is correct
35 Correct 1045 ms 23604 KB Output is correct
36 Correct 1080 ms 23540 KB Output is correct
37 Correct 882 ms 18164 KB Output is correct
38 Correct 912 ms 18164 KB Output is correct
39 Correct 776 ms 18148 KB Output is correct
40 Correct 816 ms 18156 KB Output is correct
41 Correct 670 ms 18180 KB Output is correct
42 Correct 646 ms 18172 KB Output is correct
43 Correct 379 ms 18164 KB Output is correct
44 Correct 700 ms 18236 KB Output is correct
45 Correct 690 ms 18164 KB Output is correct
46 Correct 738 ms 18224 KB Output is correct
47 Correct 610 ms 18036 KB Output is correct
48 Correct 639 ms 17900 KB Output is correct
49 Correct 676 ms 18036 KB Output is correct
50 Correct 627 ms 18144 KB Output is correct
51 Correct 741 ms 18028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4609 ms 127936 KB Output is correct
2 Execution timed out 5059 ms 110680 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5097 ms 112124 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 460 KB Output is correct
6 Correct 4 ms 456 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 4 ms 476 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 5 ms 460 KB Output is correct
13 Correct 4 ms 480 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
15 Correct 4 ms 460 KB Output is correct
16 Correct 4 ms 460 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 4 ms 460 KB Output is correct
23 Correct 4 ms 460 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 3 ms 448 KB Output is correct
28 Correct 5 ms 460 KB Output is correct
29 Correct 3 ms 460 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 1037 ms 23680 KB Output is correct
32 Correct 326 ms 18164 KB Output is correct
33 Correct 1083 ms 18812 KB Output is correct
34 Correct 946 ms 18972 KB Output is correct
35 Correct 1045 ms 23604 KB Output is correct
36 Correct 1080 ms 23540 KB Output is correct
37 Correct 882 ms 18164 KB Output is correct
38 Correct 912 ms 18164 KB Output is correct
39 Correct 776 ms 18148 KB Output is correct
40 Correct 816 ms 18156 KB Output is correct
41 Correct 670 ms 18180 KB Output is correct
42 Correct 646 ms 18172 KB Output is correct
43 Correct 379 ms 18164 KB Output is correct
44 Correct 700 ms 18236 KB Output is correct
45 Correct 690 ms 18164 KB Output is correct
46 Correct 738 ms 18224 KB Output is correct
47 Correct 610 ms 18036 KB Output is correct
48 Correct 639 ms 17900 KB Output is correct
49 Correct 676 ms 18036 KB Output is correct
50 Correct 627 ms 18144 KB Output is correct
51 Correct 741 ms 18028 KB Output is correct
52 Correct 853 ms 37056 KB Output is correct
53 Correct 814 ms 32364 KB Output is correct
54 Correct 738 ms 27392 KB Output is correct
55 Correct 773 ms 22912 KB Output is correct
56 Correct 795 ms 26600 KB Output is correct
57 Correct 720 ms 17836 KB Output is correct
58 Correct 716 ms 22784 KB Output is correct
59 Correct 736 ms 26340 KB Output is correct
60 Correct 730 ms 17780 KB Output is correct
61 Correct 582 ms 37476 KB Output is correct
62 Correct 876 ms 37332 KB Output is correct
63 Correct 819 ms 28720 KB Output is correct
64 Correct 723 ms 25124 KB Output is correct
65 Correct 674 ms 18536 KB Output is correct
66 Correct 674 ms 17464 KB Output is correct
67 Correct 559 ms 18536 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 460 KB Output is correct
6 Correct 4 ms 456 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 4 ms 476 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 5 ms 460 KB Output is correct
13 Correct 4 ms 480 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
15 Correct 4 ms 460 KB Output is correct
16 Correct 4 ms 460 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 4 ms 460 KB Output is correct
23 Correct 4 ms 460 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 3 ms 448 KB Output is correct
28 Correct 5 ms 460 KB Output is correct
29 Correct 3 ms 460 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 1037 ms 23680 KB Output is correct
32 Correct 326 ms 18164 KB Output is correct
33 Correct 1083 ms 18812 KB Output is correct
34 Correct 946 ms 18972 KB Output is correct
35 Correct 1045 ms 23604 KB Output is correct
36 Correct 1080 ms 23540 KB Output is correct
37 Correct 882 ms 18164 KB Output is correct
38 Correct 912 ms 18164 KB Output is correct
39 Correct 776 ms 18148 KB Output is correct
40 Correct 816 ms 18156 KB Output is correct
41 Correct 670 ms 18180 KB Output is correct
42 Correct 646 ms 18172 KB Output is correct
43 Correct 379 ms 18164 KB Output is correct
44 Correct 700 ms 18236 KB Output is correct
45 Correct 690 ms 18164 KB Output is correct
46 Correct 738 ms 18224 KB Output is correct
47 Correct 610 ms 18036 KB Output is correct
48 Correct 639 ms 17900 KB Output is correct
49 Correct 676 ms 18036 KB Output is correct
50 Correct 627 ms 18144 KB Output is correct
51 Correct 741 ms 18028 KB Output is correct
52 Correct 4609 ms 127936 KB Output is correct
53 Execution timed out 5059 ms 110680 KB Time limit exceeded
54 Halted 0 ms 0 KB -