#include<bits/stdc++.h>
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout<<"\n";
#define int long long
#define inf 1000000000
#define pii pair<int,int>
#define vii vector<pii>
#define lb(x) x&-x
#define bit(i,j) ((i>>j)&1)
#define offbit(i,j) (i^(1<<j))
#define onbit(i,j) (i|(1<<j))
#define vi vector<int>
template <typename T1, typename T2> bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
vi ke[maxn];
pii query[maxn];
int firstl[maxn],firstr[maxn];
vii adj[maxn];
int ans[maxn];
int n;
void solve(int x,int y)
{
if(x > y) return;
fo(i,x,y) firstl[i] = inf,firstr[i] = -inf;
int mid = (x + y) >> 1;
stack<pii> st;
fod(i,mid,x) if(ke[i].size())
{
int j = inf,k = -inf;
for(int it : ke[i])
{
if(it < mid) k = max(k,it);
if(it >= mid)
{
j = it;
break;
}
}
firstl[i] = min(firstl[i],j);
while(st.size() and st.top().se <= k + 1)
{
firstl[i] = min(firstl[i],st.top().fi);
st.pop();
}
st.push({firstl[i],i});
}
while(st.size()) st.pop();
fo(i,min(mid,y),y) if(ke[i].size())
{
int j = -inf,k = inf;
fod(u,(int)ke[i].size() - 1,0)
{
if(ke[i][u] > mid) k = min(k,ke[i][u]);
if(ke[i][u] <= mid)
{
j = ke[i][u];
break;
}
}
firstr[i] = max(j,firstr[i]);
while(st.size() and st.top().se >= k - 1)
{
firstr[i] = max(st.top().fi,firstr[i]);
st.pop();
}
st.push({firstr[i],i});
}
fo(i,x,mid)
{
for(auto [u,id] : adj[i])
{
if(u > y) break;
if(firstl[i] <= u and firstr[u] >= i) ans[id] = 1;
}
}
if(x == y) return;
solve(x,mid);
solve(mid + 1,y);
}
int m,q;
main()
{
#define name "TASK"
if(fopen(name".inp","r"))
{
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> q;
fo(i,1,m)
{
int u,v;
cin >> u >> v;
ke[u].pb(v);
ke[v].pb(u);
}
fo(i,1,n) sort(ke[i].begin(),ke[i].end());
fo(i,1,q)
{
int u,v;
cin >> u >> v;
adj[u].pb(v,i);
adj[v].pb(u,i);
}
fo(i,1,n) sort(adj[i].begin(),adj[i].end());
solve(1,n);
fo(i,1,q) cout << (ans[i] ? "YES" : "NO") << "\n";
}
Compilation message
curtains.cpp:104:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
104 | main()
| ^~~~
curtains.cpp: In function 'int main()':
curtains.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
curtains.cpp:110:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
110 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
53340 KB |
Output is correct |
2 |
Correct |
11 ms |
53340 KB |
Output is correct |
3 |
Correct |
13 ms |
53384 KB |
Output is correct |
4 |
Correct |
12 ms |
53340 KB |
Output is correct |
5 |
Correct |
14 ms |
53592 KB |
Output is correct |
6 |
Correct |
13 ms |
53488 KB |
Output is correct |
7 |
Correct |
11 ms |
53596 KB |
Output is correct |
8 |
Correct |
12 ms |
53508 KB |
Output is correct |
9 |
Correct |
13 ms |
53784 KB |
Output is correct |
10 |
Correct |
13 ms |
53536 KB |
Output is correct |
11 |
Correct |
13 ms |
53560 KB |
Output is correct |
12 |
Correct |
11 ms |
53340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
53340 KB |
Output is correct |
2 |
Correct |
11 ms |
53340 KB |
Output is correct |
3 |
Correct |
13 ms |
53384 KB |
Output is correct |
4 |
Correct |
12 ms |
53340 KB |
Output is correct |
5 |
Correct |
14 ms |
53592 KB |
Output is correct |
6 |
Correct |
13 ms |
53488 KB |
Output is correct |
7 |
Correct |
11 ms |
53596 KB |
Output is correct |
8 |
Correct |
12 ms |
53508 KB |
Output is correct |
9 |
Correct |
13 ms |
53784 KB |
Output is correct |
10 |
Correct |
13 ms |
53536 KB |
Output is correct |
11 |
Correct |
13 ms |
53560 KB |
Output is correct |
12 |
Correct |
11 ms |
53340 KB |
Output is correct |
13 |
Correct |
13 ms |
53596 KB |
Output is correct |
14 |
Correct |
13 ms |
53596 KB |
Output is correct |
15 |
Correct |
15 ms |
53660 KB |
Output is correct |
16 |
Correct |
14 ms |
53592 KB |
Output is correct |
17 |
Correct |
14 ms |
53788 KB |
Output is correct |
18 |
Correct |
17 ms |
53632 KB |
Output is correct |
19 |
Correct |
13 ms |
53596 KB |
Output is correct |
20 |
Correct |
13 ms |
53596 KB |
Output is correct |
21 |
Correct |
16 ms |
53700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
53340 KB |
Output is correct |
2 |
Correct |
11 ms |
53340 KB |
Output is correct |
3 |
Correct |
13 ms |
53384 KB |
Output is correct |
4 |
Correct |
12 ms |
53340 KB |
Output is correct |
5 |
Correct |
14 ms |
53592 KB |
Output is correct |
6 |
Correct |
13 ms |
53488 KB |
Output is correct |
7 |
Correct |
11 ms |
53596 KB |
Output is correct |
8 |
Correct |
12 ms |
53508 KB |
Output is correct |
9 |
Correct |
13 ms |
53784 KB |
Output is correct |
10 |
Correct |
13 ms |
53536 KB |
Output is correct |
11 |
Correct |
13 ms |
53560 KB |
Output is correct |
12 |
Correct |
11 ms |
53340 KB |
Output is correct |
13 |
Correct |
13 ms |
53596 KB |
Output is correct |
14 |
Correct |
13 ms |
53596 KB |
Output is correct |
15 |
Correct |
15 ms |
53660 KB |
Output is correct |
16 |
Correct |
14 ms |
53592 KB |
Output is correct |
17 |
Correct |
14 ms |
53788 KB |
Output is correct |
18 |
Correct |
17 ms |
53632 KB |
Output is correct |
19 |
Correct |
13 ms |
53596 KB |
Output is correct |
20 |
Correct |
13 ms |
53596 KB |
Output is correct |
21 |
Correct |
16 ms |
53700 KB |
Output is correct |
22 |
Correct |
154 ms |
85328 KB |
Output is correct |
23 |
Correct |
156 ms |
86096 KB |
Output is correct |
24 |
Correct |
178 ms |
88656 KB |
Output is correct |
25 |
Correct |
287 ms |
100684 KB |
Output is correct |
26 |
Correct |
160 ms |
85844 KB |
Output is correct |
27 |
Correct |
277 ms |
100188 KB |
Output is correct |
28 |
Correct |
257 ms |
101052 KB |
Output is correct |
29 |
Correct |
162 ms |
86536 KB |
Output is correct |
30 |
Correct |
156 ms |
83060 KB |
Output is correct |
31 |
Correct |
164 ms |
84276 KB |
Output is correct |
32 |
Correct |
263 ms |
96936 KB |
Output is correct |
33 |
Correct |
159 ms |
83116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
53340 KB |
Output is correct |
2 |
Correct |
12 ms |
53560 KB |
Output is correct |
3 |
Correct |
12 ms |
53340 KB |
Output is correct |
4 |
Correct |
12 ms |
53504 KB |
Output is correct |
5 |
Correct |
13 ms |
53792 KB |
Output is correct |
6 |
Correct |
14 ms |
53636 KB |
Output is correct |
7 |
Correct |
13 ms |
53592 KB |
Output is correct |
8 |
Correct |
157 ms |
83216 KB |
Output is correct |
9 |
Correct |
190 ms |
84148 KB |
Output is correct |
10 |
Correct |
259 ms |
97296 KB |
Output is correct |
11 |
Correct |
155 ms |
83220 KB |
Output is correct |
12 |
Correct |
129 ms |
68032 KB |
Output is correct |
13 |
Correct |
123 ms |
68004 KB |
Output is correct |
14 |
Correct |
122 ms |
65728 KB |
Output is correct |
15 |
Correct |
125 ms |
67780 KB |
Output is correct |
16 |
Correct |
123 ms |
65812 KB |
Output is correct |
17 |
Correct |
126 ms |
67932 KB |
Output is correct |
18 |
Correct |
865 ms |
116996 KB |
Output is correct |
19 |
Correct |
859 ms |
116736 KB |
Output is correct |
20 |
Correct |
816 ms |
115020 KB |
Output is correct |
21 |
Correct |
835 ms |
112268 KB |
Output is correct |
22 |
Correct |
783 ms |
114300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
53340 KB |
Output is correct |
2 |
Correct |
11 ms |
53340 KB |
Output is correct |
3 |
Correct |
13 ms |
53384 KB |
Output is correct |
4 |
Correct |
12 ms |
53340 KB |
Output is correct |
5 |
Correct |
14 ms |
53592 KB |
Output is correct |
6 |
Correct |
13 ms |
53488 KB |
Output is correct |
7 |
Correct |
11 ms |
53596 KB |
Output is correct |
8 |
Correct |
12 ms |
53508 KB |
Output is correct |
9 |
Correct |
13 ms |
53784 KB |
Output is correct |
10 |
Correct |
13 ms |
53536 KB |
Output is correct |
11 |
Correct |
13 ms |
53560 KB |
Output is correct |
12 |
Correct |
11 ms |
53340 KB |
Output is correct |
13 |
Correct |
13 ms |
53596 KB |
Output is correct |
14 |
Correct |
13 ms |
53596 KB |
Output is correct |
15 |
Correct |
15 ms |
53660 KB |
Output is correct |
16 |
Correct |
14 ms |
53592 KB |
Output is correct |
17 |
Correct |
14 ms |
53788 KB |
Output is correct |
18 |
Correct |
17 ms |
53632 KB |
Output is correct |
19 |
Correct |
13 ms |
53596 KB |
Output is correct |
20 |
Correct |
13 ms |
53596 KB |
Output is correct |
21 |
Correct |
16 ms |
53700 KB |
Output is correct |
22 |
Correct |
74 ms |
67792 KB |
Output is correct |
23 |
Correct |
69 ms |
67664 KB |
Output is correct |
24 |
Correct |
132 ms |
68692 KB |
Output is correct |
25 |
Correct |
142 ms |
69028 KB |
Output is correct |
26 |
Correct |
112 ms |
68652 KB |
Output is correct |
27 |
Correct |
116 ms |
68684 KB |
Output is correct |
28 |
Correct |
111 ms |
67060 KB |
Output is correct |
29 |
Correct |
116 ms |
68076 KB |
Output is correct |
30 |
Correct |
135 ms |
68692 KB |
Output is correct |
31 |
Correct |
137 ms |
68688 KB |
Output is correct |
32 |
Correct |
135 ms |
68684 KB |
Output is correct |
33 |
Correct |
129 ms |
68476 KB |
Output is correct |
34 |
Correct |
123 ms |
68488 KB |
Output is correct |
35 |
Correct |
130 ms |
68428 KB |
Output is correct |
36 |
Correct |
127 ms |
68376 KB |
Output is correct |
37 |
Correct |
120 ms |
68032 KB |
Output is correct |
38 |
Correct |
127 ms |
67988 KB |
Output is correct |
39 |
Correct |
124 ms |
65748 KB |
Output is correct |
40 |
Correct |
138 ms |
67756 KB |
Output is correct |
41 |
Correct |
121 ms |
65604 KB |
Output is correct |
42 |
Correct |
154 ms |
67524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
53340 KB |
Output is correct |
2 |
Correct |
11 ms |
53340 KB |
Output is correct |
3 |
Correct |
13 ms |
53384 KB |
Output is correct |
4 |
Correct |
12 ms |
53340 KB |
Output is correct |
5 |
Correct |
14 ms |
53592 KB |
Output is correct |
6 |
Correct |
13 ms |
53488 KB |
Output is correct |
7 |
Correct |
11 ms |
53596 KB |
Output is correct |
8 |
Correct |
12 ms |
53508 KB |
Output is correct |
9 |
Correct |
13 ms |
53784 KB |
Output is correct |
10 |
Correct |
13 ms |
53536 KB |
Output is correct |
11 |
Correct |
13 ms |
53560 KB |
Output is correct |
12 |
Correct |
11 ms |
53340 KB |
Output is correct |
13 |
Correct |
13 ms |
53596 KB |
Output is correct |
14 |
Correct |
13 ms |
53596 KB |
Output is correct |
15 |
Correct |
15 ms |
53660 KB |
Output is correct |
16 |
Correct |
14 ms |
53592 KB |
Output is correct |
17 |
Correct |
14 ms |
53788 KB |
Output is correct |
18 |
Correct |
17 ms |
53632 KB |
Output is correct |
19 |
Correct |
13 ms |
53596 KB |
Output is correct |
20 |
Correct |
13 ms |
53596 KB |
Output is correct |
21 |
Correct |
16 ms |
53700 KB |
Output is correct |
22 |
Correct |
154 ms |
85328 KB |
Output is correct |
23 |
Correct |
156 ms |
86096 KB |
Output is correct |
24 |
Correct |
178 ms |
88656 KB |
Output is correct |
25 |
Correct |
287 ms |
100684 KB |
Output is correct |
26 |
Correct |
160 ms |
85844 KB |
Output is correct |
27 |
Correct |
277 ms |
100188 KB |
Output is correct |
28 |
Correct |
257 ms |
101052 KB |
Output is correct |
29 |
Correct |
162 ms |
86536 KB |
Output is correct |
30 |
Correct |
156 ms |
83060 KB |
Output is correct |
31 |
Correct |
164 ms |
84276 KB |
Output is correct |
32 |
Correct |
263 ms |
96936 KB |
Output is correct |
33 |
Correct |
159 ms |
83116 KB |
Output is correct |
34 |
Correct |
12 ms |
53340 KB |
Output is correct |
35 |
Correct |
12 ms |
53560 KB |
Output is correct |
36 |
Correct |
12 ms |
53340 KB |
Output is correct |
37 |
Correct |
12 ms |
53504 KB |
Output is correct |
38 |
Correct |
13 ms |
53792 KB |
Output is correct |
39 |
Correct |
14 ms |
53636 KB |
Output is correct |
40 |
Correct |
13 ms |
53592 KB |
Output is correct |
41 |
Correct |
157 ms |
83216 KB |
Output is correct |
42 |
Correct |
190 ms |
84148 KB |
Output is correct |
43 |
Correct |
259 ms |
97296 KB |
Output is correct |
44 |
Correct |
155 ms |
83220 KB |
Output is correct |
45 |
Correct |
129 ms |
68032 KB |
Output is correct |
46 |
Correct |
123 ms |
68004 KB |
Output is correct |
47 |
Correct |
122 ms |
65728 KB |
Output is correct |
48 |
Correct |
125 ms |
67780 KB |
Output is correct |
49 |
Correct |
123 ms |
65812 KB |
Output is correct |
50 |
Correct |
126 ms |
67932 KB |
Output is correct |
51 |
Correct |
865 ms |
116996 KB |
Output is correct |
52 |
Correct |
859 ms |
116736 KB |
Output is correct |
53 |
Correct |
816 ms |
115020 KB |
Output is correct |
54 |
Correct |
835 ms |
112268 KB |
Output is correct |
55 |
Correct |
783 ms |
114300 KB |
Output is correct |
56 |
Correct |
74 ms |
67792 KB |
Output is correct |
57 |
Correct |
69 ms |
67664 KB |
Output is correct |
58 |
Correct |
132 ms |
68692 KB |
Output is correct |
59 |
Correct |
142 ms |
69028 KB |
Output is correct |
60 |
Correct |
112 ms |
68652 KB |
Output is correct |
61 |
Correct |
116 ms |
68684 KB |
Output is correct |
62 |
Correct |
111 ms |
67060 KB |
Output is correct |
63 |
Correct |
116 ms |
68076 KB |
Output is correct |
64 |
Correct |
135 ms |
68692 KB |
Output is correct |
65 |
Correct |
137 ms |
68688 KB |
Output is correct |
66 |
Correct |
135 ms |
68684 KB |
Output is correct |
67 |
Correct |
129 ms |
68476 KB |
Output is correct |
68 |
Correct |
123 ms |
68488 KB |
Output is correct |
69 |
Correct |
130 ms |
68428 KB |
Output is correct |
70 |
Correct |
127 ms |
68376 KB |
Output is correct |
71 |
Correct |
120 ms |
68032 KB |
Output is correct |
72 |
Correct |
127 ms |
67988 KB |
Output is correct |
73 |
Correct |
124 ms |
65748 KB |
Output is correct |
74 |
Correct |
138 ms |
67756 KB |
Output is correct |
75 |
Correct |
121 ms |
65604 KB |
Output is correct |
76 |
Correct |
154 ms |
67524 KB |
Output is correct |
77 |
Correct |
961 ms |
117596 KB |
Output is correct |
78 |
Correct |
997 ms |
117660 KB |
Output is correct |
79 |
Correct |
817 ms |
116304 KB |
Output is correct |
80 |
Correct |
888 ms |
116308 KB |
Output is correct |
81 |
Correct |
902 ms |
115656 KB |
Output is correct |
82 |
Correct |
813 ms |
115432 KB |
Output is correct |
83 |
Correct |
971 ms |
117592 KB |
Output is correct |
84 |
Correct |
1044 ms |
121008 KB |
Output is correct |
85 |
Correct |
997 ms |
120300 KB |
Output is correct |
86 |
Correct |
863 ms |
114800 KB |
Output is correct |
87 |
Correct |
824 ms |
115132 KB |
Output is correct |
88 |
Correct |
867 ms |
115364 KB |
Output is correct |