#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
const int N = 1 << 18, inf = 2e9;
int mn[N << 1]; bool s[N << 1];
int q, p, x;
void upd(int v, int l, int r) {
if (r - l == 1) return mn[v] = x, void(s[v] = 1);
int m = (l + r) >> 1;
if (p < m) upd(v << 1, l, m);
else upd(v << 1|1, m, r);
mn[v] = min(mn[v << 1], mn[v << 1|1]);
s[v] = s[v << 1] ^ s[v << 1|1];
}
void upd(int a, int b) { p = a; x = b; upd(1, 0, q); }
int find(int v, int l, int r) {
if (x <= mn[v]) return 0;
if (r - l == 1) return r;
int m = (l + r) >> 1;
int res = find(v << 1|1, m, r);
if (res) return res;
return find(v << 1, l, m);
}
int find(int a) { x = a; return find(1, 0, q); }
int lo, hi;
bool sum(int v, int l, int r) {
if (hi <= l || r <= lo) return 0;
if (lo <= l && r <= hi) return s[v];
int m = (l + r) >> 1;
return sum(v << 1, l, m) ^ sum(v << 1|1, m, r);
}
bool sum(int l, int r) { lo = l; hi = r; return sum(1, 0, q); }
array<int, 2> a[N];
int t[N], ord[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
fill(mn, mn + N, inf);
int n; cin >> n >> q;
rep(i, 0, n) cin >> a[i][0] >> a[i][1];
rep(i, 0, q) cin >> t[i], ord[i] = i;
sort(a, a + n, [](const auto &x, const auto &y) { return min(x[0], x[1]) > min(y[0], y[1]); });
sort(ord, ord + q, [&](int x, int y) { return t[x] > t[y]; });
int64_t ans = 0;
for (int i = 0, j = 0; i < n; ++i) {
bool b = 0; if (a[i][0] < a[i][1]) swap(a[i][0], a[i][1]), b = 1;
while (j < q && a[i][1] <= t[ord[j]]) upd(ord[j], t[ord[j]]), ++j;
int p = find(a[i][0]);
ans += a[i][(!p && b) ^ sum(p, q)];
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1408 KB |
Output is correct |
2 |
Correct |
2 ms |
1408 KB |
Output is correct |
3 |
Correct |
3 ms |
1408 KB |
Output is correct |
4 |
Correct |
2 ms |
1408 KB |
Output is correct |
5 |
Correct |
2 ms |
1408 KB |
Output is correct |
6 |
Correct |
2 ms |
1408 KB |
Output is correct |
7 |
Correct |
2 ms |
1408 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
3 ms |
1408 KB |
Output is correct |
10 |
Correct |
2 ms |
1408 KB |
Output is correct |
11 |
Correct |
2 ms |
1408 KB |
Output is correct |
12 |
Correct |
2 ms |
1408 KB |
Output is correct |
13 |
Correct |
3 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1408 KB |
Output is correct |
2 |
Correct |
2 ms |
1408 KB |
Output is correct |
3 |
Correct |
3 ms |
1408 KB |
Output is correct |
4 |
Correct |
2 ms |
1408 KB |
Output is correct |
5 |
Correct |
2 ms |
1408 KB |
Output is correct |
6 |
Correct |
2 ms |
1408 KB |
Output is correct |
7 |
Correct |
2 ms |
1408 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
3 ms |
1408 KB |
Output is correct |
10 |
Correct |
2 ms |
1408 KB |
Output is correct |
11 |
Correct |
2 ms |
1408 KB |
Output is correct |
12 |
Correct |
2 ms |
1408 KB |
Output is correct |
13 |
Correct |
3 ms |
1408 KB |
Output is correct |
14 |
Correct |
15 ms |
1708 KB |
Output is correct |
15 |
Correct |
31 ms |
1920 KB |
Output is correct |
16 |
Correct |
28 ms |
2048 KB |
Output is correct |
17 |
Correct |
39 ms |
2296 KB |
Output is correct |
18 |
Correct |
59 ms |
2296 KB |
Output is correct |
19 |
Correct |
50 ms |
2356 KB |
Output is correct |
20 |
Correct |
40 ms |
2304 KB |
Output is correct |
21 |
Correct |
56 ms |
2428 KB |
Output is correct |
22 |
Correct |
29 ms |
2304 KB |
Output is correct |
23 |
Correct |
31 ms |
2304 KB |
Output is correct |
24 |
Correct |
50 ms |
2296 KB |
Output is correct |
25 |
Correct |
29 ms |
2304 KB |
Output is correct |
26 |
Correct |
32 ms |
2304 KB |
Output is correct |
27 |
Correct |
41 ms |
2296 KB |
Output is correct |
28 |
Correct |
39 ms |
2320 KB |
Output is correct |
29 |
Correct |
39 ms |
2296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1408 KB |
Output is correct |
2 |
Correct |
2 ms |
1408 KB |
Output is correct |
3 |
Correct |
3 ms |
1408 KB |
Output is correct |
4 |
Correct |
2 ms |
1408 KB |
Output is correct |
5 |
Correct |
2 ms |
1408 KB |
Output is correct |
6 |
Correct |
2 ms |
1408 KB |
Output is correct |
7 |
Correct |
2 ms |
1408 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
3 ms |
1408 KB |
Output is correct |
10 |
Correct |
2 ms |
1408 KB |
Output is correct |
11 |
Correct |
2 ms |
1408 KB |
Output is correct |
12 |
Correct |
2 ms |
1408 KB |
Output is correct |
13 |
Correct |
3 ms |
1408 KB |
Output is correct |
14 |
Correct |
15 ms |
1708 KB |
Output is correct |
15 |
Correct |
31 ms |
1920 KB |
Output is correct |
16 |
Correct |
28 ms |
2048 KB |
Output is correct |
17 |
Correct |
39 ms |
2296 KB |
Output is correct |
18 |
Correct |
59 ms |
2296 KB |
Output is correct |
19 |
Correct |
50 ms |
2356 KB |
Output is correct |
20 |
Correct |
40 ms |
2304 KB |
Output is correct |
21 |
Correct |
56 ms |
2428 KB |
Output is correct |
22 |
Correct |
29 ms |
2304 KB |
Output is correct |
23 |
Correct |
31 ms |
2304 KB |
Output is correct |
24 |
Correct |
50 ms |
2296 KB |
Output is correct |
25 |
Correct |
29 ms |
2304 KB |
Output is correct |
26 |
Correct |
32 ms |
2304 KB |
Output is correct |
27 |
Correct |
41 ms |
2296 KB |
Output is correct |
28 |
Correct |
39 ms |
2320 KB |
Output is correct |
29 |
Correct |
39 ms |
2296 KB |
Output is correct |
30 |
Incorrect |
106 ms |
4728 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |