You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Description: 1D point update, range query where \texttt{comb} is
110
142
* any associative operation. If $N=2^p$ then \texttt{seg[1]==query(0,N-1)}.
@@ -139,27 +171,31 @@ template <class T> struct Seg { // comb(ID,b) = b
139
171
}
140
172
};
141
173
174
+
const int MX = 1e5 + 5;
142
175
Seg<int> S;
143
176
int N, P;
144
177
int ans[MX];
145
178
vi distinct_y;
146
179
147
180
int query_min(int ind) { return S.query(0, ind); }
148
181
void ins(int ind, int val) { S.upd(ind, val); }
149
-
int y_index(int y) { return lb(all(distinct_y), y) - begin(distinct_y); }
182
+
int y_index(int y) { return lower_bound(all(distinct_y), y) - begin(distinct_y); }
150
183
151
184
int main() {
152
-
setIO("boards");
185
+
ios_base::sync_with_stdio(0); cin.tie(0);
186
+
freopen("boards.in", "r", stdin);
187
+
freopen("boards.out", "w", stdout);
153
188
cin>>N>>P;
154
189
vector<pair<pair<int, int>, pair<int, int>>> ev;
155
190
for (inti=0; i < P; ++i) {
156
191
pair<int, int>a, b;
157
192
cin>>a.f>>a.s>>b.f>>b.s;
158
-
ev.push_back({a, {i, -1}}); // start point
159
-
ev.push_back({b, {i, 1}}); // end point
193
+
ev.pb({a, {i, -1}}); // start point
194
+
ev.pb({b, {i, 1}}); // end point
160
195
distinct_y.pb(a.s);
161
196
distinct_y.pb(b.s);
162
197
}
198
+
163
199
sort(all(distinct_y));
164
200
sort(begin(ev), end(ev));
165
201
S.init(2 * P);
@@ -175,6 +211,19 @@ int main() {
175
211
}
176
212
```
177
213
214
+
Bonus: Think of this problem as maximizing the distance covered by springboards to simplify the solution.
215
+
216
+
## Different Approach - Springboards
217
+
It turns out there is also a simpler though less straightforward method to solve this problem.
218
+
219
+
The problem boils down to having a data structure that supports the following
220
+
operations:
221
+
222
+
1. Add a pair $(a,b)$.
223
+
2. For any $x$, query the minimum value of $b$ over all pairs satisfying
224
+
$a\le x$.
225
+
226
+
This solution is described in the [official editorial](https://usaco.org/current/data/sol_boards_gold_jan20.html) and the [other module](/adv/springboards).
0 commit comments