Submission #779573

# Submission time Handle Problem Language Result Execution time Memory
779573 2023-07-11T14:28:23 Z CpDark Event Hopping (BOI22_events) C++14
30 / 100
134 ms 17488 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll inf = 1e18 + 7;

vvp table;
vp events;
vector<pair<int,pii>> endTimes;
int mylog;

int query(int start, int end) {
    if (events[start].second > events[end].second)return -1;
    if (start == end)return 0;
    int wall = events[start].second;
    int jumps = 1;
    if (events[end].first <= wall && wall <= events[end].second) return jumps;
    
    for (int i = mylog;i >= 0;i--) {
        if (events[table[i][end].first].first > wall) {
            jumps += 1 << i;
            end = table[i][end].first;
        }
    }
    jumps++;
    end = table[0][end].first;
    if (events[end].first <= wall && wall <= events[end].second)return jumps;
    return -1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, q;
    cin >> n >> q;
    mylog = ceil(log2(n + 1));
    events.resize(n);
    endTimes.resize(n);
    table.resize(mylog + 1, vp(n));
    
    for (int i = 0;i < n;i++) {
        cin >> events[i].first >> events[i].second;
        endTimes[i] = { events[i].second, {events[i].first, i} };
    }
 
    sort(endTimes.begin(), endTimes.end());
 
    for (int i = 0;i < endTimes.size();i++) {
        int index = endTimes[i].second.second;
        int far = lower_bound(endTimes.begin(), endTimes.end(), (pair<int, pii>){ events[index].first, make_pair(-1,-1)}) - endTimes.begin();
        table[0][index] = { endTimes[far].second.second, endTimes[far].first};
    }
 
    for (int i = 1;i <= mylog;i++) {
        for (int v = 0;v < n;v++) {
            int p = table[i - 1][v].first;
            table[i][v] = table[i - 1][p];
        }
    }
 
    int s, e;
    for (int i = 0;i < q;i++) {
        cin >> s >> e;
        s--; e--;
        int ans = query(s, e);
        if (ans == -1) {
            cout << "impossible\n";
        }
        else {
            cout << ans << '\n';
        }
    }
 
    return 0;
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i = 0;i < endTimes.size();i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 68 ms 17108 KB Output is correct
3 Correct 70 ms 17152 KB Output is correct
4 Correct 134 ms 17108 KB Output is correct
5 Correct 88 ms 17136 KB Output is correct
6 Correct 88 ms 17172 KB Output is correct
7 Correct 109 ms 17220 KB Output is correct
8 Correct 93 ms 17408 KB Output is correct
9 Correct 91 ms 17448 KB Output is correct
10 Correct 78 ms 17312 KB Output is correct
11 Correct 80 ms 17340 KB Output is correct
12 Correct 54 ms 17448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 17124 KB Output is correct
2 Correct 74 ms 17108 KB Output is correct
3 Correct 104 ms 17108 KB Output is correct
4 Correct 91 ms 17488 KB Output is correct
5 Correct 76 ms 17324 KB Output is correct
6 Correct 96 ms 17192 KB Output is correct
7 Correct 76 ms 17148 KB Output is correct
8 Correct 72 ms 17192 KB Output is correct
9 Correct 33 ms 17108 KB Output is correct
10 Correct 72 ms 17108 KB Output is correct
11 Correct 69 ms 17108 KB Output is correct
12 Correct 81 ms 17108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 68 ms 17108 KB Output is correct
3 Correct 70 ms 17152 KB Output is correct
4 Correct 134 ms 17108 KB Output is correct
5 Correct 88 ms 17136 KB Output is correct
6 Correct 88 ms 17172 KB Output is correct
7 Correct 109 ms 17220 KB Output is correct
8 Correct 93 ms 17408 KB Output is correct
9 Correct 91 ms 17448 KB Output is correct
10 Correct 78 ms 17312 KB Output is correct
11 Correct 80 ms 17340 KB Output is correct
12 Correct 54 ms 17448 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 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 Incorrect 1 ms 340 KB Output isn't correct
19 Halted 0 ms 0 KB -