Submission #744625

#TimeUsernameProblemLanguageResultExecution timeMemory
744625MohamedAhmed04Osumnjičeni (COCI21_osumnjiceni)C++14
0 / 110
54 ms7344 KiB
#include <bits/stdc++.h> using namespace std ; #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace __gnu_pbds; template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ; const int MAX = 2e5 + 10 ; int L[MAX] , R[MAX] ; int n , q ; int val[MAX] ; vector< pair<int , int> >queries[MAX] ; int ans[MAX] ; int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n ; for(int i = 1 ; i <= n ; ++i) cin>>L[i]>>R[i] ; cin>>q ; for(int i = 1 ; i <= q ; ++i) { int l , r ; cin>>l>>r ; queries[r].emplace_back(l , i) ; } set< array<int , 3> >s ; int last = 0 ; int cnt = 1 ; for(int i = 1 ; i <= n ; ++i) { auto it = s.lower_bound({L[i] , -1 , -1}) ; if(it != s.begin()) --it ; while(it != s.end()) { array<int , 3>a = *it ; if(a[0] > R[i]) break ; if(a[1] >= L[i]) val[i] = max(val[i] , a[2]) ; ++it ; } for(int j = last+1 ; j <= val[i] ; ++j) s.erase({L[j] , R[j] , j}) ; cnt += (val[i] > 0) ; last = max(last , val[i]) ; s.insert({L[i] , R[i] , i}) ; } return cout<<cnt<<"\n" , 0 ; ordered_set< pair<int , int> >s2 ; for(int i = 1 ; i <= n ; ++i) { s2.insert({val[i] , i}) ; for(auto &p : queries[i]) ans[p.second] = 1 + s2.size() - s2.order_of_key({p.first , -1}) ; } for(int i = 1 ; i <= q ; ++i) cout<<ans[i]<<"\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...