Submission #1169587

#TimeUsernameProblemLanguageResultExecution timeMemory
1169587nathan4690Curtains (NOI23_curtains)C++20
100 / 100
757 ms94508 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define f1(i,n) for(int i=1;i<=n;i++) #define __file_name "" using namespace std; const ll maxn=1e6+5, inf=1e18; struct Value{ int le = 1e9, ri = -1e9; Value(int le=1e9, int ri=-1e9): le(le), ri(ri){}; Value operator+(const Value &rhs) const{ // Merge two nodes Value res; if(le == 1e9) res = rhs; else if(rhs.le == 1e9) res = *this; else if(ri >= rhs.le - 1){ res.le = min(le, rhs.le); res.ri = max(ri, rhs.ri); }else res = rhs; return res; } }; template<class T> struct SegmentTree{ int n; vector<T> st; SegmentTree(){}; SegmentTree(int n): n(n), st(4*n+1){}; void _upd1(int idx, int l, int r, int i, const T &v){ if(i < l || r < i) return; if(l == r){ st[idx] = st[idx] + v; return; } int mid = (l + r) / 2; _upd1(idx*2, l, mid, i, v); _upd1(idx*2+1, mid+1, r, i, v); st[idx] = st[idx*2] + st[idx*2+1]; } inline void updatePoint(int position, const T &value){ _upd1(1,1,n,position,value); } T _get(int idx, int l, int r, int u, int v){ if(v < l || r < u) return T(); if(u <= l && r <= v) return st[idx]; int mid = (l + r) / 2; return _get(idx*2, l, mid, u, v) + _get(idx*2+1, mid+1, r, u, v); } inline T getRange(int left_, int right_){ return _get(1,1,n,left_, right_); } }; #define SegTree SegmentTree<Value> int n, m, q; pair<int,int> a[maxn]; vector<pair<int,int>> qu[maxn]; vector<int> upd[maxn]; SegTree st; bool ans[maxn]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(__file_name ".inp", "r")){ freopen(__file_name ".inp", "r", stdin); freopen(__file_name ".out", "w", stdout); } // code here cin >> n >> m >> q; st = SegTree(n); f1(i,m){ cin >> a[i].first >> a[i].second; upd[a[i].second].push_back(i); } f1(i,q){ int l, r; cin >> l >> r; qu[r].push_back({l, i}); } f1(r, n){ for(int idx: upd[r]){ int l = a[idx].first; st.updatePoint(l, Value(l, r)); } for(pair<int,int> qq: qu[r]){ int l = qq.first, idx = qq.second; Value vv = st.getRange(l, r); ans[idx] = (vv.le == l && vv.ri == r); } } f1(i,q) cout << (ans[i] ? "YES" : "NO") << '\n'; return 0; }

Compilation message (stderr)

curtains.cpp: In function 'int main()':
curtains.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen(__file_name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
curtains.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(__file_name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...