제출 #1135775

#제출 시각아이디문제언어결과실행 시간메모리
1135775Zbyszek99Event Hopping (BOI22_events)C++20
0 / 100
151 ms17536 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define ull unsigned long long #define ff first #define ss second #define pii pair<int,int> #define pll pair<long long, long long> #define vi vector<int> #define vl vector<long long> #define pb push_back #define rep(i, b) for(int i = 0; i < (b); ++i) #define rep2(i,a,b) for(int i = a; i <= (b); ++i) #define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c) #define count_bits(x) __builtin_popcountll((x)) #define all(x) (x).begin(),(x).end() #define siz(x) (int)(x).size() #define forall(it,x) for(auto& it:(x)) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; //mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());} //ll los(ll a, ll b) {return a + (mt() % (b-a+1));} const int INF = 1e9+50; const ll INF_L = 1e18+40; const ll MOD = 1e9+7; const int tree_siz = (1 << 19)-1; pii drzewo[tree_siz]; int jump[100'001][18]; pii seg[100'001]; int max_end[100'001]; pii get_min(int akt, int p1, int p2, int s1, int s2) { if(p2 < s1 || p1 > s2) return {1e9,-1}; if(p1 >= s1 && p2 <= s2) return drzewo[akt-1]; return min(get_min(akt*2,p1,(p1+p2)/2,s1,s2),get_min(akt*2+1,(p1+p2)/2+1,p2,s1,s2)); } void upd(int v) { drzewo[v-1] = min(drzewo[v*2-1],drzewo[v*2]); if(v != 1) upd(v/2); } void change(int ind, pii w) { drzewo[tree_siz/2+ind] = min(w,drzewo[tree_siz/2+ind]); upd((tree_siz/2+ind+1)/2); } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //random_start(); int n,q; cin >> n >> q; rep(i,tree_siz) drzewo[i] = {1e9,-1}; map<int,int> m; vector<pair<int,pii>> events; rep(i,n) { int a,b; cin >> a >> b; m[a]++; m[b]++; seg[i] = {a,b}; } int cur = 0; forall(it,m) { m[it.ff] = cur++; } rep(i,n) { seg[i].ff = m[seg[i].ff]; seg[i].ss = m[seg[i].ss]; //cout << seg[i].ff << " " << seg[i].ss << " seg\n"; change(seg[i].ss,{seg[i].ff,i}); } rep(i,n) { pii nxt = get_min(1,0,tree_siz/2,seg[i].ff,seg[i].ss); jump[i][0] = nxt.ss; // cout << nxt.ss << " nxt\n"; } rep2(bit,1,17) { rep(i,n) { jump[i][bit] = jump[jump[i][bit-1]][bit-1]; } } rep(qq,q) { int s,e; cin >> s >> e; s--; e--; //cout << seg[jump[e][17]].ff << " p\n"; if(seg[jump[e][17]].ff > seg[s].ss || seg[s].ss > seg[e].ss) { cout << "impossible\n"; continue; } if(seg[s].ss > seg[e].ff) { cout << "1\n"; continue; } if(s == e) { cout << "0\n"; } int ans = 0; for(int bit = 16; bit >= 0; bit--) { if(seg[jump[e][bit]].ff > seg[s].ss) { ans += (1 << bit); e = jump[e][bit]; } // cout << e << " " << jump[e][bit] << " e\n"; } cout << ans +2 << "\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...