#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <array>
#include <cassert>
using namespace std;
using ll = long long;
const int mxn = 2e5+5;
int n, m, q;
int l[mxn], r[mxn];
ll s[mxn], ans[mxn];
struct Interval {
int l, r;
long long t;
bool operator<(const Interval& other) const {
return r < other.r;
}
array<Interval, 2> cut(int m, bool right_cut) {
return {Interval{l, m-right_cut, t}, Interval{m+1-right_cut, r, t+m-l+1-right_cut}};
}
pair<ll, ll> eat(Interval top) {
assert(top.l <= l && r <= top.r);
pair<ll, ll> info; info.second = r-l+1;
info.first = (l-top.l)+(top.t-t);
return info;
}
};
int main(int argc, char const *argv[]) {
cin >> n >> m >> q;
for(int i = 1; i <= m; i++) {
cin >> l[i] >> r[i];
}
for(int i = 1; i <= q; i++) {
cin >> s[i];
}
// using intervals find largest s such that all s* s.t. s*<=s increase
map<ll, ll> inc;
set<Interval> ints;
long long t = 0;
for(int i = 1; i <= m; i++) {
Interval curr{l[i], r[i], t};
auto it = ints.lower_bound(Interval{-1000, l[i]});
while(it != ints.end() && it->l <= r[i]) {
Interval last = *it;
ints.erase(it);
if(curr.l <= last.l && last.r <= curr.r) {
auto leftovers = last.eat(curr);
inc[leftovers.first-1] += leftovers.second;
}
else {
auto parts = last.cut((last.r > curr.r ? curr.r : curr.l), !(last.r > curr.r));
ints.insert(parts[0]);
ints.insert(parts[1]);
}
it = ints.lower_bound(Interval{-1000, l[i]});
}
ints.insert(curr);
t += r[i]-l[i]+1;
}
// accumulate answers
vector<int> dec_s(q); iota(dec_s.begin(), dec_s.end(), 1);
sort(dec_s.begin(), dec_s.end(), [&](int i, int j) { return s[i] > s[j];});
ll sum = 0;
auto it = inc.rbegin();
for(int i = 0; i < q; i++) {
int j = dec_s[i];
while(it != inc.rend() && it->first >= s[j]) {
sum += it->second;
it++;
}
ans[j] = sum;
}
for(int i = 1; i <= q; i++) cout << ans[i] << " ";
cout << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
80 ms |
4948 KB |
Output is correct |
14 |
Correct |
72 ms |
4524 KB |
Output is correct |
15 |
Correct |
76 ms |
4804 KB |
Output is correct |
16 |
Correct |
86 ms |
5056 KB |
Output is correct |
17 |
Correct |
76 ms |
4792 KB |
Output is correct |
18 |
Correct |
77 ms |
4804 KB |
Output is correct |
19 |
Correct |
71 ms |
5264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
77 ms |
4776 KB |
Output is correct |
4 |
Correct |
86 ms |
5068 KB |
Output is correct |
5 |
Correct |
403 ms |
24808 KB |
Output is correct |
6 |
Correct |
435 ms |
23520 KB |
Output is correct |
7 |
Correct |
228 ms |
19548 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
80 ms |
4948 KB |
Output is correct |
14 |
Correct |
72 ms |
4524 KB |
Output is correct |
15 |
Correct |
76 ms |
4804 KB |
Output is correct |
16 |
Correct |
86 ms |
5056 KB |
Output is correct |
17 |
Correct |
76 ms |
4792 KB |
Output is correct |
18 |
Correct |
77 ms |
4804 KB |
Output is correct |
19 |
Correct |
71 ms |
5264 KB |
Output is correct |
20 |
Correct |
77 ms |
6224 KB |
Output is correct |
21 |
Correct |
84 ms |
5244 KB |
Output is correct |
22 |
Correct |
94 ms |
6104 KB |
Output is correct |
23 |
Correct |
77 ms |
5272 KB |
Output is correct |
24 |
Correct |
78 ms |
4912 KB |
Output is correct |
25 |
Correct |
86 ms |
5124 KB |
Output is correct |
26 |
Correct |
73 ms |
6452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
80 ms |
4948 KB |
Output is correct |
14 |
Correct |
72 ms |
4524 KB |
Output is correct |
15 |
Correct |
76 ms |
4804 KB |
Output is correct |
16 |
Correct |
86 ms |
5056 KB |
Output is correct |
17 |
Correct |
76 ms |
4792 KB |
Output is correct |
18 |
Correct |
77 ms |
4804 KB |
Output is correct |
19 |
Correct |
71 ms |
5264 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
77 ms |
4776 KB |
Output is correct |
23 |
Correct |
86 ms |
5068 KB |
Output is correct |
24 |
Correct |
403 ms |
24808 KB |
Output is correct |
25 |
Correct |
435 ms |
23520 KB |
Output is correct |
26 |
Correct |
228 ms |
19548 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
77 ms |
6224 KB |
Output is correct |
30 |
Correct |
84 ms |
5244 KB |
Output is correct |
31 |
Correct |
94 ms |
6104 KB |
Output is correct |
32 |
Correct |
77 ms |
5272 KB |
Output is correct |
33 |
Correct |
78 ms |
4912 KB |
Output is correct |
34 |
Correct |
86 ms |
5124 KB |
Output is correct |
35 |
Correct |
73 ms |
6452 KB |
Output is correct |
36 |
Correct |
466 ms |
20704 KB |
Output is correct |
37 |
Correct |
588 ms |
31140 KB |
Output is correct |
38 |
Correct |
529 ms |
29716 KB |
Output is correct |
39 |
Correct |
228 ms |
6968 KB |
Output is correct |
40 |
Correct |
484 ms |
26396 KB |
Output is correct |
41 |
Correct |
470 ms |
28352 KB |
Output is correct |
42 |
Correct |
458 ms |
29004 KB |
Output is correct |
43 |
Correct |
449 ms |
32144 KB |
Output is correct |
44 |
Correct |
512 ms |
31112 KB |
Output is correct |
45 |
Correct |
650 ms |
30016 KB |
Output is correct |
46 |
Correct |
633 ms |
28536 KB |
Output is correct |
47 |
Correct |
671 ms |
27652 KB |
Output is correct |
48 |
Correct |
514 ms |
30568 KB |
Output is correct |