#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];
int n,m,q;
pii query[maxn];
int firstl[maxn],firstr[maxn];
vii adj[maxn];
int ans[maxn];
void solve(int x,int y)
{
if(x > y) return;
int mid = (x + y) >> 1;
stack<pii> st;
fod(i,mid,x) if(ke[i].size())
{
int lb = lower_bound(ke[i].begin(),ke[i].end(),mid) - ke[i].begin();
if(lb >= ke[i].size()) continue;
if(ke[i][lb] >= mid) firstl[i] = ke[i][lb];
if(lb)
{
while(st.size() and st.top().se < ke[i][lb - 1])
{
if(!firstl[i]) firstl[i] = st.top().fi;
firstl[i] = min(firstl[i],st.top().fi);
st.pop();
}
st.push({firstl[i],i});
}
}
while(st.size()) st.pop();
fo(i,mid + 1,y)
{
int lb = lower_bound(ke[i].begin(),ke[i].end(),mid) - ke[i].begin();
if(lb >= ke[i].size()) continue;
if(ke[i][lb] == mid) firstr[i] = mid;
if(lb and ke[i][lb - 1] <= mid) firstr[i] = ke[i][lb - 1];
if(lb < ke[i].size() and ke[i][lb] > mid)
{
while(st.size() and st.top().se > ke[i][lb])
{
if(!firstr[i]) firstr[i] = st.top().fi;
firstr[i] = max(firstr[i],st.top().fi);
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;
}
}
solve(x,mid);
solve(mid + 1,y);
}
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);
}
solve(1,n);
fo(i,1,n) sort(adj[i].begin(),adj[i].end());
fo(i,1,q) cout << (ans[i] ? "YES" : "NO") << "\n";
}
Compilation message
curtains.cpp: In function 'void solve(long long int, long long int)':
curtains.cpp:52:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | if(lb >= ke[i].size()) continue;
| ~~~^~~~~~~~~~~~~~~
curtains.cpp:69:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | if(lb >= ke[i].size()) continue;
| ~~~^~~~~~~~~~~~~~~
curtains.cpp:72:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | if(lb < ke[i].size() and ke[i][lb] > mid)
| ~~~^~~~~~~~~~~~~~
curtains.cpp: At global scope:
curtains.cpp:95:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
95 | main()
| ^~~~
curtains.cpp: In function 'int main()':
curtains.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
curtains.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
101 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
469 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
469 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
469 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
466 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
469 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
469 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |