-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboringseg.cpp
80 lines (60 loc) · 1.34 KB
/
boringseg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>
#include <atcoder/lazysegtree>
using namespace atcoder;
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using vb = vector<bool>;
ll min_v(ll a, ll b) {
return min(a, b);
}
ll e() {
return 0;
}
ll mapping(ll f, ll x) {
return f + x;
}
ll composition(ll f, ll g) {
return f + g;
}
ll id() {
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, m;
cin >> n >> m;
vector<array<ll, 3>> a(n);
for(ll i = 0; i < n; i++) {
cin >> a[i][1] >> a[i][2] >> a[i][0];
}
sort(a.begin(), a.end());
ll r = 0;
ll mn = 1e9;
lazy_segtree<ll, min_v, e, ll, mapping, composition, id> st;
function<bool(void)> conn = [&]() {
// get min on segtree and check if its > 0
return st.prod(0, m) > 0;
};
function<void(ll, ll)> add = [&](ll l, ll r) {
// add on [l, r]
st.apply(l, r, 1);
};
function<void(ll, ll)> rem = [&](ll l, ll r) {
// sub on [l, r]
st.apply(l, r, -1);
};
for (ll l = 0; l < n; l++) {
while(!conn() && r < n) {
add(a[r][1], a[r][2]);
r++;
}
if (conn()) mn = min(mn, a[r][0] - a[l][0]);
rem(a[l][1], a[l][2]);
l++;
}
return 0;
}