Submission #826123

# Submission time Handle Problem Language Result Execution time Memory
826123 2023-08-15T10:32:57 Z model_code Curtains (NOI23_curtains) C++17
100 / 100
750 ms 88028 KB
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
typedef pair<int,int> ii;

const int MAXN = 500005;
const int inf = (1<<24);

vector<int> toRight[MAXN];
vector<int> toLeft[MAXN];
int closest[MAXN];

struct query{ int l, r, id; };
int ans[MAXN];

void dnc(int s, int e, vector<query> queries){
	if(queries.empty()) return;
	if(s == e){
		bool can = false;
		for(int x : toRight[s]) if(x == e) can = true;
		for(query q : queries) ans[q.id] = can;
		return;
	}
	int m = (s+e)/2;
	
	vector<ii> mono;
	for(int i = m;i >= s;i--){
		int beforeR = -1;
		int afterR = inf;
		for(int r : toRight[i]){
			if(r > e) continue;
			if(r >= m) afterR = min(afterR, r);
			else beforeR = max(beforeR, r);
		}
		
		closest[i] = inf;
		if(afterR != inf) closest[i] = min(closest[i], afterR);
		while(not mono.empty()){
			ii t = mono.back();
			if(t.first <= beforeR+1 or closest[i] <= t.second){
				mono.pop_back();
				closest[i] = min(closest[i], t.second);
			}
			else break;
		}
		mono.push_back(ii(i,closest[i]));
	}
	
	mono.clear();
	for(int i = m+1;i <= e;i++){
		int beforeL = inf;
		int afterL = -1;
		for(int l : toLeft[i]){
			if(l < s) continue;
			if(l <= m+1) afterL = max(afterL, l);
			else beforeL = min(beforeL, l);
		}
		
		closest[i] = -1;
		if(afterL <= m+1) closest[i] = max(closest[i], afterL);
		while(not mono.empty()){
			ii t = mono.back();
			if(beforeL-1 <= t.first or closest[i] >= t.second){
				mono.pop_back();
				closest[i] = max(closest[i], t.second);
			}
			else break;
		}
		mono.push_back(ii(i,closest[i]));
	}
	
	vector<query> leftqueries, rightqueries, now;
	for(query q : queries){
		if(q.r <= m) leftqueries.push_back(q);
		else if(q.l >= m+1) rightqueries.push_back(q);
		else{
			 ans[q.id] = (closest[q.l] <= q.r and closest[q.r] >= q.l);
		}
	}
	
	//if(s == 5 and e == 8) show2(closest[6], closest[8]);
	
	dnc(s, m, leftqueries);
	dnc(m+1, e, rightqueries);
	
	
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    
	int n, m, q; cin >> n >> m >> q;
	
	for(int i = 1;i <= m;i++){
		int l, r; cin >> l >> r;
		toRight[l].push_back(r);
		toLeft[r].push_back(l);
	}
	
	vector<query> queries;
	for(int i = 1;i <= q;i++){
		int l, r; cin >> l >> r;
		queries.push_back({l,r,i});
	}
	
	dnc(1,n,queries);
	
	for(int i = 1;i <= q;i++){
		if(ans[i]) cout << "YES\n";
		else cout << "NO\n";
	}
}


# Verdict Execution time Memory Grader output
1 Correct 13 ms 23772 KB Output is correct
2 Correct 15 ms 23820 KB Output is correct
3 Correct 14 ms 23736 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 16 ms 23764 KB Output is correct
7 Correct 15 ms 23776 KB Output is correct
8 Correct 15 ms 23784 KB Output is correct
9 Correct 16 ms 23748 KB Output is correct
10 Correct 14 ms 23820 KB Output is correct
11 Correct 16 ms 23792 KB Output is correct
12 Correct 14 ms 23724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23772 KB Output is correct
2 Correct 15 ms 23820 KB Output is correct
3 Correct 14 ms 23736 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 16 ms 23764 KB Output is correct
7 Correct 15 ms 23776 KB Output is correct
8 Correct 15 ms 23784 KB Output is correct
9 Correct 16 ms 23748 KB Output is correct
10 Correct 14 ms 23820 KB Output is correct
11 Correct 16 ms 23792 KB Output is correct
12 Correct 14 ms 23724 KB Output is correct
13 Correct 18 ms 23996 KB Output is correct
14 Correct 15 ms 23892 KB Output is correct
15 Correct 18 ms 23892 KB Output is correct
16 Correct 14 ms 24020 KB Output is correct
17 Correct 18 ms 24000 KB Output is correct
18 Correct 18 ms 24020 KB Output is correct
19 Correct 14 ms 24020 KB Output is correct
20 Correct 15 ms 24092 KB Output is correct
21 Correct 18 ms 24020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23772 KB Output is correct
2 Correct 15 ms 23820 KB Output is correct
3 Correct 14 ms 23736 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 16 ms 23764 KB Output is correct
7 Correct 15 ms 23776 KB Output is correct
8 Correct 15 ms 23784 KB Output is correct
9 Correct 16 ms 23748 KB Output is correct
10 Correct 14 ms 23820 KB Output is correct
11 Correct 16 ms 23792 KB Output is correct
12 Correct 14 ms 23724 KB Output is correct
13 Correct 18 ms 23996 KB Output is correct
14 Correct 15 ms 23892 KB Output is correct
15 Correct 18 ms 23892 KB Output is correct
16 Correct 14 ms 24020 KB Output is correct
17 Correct 18 ms 24000 KB Output is correct
18 Correct 18 ms 24020 KB Output is correct
19 Correct 14 ms 24020 KB Output is correct
20 Correct 15 ms 24092 KB Output is correct
21 Correct 18 ms 24020 KB Output is correct
22 Correct 107 ms 43636 KB Output is correct
23 Correct 98 ms 43592 KB Output is correct
24 Correct 119 ms 44832 KB Output is correct
25 Correct 182 ms 49864 KB Output is correct
26 Correct 98 ms 43568 KB Output is correct
27 Correct 219 ms 49920 KB Output is correct
28 Correct 233 ms 49896 KB Output is correct
29 Correct 134 ms 57152 KB Output is correct
30 Correct 89 ms 49396 KB Output is correct
31 Correct 96 ms 50124 KB Output is correct
32 Correct 215 ms 55564 KB Output is correct
33 Correct 91 ms 49504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 16 ms 23816 KB Output is correct
3 Correct 13 ms 23828 KB Output is correct
4 Correct 12 ms 23844 KB Output is correct
5 Correct 17 ms 24000 KB Output is correct
6 Correct 14 ms 24020 KB Output is correct
7 Correct 18 ms 24020 KB Output is correct
8 Correct 90 ms 49456 KB Output is correct
9 Correct 97 ms 50104 KB Output is correct
10 Correct 172 ms 55676 KB Output is correct
11 Correct 104 ms 49584 KB Output is correct
12 Correct 88 ms 32920 KB Output is correct
13 Correct 102 ms 32952 KB Output is correct
14 Correct 91 ms 33316 KB Output is correct
15 Correct 90 ms 32848 KB Output is correct
16 Correct 92 ms 33316 KB Output is correct
17 Correct 102 ms 32840 KB Output is correct
18 Correct 468 ms 69216 KB Output is correct
19 Correct 492 ms 69176 KB Output is correct
20 Correct 488 ms 70928 KB Output is correct
21 Correct 475 ms 70196 KB Output is correct
22 Correct 452 ms 69280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23772 KB Output is correct
2 Correct 15 ms 23820 KB Output is correct
3 Correct 14 ms 23736 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 16 ms 23764 KB Output is correct
7 Correct 15 ms 23776 KB Output is correct
8 Correct 15 ms 23784 KB Output is correct
9 Correct 16 ms 23748 KB Output is correct
10 Correct 14 ms 23820 KB Output is correct
11 Correct 16 ms 23792 KB Output is correct
12 Correct 14 ms 23724 KB Output is correct
13 Correct 18 ms 23996 KB Output is correct
14 Correct 15 ms 23892 KB Output is correct
15 Correct 18 ms 23892 KB Output is correct
16 Correct 14 ms 24020 KB Output is correct
17 Correct 18 ms 24000 KB Output is correct
18 Correct 18 ms 24020 KB Output is correct
19 Correct 14 ms 24020 KB Output is correct
20 Correct 15 ms 24092 KB Output is correct
21 Correct 18 ms 24020 KB Output is correct
22 Correct 54 ms 29492 KB Output is correct
23 Correct 64 ms 29500 KB Output is correct
24 Correct 84 ms 31860 KB Output is correct
25 Correct 89 ms 31888 KB Output is correct
26 Correct 104 ms 36016 KB Output is correct
27 Correct 98 ms 36276 KB Output is correct
28 Correct 86 ms 33192 KB Output is correct
29 Correct 76 ms 35340 KB Output is correct
30 Correct 88 ms 31940 KB Output is correct
31 Correct 83 ms 31980 KB Output is correct
32 Correct 111 ms 33452 KB Output is correct
33 Correct 130 ms 34544 KB Output is correct
34 Correct 85 ms 35292 KB Output is correct
35 Correct 74 ms 33328 KB Output is correct
36 Correct 77 ms 33364 KB Output is correct
37 Correct 67 ms 32924 KB Output is correct
38 Correct 69 ms 32844 KB Output is correct
39 Correct 67 ms 33220 KB Output is correct
40 Correct 66 ms 32836 KB Output is correct
41 Correct 89 ms 33252 KB Output is correct
42 Correct 75 ms 32856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23772 KB Output is correct
2 Correct 15 ms 23820 KB Output is correct
3 Correct 14 ms 23736 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 16 ms 23764 KB Output is correct
7 Correct 15 ms 23776 KB Output is correct
8 Correct 15 ms 23784 KB Output is correct
9 Correct 16 ms 23748 KB Output is correct
10 Correct 14 ms 23820 KB Output is correct
11 Correct 16 ms 23792 KB Output is correct
12 Correct 14 ms 23724 KB Output is correct
13 Correct 18 ms 23996 KB Output is correct
14 Correct 15 ms 23892 KB Output is correct
15 Correct 18 ms 23892 KB Output is correct
16 Correct 14 ms 24020 KB Output is correct
17 Correct 18 ms 24000 KB Output is correct
18 Correct 18 ms 24020 KB Output is correct
19 Correct 14 ms 24020 KB Output is correct
20 Correct 15 ms 24092 KB Output is correct
21 Correct 18 ms 24020 KB Output is correct
22 Correct 107 ms 43636 KB Output is correct
23 Correct 98 ms 43592 KB Output is correct
24 Correct 119 ms 44832 KB Output is correct
25 Correct 182 ms 49864 KB Output is correct
26 Correct 98 ms 43568 KB Output is correct
27 Correct 219 ms 49920 KB Output is correct
28 Correct 233 ms 49896 KB Output is correct
29 Correct 134 ms 57152 KB Output is correct
30 Correct 89 ms 49396 KB Output is correct
31 Correct 96 ms 50124 KB Output is correct
32 Correct 215 ms 55564 KB Output is correct
33 Correct 91 ms 49504 KB Output is correct
34 Correct 13 ms 23764 KB Output is correct
35 Correct 16 ms 23816 KB Output is correct
36 Correct 13 ms 23828 KB Output is correct
37 Correct 12 ms 23844 KB Output is correct
38 Correct 17 ms 24000 KB Output is correct
39 Correct 14 ms 24020 KB Output is correct
40 Correct 18 ms 24020 KB Output is correct
41 Correct 90 ms 49456 KB Output is correct
42 Correct 97 ms 50104 KB Output is correct
43 Correct 172 ms 55676 KB Output is correct
44 Correct 104 ms 49584 KB Output is correct
45 Correct 88 ms 32920 KB Output is correct
46 Correct 102 ms 32952 KB Output is correct
47 Correct 91 ms 33316 KB Output is correct
48 Correct 90 ms 32848 KB Output is correct
49 Correct 92 ms 33316 KB Output is correct
50 Correct 102 ms 32840 KB Output is correct
51 Correct 468 ms 69216 KB Output is correct
52 Correct 492 ms 69176 KB Output is correct
53 Correct 488 ms 70928 KB Output is correct
54 Correct 475 ms 70196 KB Output is correct
55 Correct 452 ms 69280 KB Output is correct
56 Correct 54 ms 29492 KB Output is correct
57 Correct 64 ms 29500 KB Output is correct
58 Correct 84 ms 31860 KB Output is correct
59 Correct 89 ms 31888 KB Output is correct
60 Correct 104 ms 36016 KB Output is correct
61 Correct 98 ms 36276 KB Output is correct
62 Correct 86 ms 33192 KB Output is correct
63 Correct 76 ms 35340 KB Output is correct
64 Correct 88 ms 31940 KB Output is correct
65 Correct 83 ms 31980 KB Output is correct
66 Correct 111 ms 33452 KB Output is correct
67 Correct 130 ms 34544 KB Output is correct
68 Correct 85 ms 35292 KB Output is correct
69 Correct 74 ms 33328 KB Output is correct
70 Correct 77 ms 33364 KB Output is correct
71 Correct 67 ms 32924 KB Output is correct
72 Correct 69 ms 32844 KB Output is correct
73 Correct 67 ms 33220 KB Output is correct
74 Correct 66 ms 32836 KB Output is correct
75 Correct 89 ms 33252 KB Output is correct
76 Correct 75 ms 32856 KB Output is correct
77 Correct 553 ms 63976 KB Output is correct
78 Correct 568 ms 63548 KB Output is correct
79 Correct 560 ms 85580 KB Output is correct
80 Correct 613 ms 85696 KB Output is correct
81 Correct 625 ms 82676 KB Output is correct
82 Correct 569 ms 84972 KB Output is correct
83 Correct 581 ms 63468 KB Output is correct
84 Correct 549 ms 63480 KB Output is correct
85 Correct 750 ms 73076 KB Output is correct
86 Correct 462 ms 88028 KB Output is correct
87 Correct 444 ms 75040 KB Output is correct
88 Correct 571 ms 73284 KB Output is correct