This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e14 + 7;
const ll ous = 1e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
ll n , m;std::vector<llll> ar;
llll rmq[ous][20];ll nex[ous][20];
void solve(){
for(ll i =0;19>i;i++){
for(ll j= 0;ous>j;j++){
rmq[j][i] = {limit , -1};
}
}
memset(nex , 0ll , sizeof(nex));
ll n , q;std::cin >> n >> q;
ar.resize(n);
std::set<ll> st;
std::vector<ll> b;
for(ll i = 0;n>i;i++){
std::cin >> ar[i].fi >> ar[i].sec;
st.insert(ar[i].sec);
}
for(auto j:st){
b.pb(j);
}
for(ll i = 0;n>i;i++){
ll l = std::lower_bound(all(b) , ar[i].sec) - b.begin();
rmq[l][0] = std::min(rmq[l][0] , {ar[i].fi , i});
}
for(ll i = 1;20>i;i++){
ll o = (1ll << i);
for(ll j = 0;n >= j + o;j++){
rmq[j][i] = std::min(rmq[j][i-1] , rmq[j + (1ll << (i-1))][i-1]);
}
}
for(ll i = 0;n>i;i++){
ll l = std::lower_bound(all(b) , ar[i].fi) - b.begin();
ll r = std::lower_bound(all(b) , ar[i].sec) - b.begin();
ll o = log2(r - l + 1);
llll t = std::min(rmq[l][o] , rmq[r - (1ll << o) + 1][o]);
nex[i][0] = t.sec;
}
for(ll i = 1;20>i;i++){
for(ll j = 0;n>j;j++){
nex[j][i] = nex[nex[j][i-1]][i-1];
}
}
//std::cout << nex[7][0] << std::endl;
while(q--){
ll x , y;std::cin >> x >> y;x--;y--;
if(x == y || (ar[x].sec >= ar[y].fi && ar[x].sec <= ar[y].sec)){
if(x == y){
std::cout << "0\n";
}
else{
std::cout << "1\n";
}
continue;
}
ll sc = 1;
for(ll i = 19;0<=i;i--){
if(ar[nex[y][i]].fi > ar[x].sec){
y = nex[y][i];
sc+= 1ll << i;
//std::cout << y << std::endl;
}
}
//std::cout << "//" << std::endl;
y = nex[y][0];
if(ar[x].sec < ar[y].fi || ar[x].sec > ar[y].sec){
std::cout << "impossible\n";
}
else{
std::cout << sc + (ar[x].sec >= ar[y].fi) << "\n";
}
}
return;/**/
}
signed main(){
std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
ll t=1;
//std::cin >> t;
ll o = 1;
while(t--){
//cout << "Case " << o++ << ":\n";
solve();
}
return 0;
}/**/
Compilation message (stderr)
events.cpp:5:78: warning: "/*" within comment [-Wcomment]
5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
|
events.cpp: In function 'int main()':
events.cpp:101:8: warning: unused variable 'o' [-Wunused-variable]
101 | ll o = 1;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |