Submission #873523

# Submission time Handle Problem Language Result Execution time Memory
873523 2023-11-15T08:57:07 Z dsyz Curtains (NOI23_curtains) C++17
100 / 100
907 ms 75960 KB
#include <bits/stdc++.h>
using namespace std;
using ll = int;
#define MAXN (1000005)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
int readInt() 
{
  int x = 0; 
  char ch=getchar_unlocked(); 
  bool s=1;
  while(ch<'0'||ch>'9'){if(ch=='-')s=0;ch=getchar_unlocked();}
  while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar_unlocked();}
  return s?x:-x;
}
struct node{
	int s,e,m,v,lazyadd;
	node *l,*r;
	node(int _s,int _e){
		s = _s;
		e = _e;
		m = (s + e) >> 1;
		v = 1e9;
		lazyadd = 1e9;
		if(s != e){
			l = new node(s,m);
			r = new node(m + 1,e);
		}
	}
	int value(){
		if(s == e){
			v = min(v,lazyadd);
			return v;
		}
		v = min(v,lazyadd);
		r->lazyadd = min(r -> lazyadd,lazyadd);
		l->lazyadd = min(l -> lazyadd,lazyadd);
		return v;
	}
	void update(int x,int y,int val){
		if(s == x && e == y) lazyadd = min(lazyadd,val);
		else{
			if(x > m) r -> update(x,y,val);
			else if(y <= m) l -> update(x,y,val);
			else l -> update(x,m,val), r -> update(m + 1,y,val);
			v = max(l->value(),r->value());
		}
	}
	int rmq(int x,int y){
		value();
		if(s == x && e == y) return value();
		if(x > m) return r -> rmq(x,y);
		if(y <= m) return l -> rmq(x,y);
		return max(l -> rmq(x,m),r -> rmq(m + 1,y)); 
	}
} *root;
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);
	ll N,M,Q;
	N = readInt(), M = readInt(), Q = readInt();
	root = new node(0,N);
	vector<pair<ll,ll> > curtain;
	for(ll i = 0;i < M;i++){
		ll S,E;
		S = readInt(), E = readInt();
		curtain.push_back({S,E});
	}
	vector<pair<pair<ll,ll>,ll> > queries;
	for(ll i = 0;i < Q;i++){
		ll L,R;
		L = readInt(), R = readInt();
		queries.push_back({{L,R},i});
	}
	sort(curtain.begin(),curtain.end());
	sort(queries.begin(),queries.end());
	bool ans[Q];
	memset(ans,0,sizeof(ans));
	ll leftmost = 1e9;
	for(ll i = queries.size() - 1;i >= 0;i--){
		ll L = queries[i].first.first;
		ll R = queries[i].first.second;
		ll index = queries[i].second;
		while(!curtain.empty() && curtain.back().first >= L){
			root -> update(curtain.back().first,curtain.back().second,curtain.back().second);
			leftmost = curtain.back().first;
			curtain.pop_back();
		}
		if(root -> rmq(L,R) == R && leftmost == L){
			ans[index] = 1;
		}
	}
	for(ll i = 0;i < Q;i++){
		if(ans[i]) cout<<"YES"<<'\n';
		else cout<<"NO"<<'\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 708 KB Output is correct
20 Correct 2 ms 712 KB Output is correct
21 Correct 2 ms 756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 708 KB Output is correct
20 Correct 2 ms 712 KB Output is correct
21 Correct 2 ms 756 KB Output is correct
22 Correct 153 ms 12988 KB Output is correct
23 Correct 162 ms 13644 KB Output is correct
24 Correct 187 ms 15764 KB Output is correct
25 Correct 300 ms 24484 KB Output is correct
26 Correct 161 ms 13280 KB Output is correct
27 Correct 300 ms 24480 KB Output is correct
28 Correct 308 ms 24476 KB Output is correct
29 Correct 147 ms 13028 KB Output is correct
30 Correct 156 ms 12504 KB Output is correct
31 Correct 175 ms 13152 KB Output is correct
32 Correct 299 ms 23464 KB Output is correct
33 Correct 156 ms 12220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 704 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 161 ms 12516 KB Output is correct
9 Correct 172 ms 13112 KB Output is correct
10 Correct 304 ms 23472 KB Output is correct
11 Correct 164 ms 12584 KB Output is correct
12 Correct 99 ms 14720 KB Output is correct
13 Correct 110 ms 15048 KB Output is correct
14 Correct 76 ms 14812 KB Output is correct
15 Correct 74 ms 14804 KB Output is correct
16 Correct 75 ms 14848 KB Output is correct
17 Correct 83 ms 14848 KB Output is correct
18 Correct 754 ms 73480 KB Output is correct
19 Correct 731 ms 73340 KB Output is correct
20 Correct 425 ms 73112 KB Output is correct
21 Correct 420 ms 73180 KB Output is correct
22 Correct 422 ms 73532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 708 KB Output is correct
20 Correct 2 ms 712 KB Output is correct
21 Correct 2 ms 756 KB Output is correct
22 Correct 76 ms 6380 KB Output is correct
23 Correct 80 ms 6320 KB Output is correct
24 Correct 111 ms 15232 KB Output is correct
25 Correct 108 ms 15244 KB Output is correct
26 Correct 77 ms 15312 KB Output is correct
27 Correct 87 ms 15300 KB Output is correct
28 Correct 70 ms 13816 KB Output is correct
29 Correct 75 ms 15040 KB Output is correct
30 Correct 110 ms 15048 KB Output is correct
31 Correct 108 ms 15096 KB Output is correct
32 Correct 94 ms 15376 KB Output is correct
33 Correct 80 ms 15300 KB Output is correct
34 Correct 105 ms 15300 KB Output is correct
35 Correct 105 ms 15036 KB Output is correct
36 Correct 101 ms 15044 KB Output is correct
37 Correct 102 ms 14844 KB Output is correct
38 Correct 102 ms 14840 KB Output is correct
39 Correct 74 ms 14800 KB Output is correct
40 Correct 74 ms 14800 KB Output is correct
41 Correct 76 ms 14844 KB Output is correct
42 Correct 76 ms 14800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 708 KB Output is correct
20 Correct 2 ms 712 KB Output is correct
21 Correct 2 ms 756 KB Output is correct
22 Correct 153 ms 12988 KB Output is correct
23 Correct 162 ms 13644 KB Output is correct
24 Correct 187 ms 15764 KB Output is correct
25 Correct 300 ms 24484 KB Output is correct
26 Correct 161 ms 13280 KB Output is correct
27 Correct 300 ms 24480 KB Output is correct
28 Correct 308 ms 24476 KB Output is correct
29 Correct 147 ms 13028 KB Output is correct
30 Correct 156 ms 12504 KB Output is correct
31 Correct 175 ms 13152 KB Output is correct
32 Correct 299 ms 23464 KB Output is correct
33 Correct 156 ms 12220 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 2 ms 704 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 1 ms 724 KB Output is correct
41 Correct 161 ms 12516 KB Output is correct
42 Correct 172 ms 13112 KB Output is correct
43 Correct 304 ms 23472 KB Output is correct
44 Correct 164 ms 12584 KB Output is correct
45 Correct 99 ms 14720 KB Output is correct
46 Correct 110 ms 15048 KB Output is correct
47 Correct 76 ms 14812 KB Output is correct
48 Correct 74 ms 14804 KB Output is correct
49 Correct 75 ms 14848 KB Output is correct
50 Correct 83 ms 14848 KB Output is correct
51 Correct 754 ms 73480 KB Output is correct
52 Correct 731 ms 73340 KB Output is correct
53 Correct 425 ms 73112 KB Output is correct
54 Correct 420 ms 73180 KB Output is correct
55 Correct 422 ms 73532 KB Output is correct
56 Correct 76 ms 6380 KB Output is correct
57 Correct 80 ms 6320 KB Output is correct
58 Correct 111 ms 15232 KB Output is correct
59 Correct 108 ms 15244 KB Output is correct
60 Correct 77 ms 15312 KB Output is correct
61 Correct 87 ms 15300 KB Output is correct
62 Correct 70 ms 13816 KB Output is correct
63 Correct 75 ms 15040 KB Output is correct
64 Correct 110 ms 15048 KB Output is correct
65 Correct 108 ms 15096 KB Output is correct
66 Correct 94 ms 15376 KB Output is correct
67 Correct 80 ms 15300 KB Output is correct
68 Correct 105 ms 15300 KB Output is correct
69 Correct 105 ms 15036 KB Output is correct
70 Correct 101 ms 15044 KB Output is correct
71 Correct 102 ms 14844 KB Output is correct
72 Correct 102 ms 14840 KB Output is correct
73 Correct 74 ms 14800 KB Output is correct
74 Correct 74 ms 14800 KB Output is correct
75 Correct 76 ms 14844 KB Output is correct
76 Correct 76 ms 14800 KB Output is correct
77 Correct 873 ms 75572 KB Output is correct
78 Correct 892 ms 75564 KB Output is correct
79 Correct 513 ms 75916 KB Output is correct
80 Correct 503 ms 75832 KB Output is correct
81 Correct 550 ms 74864 KB Output is correct
82 Correct 532 ms 75596 KB Output is correct
83 Correct 857 ms 75960 KB Output is correct
84 Correct 907 ms 75744 KB Output is correct
85 Correct 703 ms 75652 KB Output is correct
86 Correct 770 ms 75312 KB Output is correct
87 Correct 747 ms 74536 KB Output is correct
88 Correct 589 ms 75296 KB Output is correct