This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 5e5+10;
const int INF = INT_MAX;
const int mod = 1e9+7;
const string NAME = "solve";
int n,m,t;
pair<int,int> edges[N];
vector<pair<int,int>> events[N];
int ans[N];
int tree[4*N],lazy[4*N];
void down(int id, int l, int r) {
int &t = lazy[id];
if(t == 0) {
return;
}
tree[id] = max(tree[id],t);
if(l < r) {
lazy[id << 1] = max(lazy[id << 1],t);
lazy[id << 1 | 1] = max(lazy[id << 1 | 1],t);
}
t = 0;
}
void update(int u, int v, int val, int id = 1, int l = 1, int r = n) {
down(id,l,r);
if(r < u or v < l) {
return;
}
if(u <= l and r <= v) {
lazy[id] = val;
down(id,l,r);
return;
}
int mid = l + r >> 1;
update(u,v,val,id << 1,l,mid);
update(u,v,val,id << 1 | 1,mid+1,r);
tree[id] = min(tree[id << 1],tree[id << 1 | 1]);
}
int get(int u, int v, int id = 1, int l = 1, int r = n) {
down(id,l,r);
if(r < u or v < l) {
return mod;
}
if(u <= l and r <= v) {
return tree[id];
}
int mid = l + r >> 1;
return min(get(u,v,id << 1,l,mid),get(u,v,id << 1 | 1,mid+1,r));
}
signed main()
{
if (fopen((NAME + ".inp").c_str(), "r")) {
freopen((NAME + ".inp").c_str(), "r", stdin);
freopen((NAME + ".out").c_str(), "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> t;
for(int i = 1 ; i <= m ; i++) {
int l,r; cin >> l >> r;
edges[i] = {r,l};
}
for(int i = 1 ; i <= t ; i++) {
int l,r; cin >> l >> r;
events[r].push_back({l,i});
}
sort(edges+1,edges+m+1);
for(int i = 1, j = 1 ; i <= n ; i++) {
while(j <= m and edges[j].first <= i) {
update(edges[j].second,edges[j].first,edges[j].second);
j++;
}
for(auto p:events[i]) {
int val = get(p.first,i);
if(val >= p.first) {
ans[p.second] = 1;
}
}
}
for(int i = 1 ; i <= t ; i++) {
if(ans[i]) {
cout << "YES" << '\n';
}
else {
cout << "NO" << '\n';
}
}
return 0;
}
Compilation message (stderr)
curtains.cpp: In function 'void update(int, int, int, int, int, int)':
curtains.cpp:41:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
41 | int mid = l + r >> 1;
| ~~^~~
curtains.cpp: In function 'int get(int, int, int, int, int)':
curtains.cpp:55:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid = l + r >> 1;
| ~~^~~
curtains.cpp: In function 'int main()':
curtains.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen((NAME + ".inp").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
curtains.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen((NAME + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |