#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector<int> l(m), r(m);
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i];
}
set<array<long long, 3>> st;
for (int i = 1; i <= n; i++) {
// st.insert({i, i, -1 - i});
}
long long s = 0;
vector<pair<long long, int>> ev;
for (int i = 0; i < m; i++) {
while (true) {
auto it = st.lower_bound({l[i], -1, -1});
if (it == st.end() || (*it)[1] > r[i]) {
break;
}
array<long long, 3> v = *it;
st.erase(it);
if (v[1] < l[i]) {
st.insert({l[i] - 1, v[1], v[2]});
}
if (v[0] > r[i]) {
st.insert({v[0], r[i] + 1, v[2]});
}
int id = min(r[i], (int) v[0]);
long long cur = s + id - l[i];
long long bef = v[2] + id;
ev.emplace_back(cur - bef - 1, min(r[i], (int) v[0]) - max(l[i], (int) v[1]) + 1);
}
st.insert({r[i], l[i], s - l[i]});
s += r[i] - l[i] + 1;
}
/* for (auto& p : ev) {
cout << p.first << " " << p.second << '\n';
} */
vector<long long> x(q);
for (int i = 0; i < q; i++) {
cin >> x[i];
}
sort(ev.rbegin(), ev.rend());
vector<int> order(q);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
return x[i] > x[j];
});
int ptr = 0;
vector<long long> res(q);
long long total = 0;
for (int i : order) {
while (ptr < (int) ev.size() && ev[ptr].first >= x[i]) {
total += ev[ptr].second;
ptr += 1;
}
res[i] = total;
}
for (int i = 0; i < q; i++) {
cout << res[i] << " ";
}
return 0;
}
/*
5 3 7
1 3
3 5
2 3
0 1 2 3 4 5 6
6 6 7
1 6
1 5
1 4
1 3
1 2
1 1
1 2 3 4 5 6 7
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
1 ms |
356 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
1 ms |
356 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 |
41 ms |
6348 KB |
Output is correct |
14 |
Correct |
43 ms |
6232 KB |
Output is correct |
15 |
Correct |
44 ms |
6380 KB |
Output is correct |
16 |
Correct |
45 ms |
6592 KB |
Output is correct |
17 |
Correct |
52 ms |
6476 KB |
Output is correct |
18 |
Correct |
47 ms |
6252 KB |
Output is correct |
19 |
Correct |
48 ms |
6536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
48 ms |
6224 KB |
Output is correct |
4 |
Correct |
43 ms |
7024 KB |
Output is correct |
5 |
Correct |
132 ms |
16928 KB |
Output is correct |
6 |
Correct |
126 ms |
16596 KB |
Output is correct |
7 |
Correct |
93 ms |
13776 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
1 ms |
356 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 |
41 ms |
6348 KB |
Output is correct |
14 |
Correct |
43 ms |
6232 KB |
Output is correct |
15 |
Correct |
44 ms |
6380 KB |
Output is correct |
16 |
Correct |
45 ms |
6592 KB |
Output is correct |
17 |
Correct |
52 ms |
6476 KB |
Output is correct |
18 |
Correct |
47 ms |
6252 KB |
Output is correct |
19 |
Correct |
48 ms |
6536 KB |
Output is correct |
20 |
Correct |
46 ms |
7636 KB |
Output is correct |
21 |
Correct |
47 ms |
6692 KB |
Output is correct |
22 |
Correct |
65 ms |
7640 KB |
Output is correct |
23 |
Correct |
44 ms |
6740 KB |
Output is correct |
24 |
Correct |
41 ms |
6228 KB |
Output is correct |
25 |
Correct |
44 ms |
6864 KB |
Output is correct |
26 |
Correct |
42 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
1 ms |
356 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 |
41 ms |
6348 KB |
Output is correct |
14 |
Correct |
43 ms |
6232 KB |
Output is correct |
15 |
Correct |
44 ms |
6380 KB |
Output is correct |
16 |
Correct |
45 ms |
6592 KB |
Output is correct |
17 |
Correct |
52 ms |
6476 KB |
Output is correct |
18 |
Correct |
47 ms |
6252 KB |
Output is correct |
19 |
Correct |
48 ms |
6536 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
48 ms |
6224 KB |
Output is correct |
23 |
Correct |
43 ms |
7024 KB |
Output is correct |
24 |
Correct |
132 ms |
16928 KB |
Output is correct |
25 |
Correct |
126 ms |
16596 KB |
Output is correct |
26 |
Correct |
93 ms |
13776 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
46 ms |
7636 KB |
Output is correct |
30 |
Correct |
47 ms |
6692 KB |
Output is correct |
31 |
Correct |
65 ms |
7640 KB |
Output is correct |
32 |
Correct |
44 ms |
6740 KB |
Output is correct |
33 |
Correct |
41 ms |
6228 KB |
Output is correct |
34 |
Correct |
44 ms |
6864 KB |
Output is correct |
35 |
Correct |
42 ms |
7508 KB |
Output is correct |
36 |
Correct |
186 ms |
20768 KB |
Output is correct |
37 |
Correct |
212 ms |
21156 KB |
Output is correct |
38 |
Correct |
192 ms |
21176 KB |
Output is correct |
39 |
Correct |
147 ms |
17180 KB |
Output is correct |
40 |
Correct |
216 ms |
21168 KB |
Output is correct |
41 |
Correct |
263 ms |
26316 KB |
Output is correct |
42 |
Correct |
248 ms |
27076 KB |
Output is correct |
43 |
Correct |
296 ms |
30380 KB |
Output is correct |
44 |
Correct |
292 ms |
30128 KB |
Output is correct |
45 |
Correct |
257 ms |
21184 KB |
Output is correct |
46 |
Correct |
289 ms |
20412 KB |
Output is correct |
47 |
Correct |
276 ms |
20848 KB |
Output is correct |
48 |
Correct |
195 ms |
21304 KB |
Output is correct |