답안 #676640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676640 2022-12-31T14:15:19 Z Do_you_copy Event Hopping (BOI22_events) C++17
0 / 100
146 ms 37236 KB
//Then
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
mt19937_64 Rand(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 1;
//const int Mod = 1e9 + 7;
//const int inf =
int n, q;
bool invalid[maxN];
pii e[maxN];
struct TPQ{
    int x, i;
    bool operator < (const TPQ &other) const{
        if (x == other.x && i < 0 && other.i < 0){
            return e[-i].fi < e[-other.i].fi;
        }
        return x > other.x;
    }
    bool valid() const{
        return invalid[i] == 0;
    }
};

int lift[maxN][20];

void Init(){
    cin >> n >> q;
    priority_queue <TPQ> PQ;
    vector <pii> node;
    for (int i = 1; i <= n; ++i){
        cin >> e[i].fi >> e[i].se;
        node.pb({e[i].fi, i});
        node.pb({e[i].se, -i});
    }
    sort(node.begin(), node.end());
    for (auto t: node){
        if (t.fi > 0){
            PQ.push({t.fi, t.se});
        }
        else{
            invalid[-t.se] = 1;
            while (!PQ.empty() && !PQ.top().valid()) PQ.pop();
            if (PQ.empty()) continue;
            lift[-t.se][0] = PQ.top().i;
        }
    }
    for (int i = 1; i < 20; ++i){
        for (int j = 1; j <= n; ++j){
            lift[j][i] = lift[lift[j][i - 1]][i - 1];
        }
    }
    while (q--){
        int s, t;
        cin >> s >> t;
        if (s == t){
            cout << "0\n"; continue;
        }
        if (e[t].se < e[s].se){
            cout << "impossible\n"; continue;
        }
        if (e[t].fi <= e[s].se){
            cout << "1\n"; continue;
        }
        int ans = 0;
        for (int i = 19; i >= 0; --i){
            if (e[lift[t][i]].fi > e[s].se){
                t = lift[t][i];
                ans += 1 << i;
            }
            t = lift[t][0];
            if (t == 0){
                cout << "impossible\n"; continue;
            }
        }
        cout << ans + 1 << "\n";
    }
}

#define debug
#define taskname "test"
signed main(){
    faster
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    int tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
        timeout.close();
        #ifndef debug
        cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
        #endif // debug
    }
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
events.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 146 ms 37236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -