#include <bits/stdc++.h>
#define ar array
#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
vector<pll> qus;
int bin_search(ll p) {
int l=0, r=qus.size()-1, ans=-1;
while(l <= r) {
int mid = (l + r) / 2;
if(qus[mid].first <= p) ans = mid, l = mid + 1;
else r = mid - 1;
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, m, q; cin >> n >> m >> q;
ll day = 1;
vector<int> L(m), R(m);
for(int i=0; i<m; i++) cin >> L[i] >> R[i];
for(int i=0; i<q; i++) {
ll x; cin >> x;
qus.push_back({ x, i });
}
sort(qus.begin(), qus.end());
vector<ll> ans(q);
set<array<ll, 3> > s;
for(int i=0; i<m; i++) {
vector<array<ll, 3> > to_rem, to_add;
auto it = s.lower_bound({ L[i], 0, 0 });
if(it != s.begin()) --it;
while(it != s.end()) {
auto [l, r, x] = *it;
if(l > R[i]) break;
if(L[i] <= l && r <= R[i]) {
int p = bin_search(day + l - L[i] - x - 1);
if(p > -1) ans[p] += r - l + 1;
to_rem.push_back({ l, r, x });
} else if(l < L[i] && R[i] < r) {
int p = bin_search(day - (x + L[i] - l) - 1);
if(p > -1) ans[p] += R[i] - L[i] + 1;
to_rem.push_back({ l, r, x });
to_add.push_back({ l, L[i]-1, x });
to_add.push_back({ R[i]+1, r, R[i] + 1 - l + x});
} else if(l < L[i] && L[i] <= r && r <= R[i]) {
int p = bin_search(day - (x + L[i] - l) - 1);
if(p > -1) ans[p] += r - L[i] + 1;
to_rem.push_back({ l, r, x });
to_add.push_back({ l, L[i]-1, x });
} else if(L[i] <= l && l <= R[i] && R[i] < r) {
int p = bin_search(day + l - L[i] - x - 1);
if(p > -1) ans[p] += R[i] - l + 1;
to_rem.push_back({ l, r, x });
to_add.push_back({ R[i]+1, r, R[i] + 1 - l + x });
}
++it;
}
to_add.push_back({ L[i], R[i], day });
for(auto &x : to_rem) s.erase(x);
for(auto &x : to_add) s.insert(x);
day += R[i] - L[i] + 1;
}
for(int i=q-2; i>=0; i--) ans[i] += ans[i+1];
for(int i=0; i<q; i++) qus[i].first = ans[i];
sort(qus.begin(), qus.end(), [&](pll a, pll b) { return a.second < b.second; });
for(auto x : qus) cout << x.first << " ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
60 ms |
5532 KB |
Output is correct |
14 |
Correct |
53 ms |
5448 KB |
Output is correct |
15 |
Correct |
59 ms |
5388 KB |
Output is correct |
16 |
Correct |
56 ms |
5824 KB |
Output is correct |
17 |
Correct |
54 ms |
5424 KB |
Output is correct |
18 |
Correct |
57 ms |
5528 KB |
Output is correct |
19 |
Correct |
61 ms |
6076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
55 ms |
5544 KB |
Output is correct |
4 |
Correct |
56 ms |
5664 KB |
Output is correct |
5 |
Correct |
161 ms |
9968 KB |
Output is correct |
6 |
Correct |
120 ms |
8628 KB |
Output is correct |
7 |
Correct |
120 ms |
9412 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
60 ms |
5532 KB |
Output is correct |
14 |
Correct |
53 ms |
5448 KB |
Output is correct |
15 |
Correct |
59 ms |
5388 KB |
Output is correct |
16 |
Correct |
56 ms |
5824 KB |
Output is correct |
17 |
Correct |
54 ms |
5424 KB |
Output is correct |
18 |
Correct |
57 ms |
5528 KB |
Output is correct |
19 |
Correct |
61 ms |
6076 KB |
Output is correct |
20 |
Correct |
58 ms |
6852 KB |
Output is correct |
21 |
Correct |
54 ms |
5956 KB |
Output is correct |
22 |
Correct |
65 ms |
6844 KB |
Output is correct |
23 |
Correct |
54 ms |
6056 KB |
Output is correct |
24 |
Correct |
53 ms |
5552 KB |
Output is correct |
25 |
Correct |
53 ms |
5804 KB |
Output is correct |
26 |
Correct |
59 ms |
7040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
60 ms |
5532 KB |
Output is correct |
14 |
Correct |
53 ms |
5448 KB |
Output is correct |
15 |
Correct |
59 ms |
5388 KB |
Output is correct |
16 |
Correct |
56 ms |
5824 KB |
Output is correct |
17 |
Correct |
54 ms |
5424 KB |
Output is correct |
18 |
Correct |
57 ms |
5528 KB |
Output is correct |
19 |
Correct |
61 ms |
6076 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
55 ms |
5544 KB |
Output is correct |
23 |
Correct |
56 ms |
5664 KB |
Output is correct |
24 |
Correct |
161 ms |
9968 KB |
Output is correct |
25 |
Correct |
120 ms |
8628 KB |
Output is correct |
26 |
Correct |
120 ms |
9412 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
58 ms |
6852 KB |
Output is correct |
30 |
Correct |
54 ms |
5956 KB |
Output is correct |
31 |
Correct |
65 ms |
6844 KB |
Output is correct |
32 |
Correct |
54 ms |
6056 KB |
Output is correct |
33 |
Correct |
53 ms |
5552 KB |
Output is correct |
34 |
Correct |
53 ms |
5804 KB |
Output is correct |
35 |
Correct |
59 ms |
7040 KB |
Output is correct |
36 |
Correct |
278 ms |
10208 KB |
Output is correct |
37 |
Correct |
247 ms |
9840 KB |
Output is correct |
38 |
Correct |
191 ms |
8552 KB |
Output is correct |
39 |
Correct |
183 ms |
9344 KB |
Output is correct |
40 |
Correct |
246 ms |
13540 KB |
Output is correct |
41 |
Correct |
280 ms |
23612 KB |
Output is correct |
42 |
Correct |
280 ms |
24736 KB |
Output is correct |
43 |
Correct |
283 ms |
34016 KB |
Output is correct |
44 |
Correct |
277 ms |
35044 KB |
Output is correct |
45 |
Correct |
288 ms |
13128 KB |
Output is correct |
46 |
Correct |
378 ms |
15320 KB |
Output is correct |
47 |
Correct |
301 ms |
15448 KB |
Output is correct |
48 |
Correct |
204 ms |
13964 KB |
Output is correct |