#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 or (x == y and 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 + 1,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;
}
}
// if(x == 5 and y == 5) cout << j << "xxxx\n";
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(u <= mid) continue;
if(firstl[i] <= u and firstr[u] >= i) ans[id] = 1;
}
}
// cout << x << ' ' << y << ' ' << mid << "\n";
// fo(i,x,y) cout << firstl[i] << ' ';en;
// fo(i,x,y) cout << firstr[i] << ' ';en;
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:109:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
109 | main()
| ^~~~
curtains.cpp: In function 'int main()':
curtains.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
114 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
curtains.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
115 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
53340 KB |
Output is correct |
2 |
Correct |
11 ms |
53340 KB |
Output is correct |
3 |
Correct |
11 ms |
53340 KB |
Output is correct |
4 |
Correct |
12 ms |
53564 KB |
Output is correct |
5 |
Correct |
12 ms |
53436 KB |
Output is correct |
6 |
Correct |
12 ms |
53596 KB |
Output is correct |
7 |
Correct |
12 ms |
53468 KB |
Output is correct |
8 |
Correct |
13 ms |
53572 KB |
Output is correct |
9 |
Correct |
12 ms |
53340 KB |
Output is correct |
10 |
Correct |
13 ms |
53340 KB |
Output is correct |
11 |
Incorrect |
12 ms |
53596 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
53340 KB |
Output is correct |
2 |
Correct |
11 ms |
53340 KB |
Output is correct |
3 |
Correct |
11 ms |
53340 KB |
Output is correct |
4 |
Correct |
12 ms |
53564 KB |
Output is correct |
5 |
Correct |
12 ms |
53436 KB |
Output is correct |
6 |
Correct |
12 ms |
53596 KB |
Output is correct |
7 |
Correct |
12 ms |
53468 KB |
Output is correct |
8 |
Correct |
13 ms |
53572 KB |
Output is correct |
9 |
Correct |
12 ms |
53340 KB |
Output is correct |
10 |
Correct |
13 ms |
53340 KB |
Output is correct |
11 |
Incorrect |
12 ms |
53596 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
53340 KB |
Output is correct |
2 |
Correct |
11 ms |
53340 KB |
Output is correct |
3 |
Correct |
11 ms |
53340 KB |
Output is correct |
4 |
Correct |
12 ms |
53564 KB |
Output is correct |
5 |
Correct |
12 ms |
53436 KB |
Output is correct |
6 |
Correct |
12 ms |
53596 KB |
Output is correct |
7 |
Correct |
12 ms |
53468 KB |
Output is correct |
8 |
Correct |
13 ms |
53572 KB |
Output is correct |
9 |
Correct |
12 ms |
53340 KB |
Output is correct |
10 |
Correct |
13 ms |
53340 KB |
Output is correct |
11 |
Incorrect |
12 ms |
53596 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
53556 KB |
Output is correct |
2 |
Correct |
12 ms |
53340 KB |
Output is correct |
3 |
Correct |
12 ms |
53336 KB |
Output is correct |
4 |
Correct |
12 ms |
53340 KB |
Output is correct |
5 |
Correct |
13 ms |
53596 KB |
Output is correct |
6 |
Correct |
14 ms |
53592 KB |
Output is correct |
7 |
Correct |
14 ms |
53596 KB |
Output is correct |
8 |
Correct |
152 ms |
81840 KB |
Output is correct |
9 |
Correct |
160 ms |
83404 KB |
Output is correct |
10 |
Correct |
257 ms |
95040 KB |
Output is correct |
11 |
Correct |
154 ms |
82092 KB |
Output is correct |
12 |
Correct |
121 ms |
67516 KB |
Output is correct |
13 |
Correct |
149 ms |
67792 KB |
Output is correct |
14 |
Correct |
123 ms |
65220 KB |
Output is correct |
15 |
Correct |
120 ms |
67180 KB |
Output is correct |
16 |
Correct |
119 ms |
65088 KB |
Output is correct |
17 |
Correct |
130 ms |
67332 KB |
Output is correct |
18 |
Correct |
864 ms |
113680 KB |
Output is correct |
19 |
Correct |
848 ms |
113980 KB |
Output is correct |
20 |
Correct |
892 ms |
113752 KB |
Output is correct |
21 |
Correct |
812 ms |
109124 KB |
Output is correct |
22 |
Correct |
866 ms |
111056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
53340 KB |
Output is correct |
2 |
Correct |
11 ms |
53340 KB |
Output is correct |
3 |
Correct |
11 ms |
53340 KB |
Output is correct |
4 |
Correct |
12 ms |
53564 KB |
Output is correct |
5 |
Correct |
12 ms |
53436 KB |
Output is correct |
6 |
Correct |
12 ms |
53596 KB |
Output is correct |
7 |
Correct |
12 ms |
53468 KB |
Output is correct |
8 |
Correct |
13 ms |
53572 KB |
Output is correct |
9 |
Correct |
12 ms |
53340 KB |
Output is correct |
10 |
Correct |
13 ms |
53340 KB |
Output is correct |
11 |
Incorrect |
12 ms |
53596 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
53340 KB |
Output is correct |
2 |
Correct |
11 ms |
53340 KB |
Output is correct |
3 |
Correct |
11 ms |
53340 KB |
Output is correct |
4 |
Correct |
12 ms |
53564 KB |
Output is correct |
5 |
Correct |
12 ms |
53436 KB |
Output is correct |
6 |
Correct |
12 ms |
53596 KB |
Output is correct |
7 |
Correct |
12 ms |
53468 KB |
Output is correct |
8 |
Correct |
13 ms |
53572 KB |
Output is correct |
9 |
Correct |
12 ms |
53340 KB |
Output is correct |
10 |
Correct |
13 ms |
53340 KB |
Output is correct |
11 |
Incorrect |
12 ms |
53596 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |