답안 #588979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588979 2022-07-04T08:27:44 Z ParsaEs Event Hopping (BOI22_events) C++14
50 / 100
1500 ms 6272 KB
//InTheNameOfGOD
//PRS;)
#pragma GCC optimize("unroll-loops", "Ofast", "O3")
#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, l, r) for(ll i = l; i < r; i++)
#define min(x, y) (x < y ? x : y)
#define max(x, y) (x > y ? x : y)
#define X first
#define Y second
typedef int ll;
using namespace std;
typedef pair<ll, ll> pl;
typedef pair<ll, pl> pi;
constexpr ll inf = 2e9, xn = 1e5 + 5, s = 317;
ll d[xn], p[xn], sx[xn], x[xn], m[s];
pi e[xn];
int main()
{
    Fast
    ll n, q;
    cin >> n >> q;
    rep(i, 0, n) cin >> e[i].Y.X >> e[i].X;
    rep(i, 0, n) e[i] = {-e[i].X, {-e[i].Y.X, i}};
    sort(e, e + n);
    rep(i, 0, s) m[i] = -inf;
    rep(i, 0, n)
    {
        sx[i] = x[i] = -1;
        rep(j, 0, i / s + 1) if(e[i].X <= m[j])
        {
            rep(k, j * s, min((j + 1) * s, i)) if(e[i].X <= e[k].Y.X)
            {
                if(k / s < i / s) sx[i] = k, d[i] = 1;
                else if(sx[k] >= 0) sx[i] = sx[k], d[i] = d[k] + 1;
                x[i] = k;
                break;
            }
            break;
        }
        m[i / s] = max(e[i].Y.X, m[i / s]), p[e[i].Y.Y] = i;
    }
    while(q--)
    {
        ll l, r, ans = 0;
        cin >> l >> r;
        if(l == r)
        {
            cout << "0\n";
            continue;
        }
        l = p[l - 1], r = p[r - 1];
        if(e[l].X < e[r].X)
        {
            cout << "impossible\n";
            continue;
        }
        if(e[l].X == e[r].X)
        {
            cout << "1\n";
            continue;
        }
        while(sx[l] >= r) ans += d[l], l = sx[l];
        while(x[l] >= r) l = x[l], ans++;
        if(r == l)
        {
            cout << ans << '\n';
            continue;
        }
        if(e[r].X == e[l].X)
        {
            cout << ans + 1 << '\n';
            continue;
        }
        ll z = e[r].Y.X, mx = e[r].Y.X;
        bool f = 1;
        rep(i, r + 1, l + 1)
        {
            if(z < e[i].X && mx < e[i].X)
            {
                f = 0;
                break;
            }
            if(z < e[i].X) z = mx, ans++;
            mx = max(mx, e[i].Y.X);
        }
        if(f) cout << ans + 1 << '\n';
        else cout << "impossible\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 281 ms 3812 KB Output is correct
3 Correct 241 ms 4528 KB Output is correct
4 Correct 181 ms 4844 KB Output is correct
5 Correct 254 ms 4964 KB Output is correct
6 Correct 275 ms 6072 KB Output is correct
7 Correct 264 ms 5376 KB Output is correct
8 Correct 80 ms 5644 KB Output is correct
9 Correct 61 ms 6044 KB Output is correct
10 Correct 914 ms 6172 KB Output is correct
11 Correct 1418 ms 5568 KB Output is correct
12 Correct 52 ms 4816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 360 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 436 ms 1324 KB Output is correct
20 Correct 74 ms 1760 KB Output is correct
21 Correct 123 ms 1852 KB Output is correct
22 Correct 92 ms 2144 KB Output is correct
23 Correct 109 ms 1784 KB Output is correct
24 Correct 125 ms 1664 KB Output is correct
25 Correct 34 ms 1252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 47 ms 4592 KB Output is correct
20 Correct 34 ms 3352 KB Output is correct
21 Correct 42 ms 3432 KB Output is correct
22 Correct 45 ms 3304 KB Output is correct
23 Correct 34 ms 3540 KB Output is correct
24 Correct 44 ms 3832 KB Output is correct
25 Correct 24 ms 3076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 241 ms 4132 KB Output is correct
2 Correct 200 ms 6128 KB Output is correct
3 Correct 149 ms 4920 KB Output is correct
4 Correct 66 ms 4264 KB Output is correct
5 Correct 765 ms 4908 KB Output is correct
6 Correct 101 ms 4256 KB Output is correct
7 Correct 110 ms 4208 KB Output is correct
8 Correct 875 ms 6272 KB Output is correct
9 Correct 34 ms 3416 KB Output is correct
10 Correct 185 ms 5032 KB Output is correct
11 Execution timed out 1519 ms 4356 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 281 ms 3812 KB Output is correct
3 Correct 241 ms 4528 KB Output is correct
4 Correct 181 ms 4844 KB Output is correct
5 Correct 254 ms 4964 KB Output is correct
6 Correct 275 ms 6072 KB Output is correct
7 Correct 264 ms 5376 KB Output is correct
8 Correct 80 ms 5644 KB Output is correct
9 Correct 61 ms 6044 KB Output is correct
10 Correct 914 ms 6172 KB Output is correct
11 Correct 1418 ms 5568 KB Output is correct
12 Correct 52 ms 4816 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1 ms 360 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 436 ms 1324 KB Output is correct
32 Correct 74 ms 1760 KB Output is correct
33 Correct 123 ms 1852 KB Output is correct
34 Correct 92 ms 2144 KB Output is correct
35 Correct 109 ms 1784 KB Output is correct
36 Correct 125 ms 1664 KB Output is correct
37 Correct 34 ms 1252 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 47 ms 4592 KB Output is correct
48 Correct 34 ms 3352 KB Output is correct
49 Correct 42 ms 3432 KB Output is correct
50 Correct 45 ms 3304 KB Output is correct
51 Correct 34 ms 3540 KB Output is correct
52 Correct 44 ms 3832 KB Output is correct
53 Correct 24 ms 3076 KB Output is correct
54 Correct 241 ms 4132 KB Output is correct
55 Correct 200 ms 6128 KB Output is correct
56 Correct 149 ms 4920 KB Output is correct
57 Correct 66 ms 4264 KB Output is correct
58 Correct 765 ms 4908 KB Output is correct
59 Correct 101 ms 4256 KB Output is correct
60 Correct 110 ms 4208 KB Output is correct
61 Correct 875 ms 6272 KB Output is correct
62 Correct 34 ms 3416 KB Output is correct
63 Correct 185 ms 5032 KB Output is correct
64 Execution timed out 1519 ms 4356 KB Time limit exceeded
65 Halted 0 ms 0 KB -