#include <stdio.h>
#include <vector>
static inline long long min(long long a, long long b) {
return a < b ? a : b;
}
static inline long long max(long long a, long long b) {
return a > b ? a : b;
}
#define MAXN 200000
#define INFINIT 1000000000000000000
int a[MAXN * 2];
struct Restrictie {
int st, dr, val;
} v[MAXN * 2];
int cost[MAXN], st[MAXN], p[MAXN];
std::vector<int> dr[MAXN];
struct SegmentTree {
long long aint[4 * (MAXN + 1)], lazy[4 * (MAXN + 1)], qval;
int n, qleft, qright;
void init(int n) {
int i;
this->n = n;
for(i = 0; i < 4 * n; i++) {
aint[i] = lazy[i] = 0;
}
}
void propagate(int node, int left, int right) {
aint[node] += lazy[node];
if(left < right) {
lazy[2 * node + 1] += lazy[node];
lazy[2 * node + 2] += lazy[node];
}
lazy[node] = 0;
}
void _update(int node, int left, int right) {
int middle;
propagate(node, left, right);
if(qleft <= left && right <= qright) {
lazy[node] += qval;
propagate(node, left, right);
} else {
middle = (left + right) / 2;
propagate(2 * node + 1, left, middle);
propagate(2 * node + 2, middle + 1, right);
if(qleft <= middle) {
_update(2 * node + 1, left, middle);
}
if(middle < qright) {
_update(2 * node + 2, middle + 1, right);
}
aint[node] = min(aint[2 * node + 1], aint[2 * node + 2]);
}
}
void update(int qleft, int qright, long long qval) {
this->qleft = qleft;
this->qright = qright;
this->qval = qval;
_update(0, 0, n - 1);
}
long long _query(int node, int left, int right) {
int middle;
long long ans;
propagate(node, left, right);
if(qleft <= left && right <= qright) {
return aint[node];
}
middle = (left + right) / 2;
ans = INFINIT;
if(qleft <= middle) {
ans = min(ans, _query(2 * node + 1, left, middle));
}
if(middle < qright) {
ans = min(ans, _query(2 * node + 2, middle + 1, right));
}
return ans;
}
long long query(int qleft, int qright) {
this->qleft = qleft;
this->qright = qright;
return _query(0, 0, n - 1);
}
} aint;
int main() {
int n, m, i, j, l, c, j1, j2, nnou;
long long ans;
scanf("%d%d", &n, &m);
for(i = 0; i < n + m - 1; i++) {
scanf("%d", &a[i]);
}
for(i = 0; i < n + m - 1; i++) {
scanf("%d", &v[i].val);
c = min(i, m - 1);
l = i - c;
v[i].st = l - c + m - 1;
c = max(0, i - n + 1);
l = i - c;
v[i].dr = l - c + m - 1;
}
ans = 0;
for(j1 = 0; j1 < 2; j1++) {
j2 = v[j1].st % 2;
nnou = 0;
for(i = j1; i < n + m - 1; i += 2) {
cost[nnou++] = a[i];
}
for(i = j2; i < n + m - 1; i += 2) {
st[i / 2] = v[i].st / 2;
dr[v[i].dr / 2].push_back(i / 2);
p[i / 2] = v[i].val;
}
aint.init(nnou + 1);
for(i = 0; i < nnou; i++) {
aint.update(i + 1, i + 1, aint.query(0, i));
aint.update(0, i, cost[i]);
for(j = 0; j < (int)dr[i].size(); j++) {
aint.update(st[dr[i][j]] + 1, i + 1, p[dr[i][j]]);
}
}
ans += aint.query(0, nnou);
for(i = 0; i < nnou; i++) {
dr[i].clear();
}
}
printf("%lld\n", ans);
return 0;
}
Compilation message
colouring.cpp: In function 'int main()':
colouring.cpp:102:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
102 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
colouring.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
colouring.cpp:107:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | scanf("%d", &v[i].val);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 ms |
6236 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
6232 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 ms |
6236 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
6232 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
3 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
5128 KB |
Output is correct |
16 |
Correct |
2 ms |
6236 KB |
Output is correct |
17 |
Correct |
2 ms |
5136 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 ms |
6236 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
6232 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
3 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
5128 KB |
Output is correct |
16 |
Correct |
2 ms |
6236 KB |
Output is correct |
17 |
Correct |
2 ms |
5136 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
3 ms |
6236 KB |
Output is correct |
25 |
Correct |
3 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
6236 KB |
Output is correct |
28 |
Correct |
3 ms |
6232 KB |
Output is correct |
29 |
Correct |
2 ms |
6236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 ms |
6236 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
6232 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
3 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
5128 KB |
Output is correct |
16 |
Correct |
2 ms |
6236 KB |
Output is correct |
17 |
Correct |
2 ms |
5136 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
3 ms |
6236 KB |
Output is correct |
25 |
Correct |
3 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
6236 KB |
Output is correct |
28 |
Correct |
3 ms |
6232 KB |
Output is correct |
29 |
Correct |
2 ms |
6236 KB |
Output is correct |
30 |
Correct |
5 ms |
6492 KB |
Output is correct |
31 |
Correct |
4 ms |
5212 KB |
Output is correct |
32 |
Correct |
6 ms |
5212 KB |
Output is correct |
33 |
Correct |
3 ms |
6488 KB |
Output is correct |
34 |
Correct |
7 ms |
5212 KB |
Output is correct |
35 |
Correct |
3 ms |
5212 KB |
Output is correct |
36 |
Correct |
3 ms |
6492 KB |
Output is correct |
37 |
Correct |
4 ms |
5212 KB |
Output is correct |
38 |
Correct |
4 ms |
5212 KB |
Output is correct |
39 |
Correct |
3 ms |
6492 KB |
Output is correct |
40 |
Correct |
4 ms |
6552 KB |
Output is correct |
41 |
Correct |
5 ms |
6492 KB |
Output is correct |
42 |
Correct |
4 ms |
5212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
176 ms |
20060 KB |
Output is correct |
2 |
Correct |
170 ms |
20084 KB |
Output is correct |
3 |
Correct |
187 ms |
19996 KB |
Output is correct |
4 |
Correct |
206 ms |
20084 KB |
Output is correct |
5 |
Correct |
181 ms |
19856 KB |
Output is correct |
6 |
Correct |
180 ms |
20048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
485 ms |
29356 KB |
Output is correct |
2 |
Correct |
479 ms |
37104 KB |
Output is correct |
3 |
Correct |
464 ms |
37000 KB |
Output is correct |
4 |
Correct |
502 ms |
37204 KB |
Output is correct |
5 |
Correct |
505 ms |
37236 KB |
Output is correct |
6 |
Correct |
470 ms |
34404 KB |
Output is correct |
7 |
Correct |
445 ms |
36760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 ms |
6236 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
6232 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
3 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
5128 KB |
Output is correct |
16 |
Correct |
2 ms |
6236 KB |
Output is correct |
17 |
Correct |
2 ms |
5136 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
3 ms |
6236 KB |
Output is correct |
25 |
Correct |
3 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
6236 KB |
Output is correct |
28 |
Correct |
3 ms |
6232 KB |
Output is correct |
29 |
Correct |
2 ms |
6236 KB |
Output is correct |
30 |
Correct |
5 ms |
6492 KB |
Output is correct |
31 |
Correct |
4 ms |
5212 KB |
Output is correct |
32 |
Correct |
6 ms |
5212 KB |
Output is correct |
33 |
Correct |
3 ms |
6488 KB |
Output is correct |
34 |
Correct |
7 ms |
5212 KB |
Output is correct |
35 |
Correct |
3 ms |
5212 KB |
Output is correct |
36 |
Correct |
3 ms |
6492 KB |
Output is correct |
37 |
Correct |
4 ms |
5212 KB |
Output is correct |
38 |
Correct |
4 ms |
5212 KB |
Output is correct |
39 |
Correct |
3 ms |
6492 KB |
Output is correct |
40 |
Correct |
4 ms |
6552 KB |
Output is correct |
41 |
Correct |
5 ms |
6492 KB |
Output is correct |
42 |
Correct |
4 ms |
5212 KB |
Output is correct |
43 |
Correct |
176 ms |
20060 KB |
Output is correct |
44 |
Correct |
170 ms |
20084 KB |
Output is correct |
45 |
Correct |
187 ms |
19996 KB |
Output is correct |
46 |
Correct |
206 ms |
20084 KB |
Output is correct |
47 |
Correct |
181 ms |
19856 KB |
Output is correct |
48 |
Correct |
180 ms |
20048 KB |
Output is correct |
49 |
Correct |
485 ms |
29356 KB |
Output is correct |
50 |
Correct |
479 ms |
37104 KB |
Output is correct |
51 |
Correct |
464 ms |
37000 KB |
Output is correct |
52 |
Correct |
502 ms |
37204 KB |
Output is correct |
53 |
Correct |
505 ms |
37236 KB |
Output is correct |
54 |
Correct |
470 ms |
34404 KB |
Output is correct |
55 |
Correct |
445 ms |
36760 KB |
Output is correct |
56 |
Correct |
169 ms |
23380 KB |
Output is correct |
57 |
Correct |
199 ms |
23608 KB |
Output is correct |
58 |
Correct |
204 ms |
23812 KB |
Output is correct |
59 |
Correct |
203 ms |
22560 KB |
Output is correct |
60 |
Correct |
192 ms |
23792 KB |
Output is correct |
61 |
Correct |
200 ms |
23892 KB |
Output is correct |
62 |
Correct |
175 ms |
22636 KB |
Output is correct |
63 |
Correct |
208 ms |
23968 KB |
Output is correct |
64 |
Correct |
190 ms |
24036 KB |
Output is correct |
65 |
Correct |
211 ms |
24660 KB |
Output is correct |
66 |
Correct |
271 ms |
26288 KB |
Output is correct |
67 |
Correct |
283 ms |
27732 KB |
Output is correct |
68 |
Correct |
467 ms |
34404 KB |
Output is correct |
69 |
Correct |
449 ms |
35852 KB |
Output is correct |
70 |
Correct |
362 ms |
31128 KB |
Output is correct |