#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#define fi first
#define se second
using namespace std;
const int maxn = 2e5 + 5;
int n, m,q;
pair <int, int> a[maxn];
int id[maxn];
long long s[maxn], s1[maxn];
set <pair <int, int>> st;
vector <pair <int, int>> vt;
vector <pair <long long, int>> v;
long long f[maxn];
bool cmp(int i, int j) {
return s[i]> s[j];
}
int main() {
ios_base::sync_with_stdio(NULL); cin.tie(nullptr);
cin >> n >> m >> q;
for(int i = 1; i <= m; ++i) {
cin >> a[i].fi >> a[i].se;
s1[i] = s1[i - 1] + (a[i].se - a[i].fi + 1);
}
for(int i = 1; i <= q; ++i) cin >> s[i];
for(int i = 1; i <= q; ++i) id[i] = i;
st.insert({1, 0});
st.insert({n + 1, 0});
sort(id + 1, id + q + 1, cmp);
for(int i = 1; i <= m; ++i) {
vt.clear();
auto it = st.upper_bound({a[i].fi, m + 1});
--it;
int x = 0;
int y = 0;
int dx = 0;
int dy = 0;
for(it; it != st.end(); ++it) {
auto r = (*it);
//cout << i << ' ' << r.fi << ' ' << r.se << '\n';
if(r.fi < a[i].fi) {
x = r.fi;
dx = r.se;
}
else if(r.fi >= a[i].se + 1) {
if(r.fi == a[i].se + 1) break;
y = r.fi - 1;
dy = (*(--it)).se;
break;
}
auto it1 = it;
auto nxt = *(++it1);
vt.push_back(r);
int d = r.se;
if(d == 0) continue;
if(r.fi < a[i].fi) {
v.push_back({s1[i - 1] - s1[d] + a[d].se - a[i].fi + 1, min(nxt.fi, a[i].se + 1) - a[i].fi});
}
else {
v.push_back({s1[i - 1] - s1[d] + r.fi - a[i].fi + a[d].se - r.fi + 1, min(nxt.fi, a[i].se + 1) - r.fi});
}
}
for(auto j : vt) {
st.erase(j);
}
if(x) st.insert({x, dx});
if(y) st.insert({a[i].se + 1, dy});
st.insert({a[i].fi, i});
}
sort(v.begin(), v.end());
long long res = 0;
for(int i1 = 1; i1 <= q; ++i1) {
int i = id[i1];
while(!v.empty() && v.back().fi > s[i]) {
res += v.back().se;
v.pop_back();
}
f[i] = res;
}
for(int i = 1; i <= q; ++i) cout << f[i] << ' ';
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:44:13: warning: statement has no effect [-Wunused-value]
44 | for(it; it != st.end(); ++it) {
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
50 ms |
8860 KB |
Output is correct |
14 |
Correct |
46 ms |
8464 KB |
Output is correct |
15 |
Correct |
49 ms |
8940 KB |
Output is correct |
16 |
Correct |
49 ms |
8832 KB |
Output is correct |
17 |
Correct |
49 ms |
8644 KB |
Output is correct |
18 |
Correct |
48 ms |
8772 KB |
Output is correct |
19 |
Correct |
48 ms |
9064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
49 ms |
8588 KB |
Output is correct |
4 |
Correct |
50 ms |
9296 KB |
Output is correct |
5 |
Correct |
133 ms |
19652 KB |
Output is correct |
6 |
Correct |
138 ms |
20308 KB |
Output is correct |
7 |
Correct |
101 ms |
15364 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
50 ms |
8860 KB |
Output is correct |
14 |
Correct |
46 ms |
8464 KB |
Output is correct |
15 |
Correct |
49 ms |
8940 KB |
Output is correct |
16 |
Correct |
49 ms |
8832 KB |
Output is correct |
17 |
Correct |
49 ms |
8644 KB |
Output is correct |
18 |
Correct |
48 ms |
8772 KB |
Output is correct |
19 |
Correct |
48 ms |
9064 KB |
Output is correct |
20 |
Correct |
51 ms |
10068 KB |
Output is correct |
21 |
Correct |
53 ms |
9156 KB |
Output is correct |
22 |
Correct |
49 ms |
9812 KB |
Output is correct |
23 |
Correct |
57 ms |
9048 KB |
Output is correct |
24 |
Correct |
47 ms |
8788 KB |
Output is correct |
25 |
Correct |
56 ms |
9296 KB |
Output is correct |
26 |
Correct |
47 ms |
10056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
50 ms |
8860 KB |
Output is correct |
14 |
Correct |
46 ms |
8464 KB |
Output is correct |
15 |
Correct |
49 ms |
8940 KB |
Output is correct |
16 |
Correct |
49 ms |
8832 KB |
Output is correct |
17 |
Correct |
49 ms |
8644 KB |
Output is correct |
18 |
Correct |
48 ms |
8772 KB |
Output is correct |
19 |
Correct |
48 ms |
9064 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
49 ms |
8588 KB |
Output is correct |
23 |
Correct |
50 ms |
9296 KB |
Output is correct |
24 |
Correct |
133 ms |
19652 KB |
Output is correct |
25 |
Correct |
138 ms |
20308 KB |
Output is correct |
26 |
Correct |
101 ms |
15364 KB |
Output is correct |
27 |
Correct |
1 ms |
6488 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
51 ms |
10068 KB |
Output is correct |
30 |
Correct |
53 ms |
9156 KB |
Output is correct |
31 |
Correct |
49 ms |
9812 KB |
Output is correct |
32 |
Correct |
57 ms |
9048 KB |
Output is correct |
33 |
Correct |
47 ms |
8788 KB |
Output is correct |
34 |
Correct |
56 ms |
9296 KB |
Output is correct |
35 |
Correct |
47 ms |
10056 KB |
Output is correct |
36 |
Correct |
207 ms |
27324 KB |
Output is correct |
37 |
Correct |
211 ms |
29480 KB |
Output is correct |
38 |
Correct |
206 ms |
30132 KB |
Output is correct |
39 |
Correct |
154 ms |
21424 KB |
Output is correct |
40 |
Correct |
243 ms |
30432 KB |
Output is correct |
41 |
Correct |
235 ms |
34620 KB |
Output is correct |
42 |
Correct |
239 ms |
34992 KB |
Output is correct |
43 |
Correct |
267 ms |
34012 KB |
Output is correct |
44 |
Correct |
280 ms |
34864 KB |
Output is correct |
45 |
Correct |
244 ms |
28788 KB |
Output is correct |
46 |
Correct |
291 ms |
21680 KB |
Output is correct |
47 |
Correct |
295 ms |
23192 KB |
Output is correct |
48 |
Correct |
204 ms |
29876 KB |
Output is correct |