Submission #526753

#TimeUsernameProblemLanguageResultExecution timeMemory
526753joelauOsumnjičeni (COCI21_osumnjiceni)C++14
110 / 110
311 ms32964 KiB
#include <bits/stdc++.h> using namespace std; int N,Q, p[200005][20]; pair<int,int> lst[200005]; set< pair<int,int> > s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N; for (int i = 0; i < N; ++i) cin >> lst[i].first >> lst[i].second; memset(p,-1,sizeof(p)); for (int l = 0, r = 0; l < N; ++l) { while (r < N) { bool can = true; auto it = s.lower_bound(make_pair(lst[r].first,-1)); if (it != s.end() && it->first <= lst[r].second) can = false; if (it != s.begin() && prev(it)->second >= lst[r].first) can = false; if (!can) break; s.insert(lst[r++]); } p[l][0] = r; s.erase(lst[l]); } for (int k = 1; k < 20; ++k) for (int i = 0; i < N; ++i) { if (p[i][k-1] == -1) p[i][k] = -1; else p[i][k] = p[p[i][k-1]][k-1]; } cin >> Q; while (Q--) { int l,r; cin >> l >> r; l--, r--; int ans = 1; for (int k = 19; k >= 0; --k) if (p[l][k] != -1 && p[l][k] <= r) ans += (1<<k), l = p[l][k]; cout << ans << '\n'; } return 0; }
#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...