// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T& x, T y) {x = min(x, y);}
template <typename T> inline void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
const int N = 2e5 + 10;//, inf = 1e9;
const ll INF = 1e18;
int n, m, q, l[N], r[N];
ll sum;
pair <ll, int> qq[N];
set <pair <pair <int, int>, ll>> s;
auto split(int x) { // x - 1 x
auto it = s.lower_bound(make_pair(make_pair(x, 0), 0));
if (it == s.begin()) return it;
it--;
if (it -> first.first < x && it -> first.second >= x) {
auto g = *it;
s.erase(it);
s.emplace(make_pair(g.first.first, x - 1), g.second);
return s.emplace(make_pair(x, g.first.second), g.second).first;
}
return next(it);
}
vector <pair <ll, int>> v;
void dot(int x, ll y) {
v.emplace_back(y, x);
}
void ins(int l, int r, ll g) {
auto tr = split(r + 1), tl = split(l);
// if (r != 6) {
// debug << tl -> first.first << " " << tl -> first.second << endl;
// debug << tr -> first.first << " " << tr -> first.second << endl;
// }
// for (auto [a, b]: s) debug << a.first << " " << a.second << " : " << b << endl; debug << endl;
while (tl != tr) {
// debug << tl -> first.first << " " << tl -> first.second << endl;
dot(tl -> first.second - tl -> first.first + 1, g - tl -> second);
tl = s.erase(tl);
}
s.emplace(make_pair(l, r), g);
}
int pos;
ll e, ans[N];
signed main() {
read(n), read(m), read(q);
// s.emplace(make_pair(1, n), -INF);
F(i, 1, m) {
read(l[i]), read(r[i]);
ins(l[i], r[i], sum - l[i] + 1);
sum += r[i] - l[i] + 1;
}
F(i, 1, q) read(qq[i].first), qq[i].second = i;
sort(qq + 1, qq + q + 1);
sort(v.rbegin(), v.rend());
// for (auto [a, b]: v) cout << a << " " << b << endl;
DF(i, q, 1) {
while (pos <= SZ(v) && v[pos].first > qq[i].first) {
e += v[pos].second;
pos++;
}
// debug << qq[i].first << " " << e << endl;
ans[qq[i].second] = e;
}
F(i, 1, q) cout << ans[i] << ' ';
return 0;
}
/* why?
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2504 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2504 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
34 ms |
7256 KB |
Output is correct |
14 |
Correct |
32 ms |
6996 KB |
Output is correct |
15 |
Correct |
33 ms |
7252 KB |
Output is correct |
16 |
Correct |
34 ms |
7504 KB |
Output is correct |
17 |
Correct |
33 ms |
6996 KB |
Output is correct |
18 |
Correct |
33 ms |
6996 KB |
Output is correct |
19 |
Correct |
35 ms |
7256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
33 ms |
7032 KB |
Output is correct |
4 |
Correct |
36 ms |
7764 KB |
Output is correct |
5 |
Correct |
113 ms |
19556 KB |
Output is correct |
6 |
Correct |
118 ms |
18812 KB |
Output is correct |
7 |
Correct |
86 ms |
14728 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2504 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
34 ms |
7256 KB |
Output is correct |
14 |
Correct |
32 ms |
6996 KB |
Output is correct |
15 |
Correct |
33 ms |
7252 KB |
Output is correct |
16 |
Correct |
34 ms |
7504 KB |
Output is correct |
17 |
Correct |
33 ms |
6996 KB |
Output is correct |
18 |
Correct |
33 ms |
6996 KB |
Output is correct |
19 |
Correct |
35 ms |
7256 KB |
Output is correct |
20 |
Correct |
35 ms |
8392 KB |
Output is correct |
21 |
Correct |
33 ms |
7428 KB |
Output is correct |
22 |
Correct |
34 ms |
8276 KB |
Output is correct |
23 |
Correct |
33 ms |
7508 KB |
Output is correct |
24 |
Correct |
33 ms |
6940 KB |
Output is correct |
25 |
Correct |
35 ms |
7760 KB |
Output is correct |
26 |
Correct |
36 ms |
8384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2504 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
34 ms |
7256 KB |
Output is correct |
14 |
Correct |
32 ms |
6996 KB |
Output is correct |
15 |
Correct |
33 ms |
7252 KB |
Output is correct |
16 |
Correct |
34 ms |
7504 KB |
Output is correct |
17 |
Correct |
33 ms |
6996 KB |
Output is correct |
18 |
Correct |
33 ms |
6996 KB |
Output is correct |
19 |
Correct |
35 ms |
7256 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
33 ms |
7032 KB |
Output is correct |
23 |
Correct |
36 ms |
7764 KB |
Output is correct |
24 |
Correct |
113 ms |
19556 KB |
Output is correct |
25 |
Correct |
118 ms |
18812 KB |
Output is correct |
26 |
Correct |
86 ms |
14728 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
35 ms |
8392 KB |
Output is correct |
30 |
Correct |
33 ms |
7428 KB |
Output is correct |
31 |
Correct |
34 ms |
8276 KB |
Output is correct |
32 |
Correct |
33 ms |
7508 KB |
Output is correct |
33 |
Correct |
33 ms |
6940 KB |
Output is correct |
34 |
Correct |
35 ms |
7760 KB |
Output is correct |
35 |
Correct |
36 ms |
8384 KB |
Output is correct |
36 |
Correct |
189 ms |
23472 KB |
Output is correct |
37 |
Correct |
187 ms |
23060 KB |
Output is correct |
38 |
Correct |
185 ms |
24244 KB |
Output is correct |
39 |
Correct |
133 ms |
19376 KB |
Output is correct |
40 |
Correct |
211 ms |
24748 KB |
Output is correct |
41 |
Correct |
240 ms |
28848 KB |
Output is correct |
42 |
Correct |
260 ms |
30448 KB |
Output is correct |
43 |
Correct |
276 ms |
32940 KB |
Output is correct |
44 |
Correct |
282 ms |
32036 KB |
Output is correct |
45 |
Correct |
221 ms |
24228 KB |
Output is correct |
46 |
Correct |
259 ms |
21164 KB |
Output is correct |
47 |
Correct |
268 ms |
21512 KB |
Output is correct |
48 |
Correct |
189 ms |
24492 KB |
Output is correct |