Submission #660288

# Submission time Handle Problem Language Result Execution time Memory
660288 2022-11-21T13:16:19 Z ktkerem Event Hopping (BOI22_events) C++17
0 / 100
454 ms 56364 KB
/*#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-5>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" << std::endl;
            }
            else{
                std::cout << "1" << std::endl;
            }
            continue;
        }
        ll sc = 1;
        for(ll i = 18;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" << std::endl;
        }
        else{
            std::cout << sc + 1 << std::endl;
        }
    }
    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

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
1 Correct 34 ms 47188 KB Output is correct
2 Correct 403 ms 56268 KB Output is correct
3 Correct 393 ms 56252 KB Output is correct
4 Incorrect 444 ms 56272 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47188 KB Output is correct
2 Correct 29 ms 47148 KB Output is correct
3 Correct 31 ms 47360 KB Output is correct
4 Incorrect 31 ms 47436 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47188 KB Output is correct
2 Correct 29 ms 47148 KB Output is correct
3 Correct 31 ms 47360 KB Output is correct
4 Incorrect 31 ms 47436 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47188 KB Output is correct
2 Correct 29 ms 47148 KB Output is correct
3 Correct 31 ms 47360 KB Output is correct
4 Incorrect 31 ms 47436 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 394 ms 56364 KB Output is correct
2 Correct 403 ms 56332 KB Output is correct
3 Incorrect 454 ms 56272 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 47188 KB Output is correct
2 Correct 403 ms 56268 KB Output is correct
3 Correct 393 ms 56252 KB Output is correct
4 Incorrect 444 ms 56272 KB Output isn't correct
5 Halted 0 ms 0 KB -