답안 #1112751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112751 2024-11-14T18:37:17 Z cpptowin Event Hopping (BOI22_events) C++17
100 / 100
142 ms 71360 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
// #define int long long
#define inf (int)1e8
#define bitcount(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ss(x) (int)x.size()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
void add(int &x, int k)
{
    x += k;
    x %= mod;
    if(x < 0) x += mod;
}
void del(int &x, int k)
{
    x -= k;
    x %= mod;
    if(x < 0) x += mod;
}
int n,q;
array<int,3> a[maxn];
pii rmq[maxn][20];
pii minn[maxn][20];
vi nen;
pii getmin(int l,int r) 
{
    int lg = __lg(r - l + 1);
    return min(minn[l][lg],minn[r - (1 << lg) + 1][lg]);
}
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> q;
    fo(i,1,n) 
    {
        cin >> a[i][0] >> a[i][1];
        nen.pb(a[i][0]);
        nen.pb(a[i][1]);
        a[i][2] = i;
    }
    sort(all(nen));UNIQUE(nen);
    fo(i,1,ss(nen)) fo(j,0,19) minn[i][j] = rmq[i][j] = {inf,inf};
    fo(i,1,n) 
    {
        a[i][0] = lower_bound(all(nen),a[i][0]) - nen.begin() + 1;
        a[i][1] = lower_bound(all(nen),a[i][1]) - nen.begin() + 1;
        minimize(minn[a[i][1]][0],make_pair(a[i][0],i));
    }
    fo(j,1,19) fo(i,1,ss(nen)) 
        minn[i][j] = min(minn[i][j - 1],minn[i + (1 << j - 1)][j - 1]);
    fo(i,1,n) 
    {
        rmq[i][0] = getmin(a[i][0],a[i][1]);
    }
    // cout << rmq[8][0].fi << ' ' << rmq[8][0].se;en;
    fo(j,1,19) fo(i,1,n) 
    {
        if(rmq[i][j - 1].fi == inf) continue;
        rmq[i][j] = rmq[rmq[i][j - 1].se][j - 1];
    }
    while(q--) 
    {
        int l,r;
        cin >> l >> r;
        if(a[r][1] < a[l][1]) 
        {
            cout << "impossible";en;
            continue;
        }
        if(l == r) 
        {
            cout << 0;en;
            continue;
        }
        if(a[r][0] <= a[l][1] and a[l][1] <= a[r][1])
        {
            cout << 1;en;
            continue;
        }
        int ans = 0;
        fod(i,19,0) if(rmq[r][i].fi != inf and rmq[r][i].fi > a[l][1]) 
        {
            ans += (1 << i);
            r = rmq[r][i].se;
            if(r == inf) break;
        }
        // cout << r;en;
        if(r != inf) 
        {
            r = rmq[r][0].se;
            ans++;
            if(r != inf and a[r][0] <= a[l][1] and a[r][1] >= a[l][1]) 
            {
                cout << ans + 1;en;
                continue;
            }
            else cout << "impossible \n";
        }
        else cout << "impossible\n";
    }
}

Compilation message

events.cpp:68:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   68 | main()
      | ^~~~
events.cpp: In function 'int main()':
events.cpp:95:58: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   95 |         minn[i][j] = min(minn[i][j - 1],minn[i + (1 << j - 1)][j - 1]);
      |                                                        ~~^~~
events.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
events.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 89 ms 39016 KB Output is correct
3 Correct 88 ms 39120 KB Output is correct
4 Correct 104 ms 39108 KB Output is correct
5 Correct 96 ms 44104 KB Output is correct
6 Correct 95 ms 47472 KB Output is correct
7 Correct 96 ms 47480 KB Output is correct
8 Correct 116 ms 71360 KB Output is correct
9 Correct 107 ms 69572 KB Output is correct
10 Correct 94 ms 41176 KB Output is correct
11 Correct 99 ms 51908 KB Output is correct
12 Correct 58 ms 39620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4688 KB Output is correct
4 Correct 1 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 2 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4688 KB Output is correct
4 Correct 1 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 2 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 2 ms 4688 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 1 ms 4688 KB Output is correct
15 Correct 2 ms 4688 KB Output is correct
16 Correct 2 ms 6736 KB Output is correct
17 Correct 2 ms 6736 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 24 ms 7344 KB Output is correct
20 Correct 22 ms 7248 KB Output is correct
21 Correct 26 ms 7496 KB Output is correct
22 Correct 22 ms 7752 KB Output is correct
23 Correct 20 ms 7504 KB Output is correct
24 Correct 19 ms 7504 KB Output is correct
25 Correct 25 ms 6992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4688 KB Output is correct
4 Correct 1 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 2 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 2 ms 4688 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 2 ms 4688 KB Output is correct
15 Correct 2 ms 4688 KB Output is correct
16 Correct 2 ms 6736 KB Output is correct
17 Correct 2 ms 6736 KB Output is correct
18 Correct 2 ms 4432 KB Output is correct
19 Correct 72 ms 37228 KB Output is correct
20 Correct 74 ms 37236 KB Output is correct
21 Correct 78 ms 38340 KB Output is correct
22 Correct 88 ms 48696 KB Output is correct
23 Correct 125 ms 68612 KB Output is correct
24 Correct 123 ms 68548 KB Output is correct
25 Correct 31 ms 21620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 37824 KB Output is correct
2 Correct 107 ms 37828 KB Output is correct
3 Correct 110 ms 37828 KB Output is correct
4 Correct 140 ms 70604 KB Output is correct
5 Correct 133 ms 38084 KB Output is correct
6 Correct 137 ms 69316 KB Output is correct
7 Correct 133 ms 69236 KB Output is correct
8 Correct 132 ms 70340 KB Output is correct
9 Correct 109 ms 68548 KB Output is correct
10 Correct 126 ms 68812 KB Output is correct
11 Correct 118 ms 70432 KB Output is correct
12 Correct 129 ms 70596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 89 ms 39016 KB Output is correct
3 Correct 88 ms 39120 KB Output is correct
4 Correct 104 ms 39108 KB Output is correct
5 Correct 96 ms 44104 KB Output is correct
6 Correct 95 ms 47472 KB Output is correct
7 Correct 96 ms 47480 KB Output is correct
8 Correct 116 ms 71360 KB Output is correct
9 Correct 107 ms 69572 KB Output is correct
10 Correct 94 ms 41176 KB Output is correct
11 Correct 99 ms 51908 KB Output is correct
12 Correct 58 ms 39620 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 2 ms 4688 KB Output is correct
16 Correct 1 ms 4688 KB Output is correct
17 Correct 2 ms 4688 KB Output is correct
18 Correct 2 ms 4688 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 2 ms 6736 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 2 ms 4688 KB Output is correct
25 Correct 2 ms 4688 KB Output is correct
26 Correct 1 ms 4688 KB Output is correct
27 Correct 2 ms 4688 KB Output is correct
28 Correct 2 ms 6736 KB Output is correct
29 Correct 2 ms 6736 KB Output is correct
30 Correct 1 ms 4432 KB Output is correct
31 Correct 24 ms 7344 KB Output is correct
32 Correct 22 ms 7248 KB Output is correct
33 Correct 26 ms 7496 KB Output is correct
34 Correct 22 ms 7752 KB Output is correct
35 Correct 20 ms 7504 KB Output is correct
36 Correct 19 ms 7504 KB Output is correct
37 Correct 25 ms 6992 KB Output is correct
38 Correct 1 ms 4432 KB Output is correct
39 Correct 1 ms 4432 KB Output is correct
40 Correct 2 ms 4688 KB Output is correct
41 Correct 2 ms 4688 KB Output is correct
42 Correct 2 ms 4688 KB Output is correct
43 Correct 2 ms 4688 KB Output is correct
44 Correct 2 ms 6736 KB Output is correct
45 Correct 2 ms 6736 KB Output is correct
46 Correct 2 ms 4432 KB Output is correct
47 Correct 72 ms 37228 KB Output is correct
48 Correct 74 ms 37236 KB Output is correct
49 Correct 78 ms 38340 KB Output is correct
50 Correct 88 ms 48696 KB Output is correct
51 Correct 125 ms 68612 KB Output is correct
52 Correct 123 ms 68548 KB Output is correct
53 Correct 31 ms 21620 KB Output is correct
54 Correct 106 ms 37824 KB Output is correct
55 Correct 107 ms 37828 KB Output is correct
56 Correct 110 ms 37828 KB Output is correct
57 Correct 140 ms 70604 KB Output is correct
58 Correct 133 ms 38084 KB Output is correct
59 Correct 137 ms 69316 KB Output is correct
60 Correct 133 ms 69236 KB Output is correct
61 Correct 132 ms 70340 KB Output is correct
62 Correct 109 ms 68548 KB Output is correct
63 Correct 126 ms 68812 KB Output is correct
64 Correct 118 ms 70432 KB Output is correct
65 Correct 129 ms 70596 KB Output is correct
66 Correct 2 ms 4432 KB Output is correct
67 Correct 94 ms 39112 KB Output is correct
68 Correct 105 ms 37996 KB Output is correct
69 Correct 106 ms 37996 KB Output is correct
70 Correct 100 ms 40904 KB Output is correct
71 Correct 107 ms 44740 KB Output is correct
72 Correct 109 ms 44740 KB Output is correct
73 Correct 130 ms 69572 KB Output is correct
74 Correct 119 ms 69576 KB Output is correct
75 Correct 103 ms 38216 KB Output is correct
76 Correct 117 ms 50636 KB Output is correct
77 Correct 60 ms 38600 KB Output is correct
78 Correct 2 ms 4432 KB Output is correct
79 Correct 2 ms 4688 KB Output is correct
80 Correct 2 ms 4688 KB Output is correct
81 Correct 2 ms 4688 KB Output is correct
82 Correct 2 ms 4688 KB Output is correct
83 Correct 2 ms 6748 KB Output is correct
84 Correct 2 ms 6736 KB Output is correct
85 Correct 1 ms 4432 KB Output is correct
86 Correct 26 ms 7384 KB Output is correct
87 Correct 23 ms 7248 KB Output is correct
88 Correct 31 ms 8488 KB Output is correct
89 Correct 29 ms 7768 KB Output is correct
90 Correct 20 ms 7504 KB Output is correct
91 Correct 19 ms 7504 KB Output is correct
92 Correct 23 ms 7760 KB Output is correct
93 Correct 81 ms 38596 KB Output is correct
94 Correct 63 ms 37560 KB Output is correct
95 Correct 73 ms 37264 KB Output is correct
96 Correct 80 ms 48580 KB Output is correct
97 Correct 123 ms 69572 KB Output is correct
98 Correct 110 ms 68548 KB Output is correct
99 Correct 23 ms 21836 KB Output is correct
100 Correct 133 ms 71280 KB Output is correct
101 Correct 125 ms 69324 KB Output is correct
102 Correct 121 ms 69316 KB Output is correct
103 Correct 142 ms 68804 KB Output is correct
104 Correct 122 ms 68808 KB Output is correct
105 Correct 140 ms 68804 KB Output is correct
106 Correct 80 ms 36552 KB Output is correct
107 Correct 95 ms 39876 KB Output is correct
108 Correct 88 ms 38084 KB Output is correct
109 Correct 91 ms 39876 KB Output is correct
110 Correct 124 ms 69316 KB Output is correct
111 Correct 137 ms 69060 KB Output is correct