# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1002114 |
2024-06-19T10:03:46 Z |
LOLOLO |
Fire (BOI24_fire) |
C++17 |
|
0 ms |
468 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (ll)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 4e5 + 10;
const int L = sqrt(N) + 10;
int nxt[N][20], is[N][20];
ll solve() {
int n, m;
cin >> n >> m;
map <int, int> mp;
mp[m];
vector <pair <int, int>> seg(n);
for (auto &x : seg) {
cin >> x.f >> x.s;
mp[x.s], mp[x.f];
}
int timer = 0;
for (auto &x : mp) {
timer++;
x.s = timer;
}
for (auto &x : seg) {
x.f = mp[x.f];
x.s = mp[x.s];
}
sort(all(seg));
int j = 0, ov = 0, mx = 0;
for (int i = 1; i <= timer; i++) {
while (j < sz(seg) && seg[j].f <= i) {
if (ov) {
if (seg[j].f > seg[j].s) {
mx = min(mx, seg[j].s);
}
} else {
if (seg[j].f > seg[j].s) {
ov = 1;
mx = seg[j].s;
} else {
mx = max(mx, seg[j].s);
}
}
j++;
}
if (mx) {
nxt[i][0] = mx;
is[i][0] = ov;
} else {
nxt[i][0] = 0;
}
}
for (int j = 1; j < 20; j++) {
for (int i = 1; i <= timer; i++) {
nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
is[i][j] = is[i][j - 1] | is[nxt[i][j - 1]][j - 1];
}
}
ll ans = 1e18;
for (auto x : seg) {
if (x.f > x.s)
continue;
int l = x.f, r = x.s;
ll cc = 1;
for (int j = 19; j >= 0; j--) {
if (is[r][j] == 0) {
r = nxt[r][j];
cc += (1 << j);
}
}
if (is[r][j] == 0)
continue;
r = nxt[r][j];
cc++;
for (int j = 19; j >= 0; j--) {
if (is[r][j] == 0 && nxt[r][j] < l) {
r = nxt[r][j];
cc += (1 << j);
}
}
if (is[r][0] || nxt[r][0] >= l) {
ans = min(ans, cc + 1);
}
}
if (ans > n)
return -1;
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
cout << solve() << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |