답안 #777050

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777050 2023-07-08T14:51:49 Z Cookie Event Hopping (BOI22_events) C++14
0 / 100
44 ms 10084 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("WINTER.inp");
ofstream fout("WINTER.out");
#define sz(v) (int)v.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
const int x[4] = {1, -1, 0, 0};
const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7;
const int mxn = 1e5 + 5, mxm = 1e5, sq = 400;
const int base = (1 << 18);
const ll inf = 1e9;
const ld pre = 1e-6;
struct th{
    int s, e, id;
    bool operator <(const th &b){
        return(s < b.s);
    }
};
int n, q;
int pos[mxn + 1], up[mxn + 1][18];
vt<th>comp;
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        int s, e; cin >> s >> e;
        comp.pb({s, e, i});
    }
    sort(comp.begin(), comp.end());
    int lp = 0;
    for(int i = 0; i < sz(comp); i++){
        pos[comp[i].id] = i;
        while(lp < sz(comp) && comp[lp].s <= comp[i].e)lp++;
        up[i][0] = lp - 1;
    }
    for(int i = 1; i < 18; i++){
        for(int j = 0; j < sz(comp); j++){
            up[j][i] = up[up[j][i - 1]][i - 1];
        }
    }
    for(int i = 0; i < q; i++){
        int s, e; cin >> s >> e; s--; e--;
        s = pos[s]; e = pos[e];
        if(s > e){
            cout << "Impossible" << "\n";
            continue;
        }else if(s == e){
            cout << 0 << "\n";
            continue;
        }
        int ans = 0;
        for(int i = 17; i >= 0; i--){
            if(up[s][i] < e){
                s = up[s][i]; ans += (1 << i);
            }
        }
        if(up[s][0] < e){
            cout << "Impossible" << "\n";
        }else{
            cout << ans + 1 << "\n";
        }
    }
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 10084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -