#include <bits/stdc++.h>
//#include "bits_stdc++.h"
#include <stdio.h>
#include <algorithm>
#include <memory.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
ll n, m, q, l ,r;
ll const INF = 1e13;
vector<vector<ll> > leftt, rightt;
vector<pii> queries;
vector<bool> ans;
vector<ll> toright, toleft;
void dnc(ll from, ll to, vector<pii> queries)
{
vector<pii> leftone, rightone;
if (queries.empty()) return;
if (from==to)
{
bool pos = false;
for (ll u: rightt[from]) if (u==to) {pos=true; break;}
for (pii u: queries) ans[u.s] = pos;
return;
}
ll mid = (from+to)/2;
toright.clear(); toleft.clear();
deque<pi> que;// (val, i)
for (ll i = mid; i>=from; i--)
{
ll aftermid = INF;
toright[i] = INF;
ll befmid = -INF;
for (ll u: rightt[i])
{
if (u>to) continue;
if (u>=mid) aftermid = min(aftermid, u);
else befmid = max(befmid, u);
}
toright[i] = min(toright[i], aftermid);
while (que.size() && (que.back().s<=befmid+1 || que.back().f>=toright[i]))
{
toright[i] = min(toright[i], que.back().f);
que.pop_back();
}
que.push_back(mp(toright[i], i));
}
que.clear();
for (ll i = mid+1; i<=to; i++)
{
ll aftermid = -INF;
toleft[i] = -INF;
ll befmid = INF;
for (ll u: leftt[i])
{
if (u<from) continue;
if (u<=mid+1) aftermid = max(aftermid, u);
else befmid = min(befmid, u);
}
toleft[i] = max(toleft[i], aftermid);
while (que.size() && (que.back().s>=befmid-1 || que.back().f<=toleft[i]))
{
toleft[i] = max(toleft[i], que.back().f);
que.pop_back();
}
que.push_back(mp(toleft[i], i));
}
for (pii u: queries)
{
if (u.f.f <mid+1 && u.f.s>mid)
{
ans[u.s] = (toright[u.f.f]<=u.f.s && toleft[u.f.s]>=u.f.f);
}
else if (u.f.s <= mid)
{
leftone.pb(u);
}
else
{
rightone.pb(u);
}
}
dnc(from, mid, leftone);
dnc(mid+1, to, rightone);
}
int main()
{
input(n); input(m); input(q);
leftt.resize(n+1); rightt.resize(n+1);
toleft.resize(n+1); toright.resize(n+1);
ans.resize(q);
for (ll i=0; i<m; ++i)
{
input(l); input(r);
leftt[r].pb(l);
rightt[l].pb(r);
}
for (ll i=0; i<q; ++i)
{
input(l); input(r);
queries.pb(mp(mp(l, r), i));
}
dnc(1, n, queries);
for (ll i=0; i<q; ++i)
{
if (ans[i]) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
Compilation message
curtains.cpp: In function 'int main()':
curtains.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
curtains.cpp:105:2: note: in expansion of macro 'input'
105 | input(n); input(m); input(q);
| ^~~~~
curtains.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
curtains.cpp:105:12: note: in expansion of macro 'input'
105 | input(n); input(m); input(q);
| ^~~~~
curtains.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
curtains.cpp:105:22: note: in expansion of macro 'input'
105 | input(n); input(m); input(q);
| ^~~~~
curtains.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
curtains.cpp:111:3: note: in expansion of macro 'input'
111 | input(l); input(r);
| ^~~~~
curtains.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
curtains.cpp:111:13: note: in expansion of macro 'input'
111 | input(l); input(r);
| ^~~~~
curtains.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
curtains.cpp:117:3: note: in expansion of macro 'input'
117 | input(l); input(r);
| ^~~~~
curtains.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
curtains.cpp:117:13: note: in expansion of macro 'input'
117 | input(l); input(r);
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
440 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
668 KB |
Output is correct |
15 |
Correct |
5 ms |
600 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
4 ms |
860 KB |
Output is correct |
20 |
Correct |
4 ms |
860 KB |
Output is correct |
21 |
Correct |
4 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
440 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
668 KB |
Output is correct |
15 |
Correct |
5 ms |
600 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
4 ms |
860 KB |
Output is correct |
20 |
Correct |
4 ms |
860 KB |
Output is correct |
21 |
Correct |
4 ms |
860 KB |
Output is correct |
22 |
Correct |
630 ms |
41732 KB |
Output is correct |
23 |
Correct |
648 ms |
41136 KB |
Output is correct |
24 |
Correct |
645 ms |
44464 KB |
Output is correct |
25 |
Correct |
756 ms |
56824 KB |
Output is correct |
26 |
Correct |
631 ms |
40732 KB |
Output is correct |
27 |
Correct |
728 ms |
57100 KB |
Output is correct |
28 |
Correct |
724 ms |
57016 KB |
Output is correct |
29 |
Correct |
656 ms |
71464 KB |
Output is correct |
30 |
Correct |
628 ms |
50864 KB |
Output is correct |
31 |
Correct |
669 ms |
52620 KB |
Output is correct |
32 |
Correct |
721 ms |
67508 KB |
Output is correct |
33 |
Correct |
629 ms |
51372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
604 KB |
Output is correct |
7 |
Correct |
4 ms |
840 KB |
Output is correct |
8 |
Correct |
654 ms |
47936 KB |
Output is correct |
9 |
Correct |
642 ms |
49580 KB |
Output is correct |
10 |
Correct |
731 ms |
60084 KB |
Output is correct |
11 |
Correct |
627 ms |
48124 KB |
Output is correct |
12 |
Correct |
170 ms |
20300 KB |
Output is correct |
13 |
Correct |
169 ms |
20168 KB |
Output is correct |
14 |
Correct |
183 ms |
20340 KB |
Output is correct |
15 |
Correct |
196 ms |
20120 KB |
Output is correct |
16 |
Correct |
170 ms |
20356 KB |
Output is correct |
17 |
Correct |
173 ms |
20136 KB |
Output is correct |
18 |
Correct |
1065 ms |
109604 KB |
Output is correct |
19 |
Correct |
1079 ms |
109688 KB |
Output is correct |
20 |
Correct |
1056 ms |
111376 KB |
Output is correct |
21 |
Correct |
1044 ms |
110504 KB |
Output is correct |
22 |
Correct |
1065 ms |
109452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
440 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
668 KB |
Output is correct |
15 |
Correct |
5 ms |
600 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
4 ms |
860 KB |
Output is correct |
20 |
Correct |
4 ms |
860 KB |
Output is correct |
21 |
Correct |
4 ms |
860 KB |
Output is correct |
22 |
Correct |
170 ms |
13256 KB |
Output is correct |
23 |
Correct |
165 ms |
13008 KB |
Output is correct |
24 |
Correct |
193 ms |
20412 KB |
Output is correct |
25 |
Correct |
185 ms |
20420 KB |
Output is correct |
26 |
Correct |
209 ms |
25696 KB |
Output is correct |
27 |
Correct |
197 ms |
26308 KB |
Output is correct |
28 |
Correct |
177 ms |
22732 KB |
Output is correct |
29 |
Correct |
183 ms |
24684 KB |
Output is correct |
30 |
Correct |
188 ms |
20712 KB |
Output is correct |
31 |
Correct |
203 ms |
20424 KB |
Output is correct |
32 |
Correct |
248 ms |
22984 KB |
Output is correct |
33 |
Correct |
221 ms |
24144 KB |
Output is correct |
34 |
Correct |
177 ms |
27524 KB |
Output is correct |
35 |
Correct |
170 ms |
23232 KB |
Output is correct |
36 |
Correct |
178 ms |
22724 KB |
Output is correct |
37 |
Correct |
172 ms |
21960 KB |
Output is correct |
38 |
Correct |
174 ms |
21960 KB |
Output is correct |
39 |
Correct |
192 ms |
22724 KB |
Output is correct |
40 |
Correct |
170 ms |
22208 KB |
Output is correct |
41 |
Correct |
170 ms |
22216 KB |
Output is correct |
42 |
Correct |
170 ms |
21956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
440 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
668 KB |
Output is correct |
15 |
Correct |
5 ms |
600 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
4 ms |
860 KB |
Output is correct |
20 |
Correct |
4 ms |
860 KB |
Output is correct |
21 |
Correct |
4 ms |
860 KB |
Output is correct |
22 |
Correct |
630 ms |
41732 KB |
Output is correct |
23 |
Correct |
648 ms |
41136 KB |
Output is correct |
24 |
Correct |
645 ms |
44464 KB |
Output is correct |
25 |
Correct |
756 ms |
56824 KB |
Output is correct |
26 |
Correct |
631 ms |
40732 KB |
Output is correct |
27 |
Correct |
728 ms |
57100 KB |
Output is correct |
28 |
Correct |
724 ms |
57016 KB |
Output is correct |
29 |
Correct |
656 ms |
71464 KB |
Output is correct |
30 |
Correct |
628 ms |
50864 KB |
Output is correct |
31 |
Correct |
669 ms |
52620 KB |
Output is correct |
32 |
Correct |
721 ms |
67508 KB |
Output is correct |
33 |
Correct |
629 ms |
51372 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
4 ms |
604 KB |
Output is correct |
39 |
Correct |
4 ms |
604 KB |
Output is correct |
40 |
Correct |
4 ms |
840 KB |
Output is correct |
41 |
Correct |
654 ms |
47936 KB |
Output is correct |
42 |
Correct |
642 ms |
49580 KB |
Output is correct |
43 |
Correct |
731 ms |
60084 KB |
Output is correct |
44 |
Correct |
627 ms |
48124 KB |
Output is correct |
45 |
Correct |
170 ms |
20300 KB |
Output is correct |
46 |
Correct |
169 ms |
20168 KB |
Output is correct |
47 |
Correct |
183 ms |
20340 KB |
Output is correct |
48 |
Correct |
196 ms |
20120 KB |
Output is correct |
49 |
Correct |
170 ms |
20356 KB |
Output is correct |
50 |
Correct |
173 ms |
20136 KB |
Output is correct |
51 |
Correct |
1065 ms |
109604 KB |
Output is correct |
52 |
Correct |
1079 ms |
109688 KB |
Output is correct |
53 |
Correct |
1056 ms |
111376 KB |
Output is correct |
54 |
Correct |
1044 ms |
110504 KB |
Output is correct |
55 |
Correct |
1065 ms |
109452 KB |
Output is correct |
56 |
Correct |
170 ms |
13256 KB |
Output is correct |
57 |
Correct |
165 ms |
13008 KB |
Output is correct |
58 |
Correct |
193 ms |
20412 KB |
Output is correct |
59 |
Correct |
185 ms |
20420 KB |
Output is correct |
60 |
Correct |
209 ms |
25696 KB |
Output is correct |
61 |
Correct |
197 ms |
26308 KB |
Output is correct |
62 |
Correct |
177 ms |
22732 KB |
Output is correct |
63 |
Correct |
183 ms |
24684 KB |
Output is correct |
64 |
Correct |
188 ms |
20712 KB |
Output is correct |
65 |
Correct |
203 ms |
20424 KB |
Output is correct |
66 |
Correct |
248 ms |
22984 KB |
Output is correct |
67 |
Correct |
221 ms |
24144 KB |
Output is correct |
68 |
Correct |
177 ms |
27524 KB |
Output is correct |
69 |
Correct |
170 ms |
23232 KB |
Output is correct |
70 |
Correct |
178 ms |
22724 KB |
Output is correct |
71 |
Correct |
172 ms |
21960 KB |
Output is correct |
72 |
Correct |
174 ms |
21960 KB |
Output is correct |
73 |
Correct |
192 ms |
22724 KB |
Output is correct |
74 |
Correct |
170 ms |
22208 KB |
Output is correct |
75 |
Correct |
170 ms |
22216 KB |
Output is correct |
76 |
Correct |
170 ms |
21956 KB |
Output is correct |
77 |
Correct |
1260 ms |
100660 KB |
Output is correct |
78 |
Correct |
1264 ms |
101300 KB |
Output is correct |
79 |
Correct |
1278 ms |
130308 KB |
Output is correct |
80 |
Correct |
1355 ms |
130312 KB |
Output is correct |
81 |
Correct |
1295 ms |
126088 KB |
Output is correct |
82 |
Correct |
1260 ms |
129204 KB |
Output is correct |
83 |
Correct |
1263 ms |
100988 KB |
Output is correct |
84 |
Correct |
1253 ms |
100528 KB |
Output is correct |
85 |
Correct |
1440 ms |
115132 KB |
Output is correct |
86 |
Correct |
1073 ms |
152172 KB |
Output is correct |
87 |
Correct |
1039 ms |
127428 KB |
Output is correct |
88 |
Correct |
1270 ms |
107336 KB |
Output is correct |