Submission #724584

#TimeUsernameProblemLanguageResultExecution timeMemory
724584TheSahibOsumnjičeni (COCI21_osumnjiceni)C++17
30 / 110
1083 ms20928 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define ll long long #define oo 1e9 + 9 #define pii pair<int, int> using namespace std; const int MAX = 2e5 + 5; int n, q; pii arr[MAX]; int st[20][MAX]; bool checkRange(pii a, pii b){ return a.first <= b.second && a.second >= b.first; } void calcMaxR(){ set<pii> s; int l = 0; for (int i = 0; i < n; i++) { while(!s.empty()){ //auto itr = s.upper_bound({arr[i].first, 0}); //auto itr2 = s.upper_bound({arr[i].second, 0}); //if(itr != s.begin()) --itr; //if(itr2 != s.begin()) --itr2; bool b = false; for(auto& p:s){ if(checkRange(p, arr[i])) b = true; } if(b){ st[0][l] = i; s.erase(arr[l]); ++l; } else{ break; } } s.insert(arr[i]); } for (int j = l; j <= n; j++) { st[0][j] = n; } } void build(){ for (int j = 1; j < 20; j++) { for (int i = 0; i <= n; i++) { st[j][i] = st[j - 1][st[j - 1][i]]; } } } int ask(int l, int r){ int ans = 1; for(int j = 19; j >= 0; --j){ if(st[j][l] <= r){ l = st[j][l]; ans += (1 << j); } } return ans; } int main(){ cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i].first >> arr[i].second; } calcMaxR(); build(); cin >> q; while(q--){ int l, r; cin >> l >> r; --l; --r; cout << ask(l, r) << '\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...