Submission #886092

#TimeUsernameProblemLanguageResultExecution timeMemory
886092vjudge1Curtains (NOI23_curtains)C++17
20 / 100
706 ms70136 KiB
#include <bits/stdc++.h> using namespace std; #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define sp " " //#define endl "\n" #define pii pair<int, int> #define st first #define nd second #define pb push_back #define N 500005 #define M 500005 #define L(node) node * 2 #define R(node) node * 2 + 1 const int INF = 1e9 + 7; int lazy[4 * N]; pii tree[4 * N]; void push(int node, int l, int r){ tree[node].st += lazy[node]; if (l != r){ lazy[L(node)] += lazy[node]; lazy[R(node)] += lazy[node]; } lazy[node] = 0; } pii merge(pii a, pii b){ if (a.st == b.st) return {a.st, a.nd + b.nd}; return min(a, b); } void update(int node, int l, int r, int sl, int sr, int val){ push(node, l, r); if (l > sr || r < sl) return; if (l >= sl && r <= sr){ lazy[node] += val; push(node, l, r); return; } int mid = (l + r) / 2; update(L(node), l, mid, sl, sr, val); update(R(node), mid + 1, r, sl, sr, val); tree[node] = merge(tree[L(node)], tree[R(node)]); } void build(int node, int l, int r){ tree[node] = {0, r - l + 1}; if (l == r) return; int mid = (l + r) / 2; build(L(node), l, mid); build(R(node), mid + 1, r); } pii query(int node, int l, int r, int sl, int sr){ push(node, l, r); if (l > sr || r < sl) return {INF, 0}; if (l >= sl && r <= sr) return tree[node]; int mid = (l + r) / 2; return merge(query(L(node), l, mid, sl, sr), query(R(node), mid + 1, r, sl, sr)); } int32_t main(){ //fileio(); fastio(); int n, m, q; cin>>n>>m>>q; build(1, 1, n); vector<int> l(m + 5, 0), r(m + 5, 0), ans(q + 5, 0); vector<vector<int>> ex(n + 5); vector<vector<pii>> todo(n + 5); for (int i = 1; i <= m; i++){ cin>>l[i]>>r[i]; ex[r[i]].pb(l[i]); } for (int i = 1; i <= q; i++){ int s, e; cin>>s>>e; todo[e].pb({s, i}); } for (int i = 1; i <= n; i++){ for (auto j : ex[i]){ update(1, 1, n, j, i, 1); } for (auto j : todo[i]){ if (query(1, 1, n, j.st, i).st != 0) ans[j.nd] = 1; } } for (int i = 1; i <= q; i++) { if (ans[i]) cout<<"YES\n"; else cout<<"NO\n"; } cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; }
#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...