답안 #653523

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653523 2022-10-27T07:14:52 Z prvocislo Event Hopping (BOI22_events) C++17
0 / 100
112 ms 22240 KB
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 2e5 + 5, logn = 18, inf = 1e9 + 5;
//const int maxn = 16, logn = 18, inf = 1e9 + 5;
vector<pair<int, int> > st(maxn * 2, { inf, inf });
int mini(int l, int r)
{
    pair<int, int> p = { inf, inf };
    for (l += maxn, r += maxn + 1; l < r; l >>= 1, r >>= 1)
    {
        if (l & 1) p = min(st[l++], p);
        if (r & 1) p = min(st[--r], p);
    }
    return p.second;
}
vector<vector<int> > l(logn, vector<int>(maxn, -1));
struct usek
{
    int l, r;
};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    vector<usek> u(n);
    vector<int> s;
    for (int i = 0; i < n; i++)
    {
        cin >> u[i].l >> u[i].r;
        s.push_back(u[i].l);
        s.push_back(u[i].r);
    }
    sort(s.begin(), s.end());
    for (int i = 0; i < n; i++)
    {
        u[i].l = lower_bound(s.begin(), s.end(), u[i].l) - s.begin();
        u[i].r = lower_bound(s.begin(), s.end(), u[i].r) - s.begin();
        st[maxn + u[i].r] = min(st[maxn + u[i].r], {u[i].l, i});
    }
    for (int i = maxn - 1; i > 0; i--) st[i] = min(st[i << 1], st[(i << 1) | 1]);
    for (int i = 0; i < n; i++)
    {
        int mi = mini(u[i].l, u[i].r);
        l[0][i] = mi;
    }
    for (int i = 0; i < n; i++) 
    {
        for (int j = 1; j < logn; j++) l[j][i] = l[j - 1][l[j - 1][i]];
    }
    while (q--)
    {
        int s, e;
        cin >> s >> e; 
        s--, e--;
        //cout << "                   ";
        if (s == e)
        {
            cout << "0\n";
            continue;
        }
        if (u[s].r > u[e].r)
        {
            cout << "impossible\n";
            continue;
        }
        if (u[e].l <= u[s].r)
        {
            cout << "1\n";
            continue;
        }
        int ans = 1;
        for (int j = logn - 1; j >= 0; j--)
        {
            if (u[l[j][e]].l > u[s].r) ans += (1 << j), e = l[j][e];
        }
        if (u[l[0][e]].l <= u[s].r) cout << ans + 1 << "\n";
        else cout << "impossible\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 18260 KB Output is correct
2 Incorrect 111 ms 22240 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 18260 KB Output is correct
2 Correct 8 ms 18264 KB Output is correct
3 Incorrect 9 ms 18260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 18260 KB Output is correct
2 Correct 8 ms 18264 KB Output is correct
3 Incorrect 9 ms 18260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 18260 KB Output is correct
2 Correct 8 ms 18264 KB Output is correct
3 Incorrect 9 ms 18260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 112 ms 22236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 18260 KB Output is correct
2 Incorrect 111 ms 22240 KB Output isn't correct
3 Halted 0 ms 0 KB -