#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
struct xy { long long x, y; }a[412121];
bool sort_x(xy a, xy b) { if (a.x != b.x)return a.x < b.x; return a.y < b.y; }
long long Q[612121], ALL[614141], an, tn, tree[2121212], P[612121];
vector<long long>T[612121], R;
long long oper(long long a, long long b, long long tp) {if (tp == 1) { if (a < b)return b; return a; }else return a + b;}
void insert_g(long long w, long long g, long long tp) { for (long long i = w + tn; i > 0; i /= 2)tree[i] = oper(tree[i], g, tp); }
long long search_g(long long ss, long long ee,long long tp) {
long long s = ss + tn, e = ee + tn, res = tp==1?-1:0;
while (s <= e) {
if (s % 2 == 1)res = oper(res, tree[s++],tp);
if (e % 2 == 0)res = oper(res, tree[e--],tp);
s /= 2; e /= 2;
}
return res;
}
int main() {
long long n, m, i, j; scanf("%lld%lld", &n, &m);
for (i = 0; i < n; i++)scanf("%lld%lld", &a[i].x, &a[i].y), ALL[an++] = a[i].x, ALL[an++] = a[i].y;
for (i = 0; i < m; i++)scanf("%lld", &Q[i]), ALL[an++] = Q[i];
sort(ALL, ALL + an);
an = unique(ALL, ALL + an) - ALL;
for (i = 0; i < n; i++)a[i] = { lower_bound(ALL, ALL + an, a[i].x) - ALL,lower_bound(ALL, ALL + an, a[i].y) - ALL };
for (i = 0; i < m; i++)Q[i] = lower_bound(ALL, ALL + an, Q[i]) - ALL;
for (tn = 1; tn < an; tn *= 2);
for (i = 0; i < tn * 2; i++)tree[i] = -1;
for (i = 0; i < m; i++)insert_g(Q[i], i, 1);
for (i = 0; i < n; i++) {
long long s = min(a[i].x, a[i].y), e = max(a[i].x, a[i].y);
P[i] = search_g(s, e - 1,1);
if (P[i] == -1)R.push_back(i);
else T[P[i]].push_back(i);
}
for (i = 0; i < tn * 2; i++)tree[i] = 0;
long long ans = 0;
for (i = m - 1; i >= 0; i--) {
for (j = 0; j < T[i].size(); j++) {
long long now = T[i][j];
if (search_g(max(a[now].x, a[now].y), an - 1, 0) % 2 == 0)ans += ALL[max(a[now].x, a[now].y)];
else ans += ALL[min(a[now].x, a[now].y)];
}
insert_g(Q[i], 1, 0);
}
for (i = 0; i < R.size(); i++) {
long long now = R[i];
if (search_g(a[now].x, an - 1, 0) % 2 == 0)ans += ALL[a[now].x];
else ans += ALL[a[now].y];
}
printf("%lld", ans);
return 0;
}
Compilation message
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:40:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (j = 0; j < T[i].size(); j++) {
~~^~~~~~~~~~~~~
fortune_telling2.cpp:47:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < R.size(); i++) {
~~^~~~~~~~~~
fortune_telling2.cpp:21:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
long long n, m, i, j; scanf("%lld%lld", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:22:80: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 0; i < n; i++)scanf("%lld%lld", &a[i].x, &a[i].y), ALL[an++] = a[i].x, ALL[an++] = a[i].y;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:23:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 0; i < m; i++)scanf("%lld", &Q[i]), ALL[an++] = Q[i];
~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
14844 KB |
Output is correct |
2 |
Correct |
20 ms |
14952 KB |
Output is correct |
3 |
Correct |
18 ms |
14972 KB |
Output is correct |
4 |
Correct |
19 ms |
14972 KB |
Output is correct |
5 |
Correct |
16 ms |
14988 KB |
Output is correct |
6 |
Correct |
18 ms |
15012 KB |
Output is correct |
7 |
Correct |
17 ms |
15012 KB |
Output is correct |
8 |
Correct |
20 ms |
15140 KB |
Output is correct |
9 |
Correct |
22 ms |
15312 KB |
Output is correct |
10 |
Correct |
20 ms |
15312 KB |
Output is correct |
11 |
Correct |
20 ms |
15312 KB |
Output is correct |
12 |
Correct |
17 ms |
15312 KB |
Output is correct |
13 |
Correct |
21 ms |
15312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
14844 KB |
Output is correct |
2 |
Correct |
20 ms |
14952 KB |
Output is correct |
3 |
Correct |
18 ms |
14972 KB |
Output is correct |
4 |
Correct |
19 ms |
14972 KB |
Output is correct |
5 |
Correct |
16 ms |
14988 KB |
Output is correct |
6 |
Correct |
18 ms |
15012 KB |
Output is correct |
7 |
Correct |
17 ms |
15012 KB |
Output is correct |
8 |
Correct |
20 ms |
15140 KB |
Output is correct |
9 |
Correct |
22 ms |
15312 KB |
Output is correct |
10 |
Correct |
20 ms |
15312 KB |
Output is correct |
11 |
Correct |
20 ms |
15312 KB |
Output is correct |
12 |
Correct |
17 ms |
15312 KB |
Output is correct |
13 |
Correct |
21 ms |
15312 KB |
Output is correct |
14 |
Correct |
33 ms |
16236 KB |
Output is correct |
15 |
Correct |
53 ms |
17500 KB |
Output is correct |
16 |
Correct |
89 ms |
18924 KB |
Output is correct |
17 |
Correct |
96 ms |
19692 KB |
Output is correct |
18 |
Correct |
96 ms |
19692 KB |
Output is correct |
19 |
Correct |
110 ms |
19692 KB |
Output is correct |
20 |
Correct |
95 ms |
19720 KB |
Output is correct |
21 |
Correct |
94 ms |
19816 KB |
Output is correct |
22 |
Correct |
90 ms |
19816 KB |
Output is correct |
23 |
Correct |
91 ms |
19816 KB |
Output is correct |
24 |
Correct |
65 ms |
19816 KB |
Output is correct |
25 |
Correct |
73 ms |
19820 KB |
Output is correct |
26 |
Correct |
89 ms |
19820 KB |
Output is correct |
27 |
Correct |
92 ms |
19820 KB |
Output is correct |
28 |
Correct |
85 ms |
19820 KB |
Output is correct |
29 |
Correct |
81 ms |
19820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
14844 KB |
Output is correct |
2 |
Correct |
20 ms |
14952 KB |
Output is correct |
3 |
Correct |
18 ms |
14972 KB |
Output is correct |
4 |
Correct |
19 ms |
14972 KB |
Output is correct |
5 |
Correct |
16 ms |
14988 KB |
Output is correct |
6 |
Correct |
18 ms |
15012 KB |
Output is correct |
7 |
Correct |
17 ms |
15012 KB |
Output is correct |
8 |
Correct |
20 ms |
15140 KB |
Output is correct |
9 |
Correct |
22 ms |
15312 KB |
Output is correct |
10 |
Correct |
20 ms |
15312 KB |
Output is correct |
11 |
Correct |
20 ms |
15312 KB |
Output is correct |
12 |
Correct |
17 ms |
15312 KB |
Output is correct |
13 |
Correct |
21 ms |
15312 KB |
Output is correct |
14 |
Correct |
33 ms |
16236 KB |
Output is correct |
15 |
Correct |
53 ms |
17500 KB |
Output is correct |
16 |
Correct |
89 ms |
18924 KB |
Output is correct |
17 |
Correct |
96 ms |
19692 KB |
Output is correct |
18 |
Correct |
96 ms |
19692 KB |
Output is correct |
19 |
Correct |
110 ms |
19692 KB |
Output is correct |
20 |
Correct |
95 ms |
19720 KB |
Output is correct |
21 |
Correct |
94 ms |
19816 KB |
Output is correct |
22 |
Correct |
90 ms |
19816 KB |
Output is correct |
23 |
Correct |
91 ms |
19816 KB |
Output is correct |
24 |
Correct |
65 ms |
19816 KB |
Output is correct |
25 |
Correct |
73 ms |
19820 KB |
Output is correct |
26 |
Correct |
89 ms |
19820 KB |
Output is correct |
27 |
Correct |
92 ms |
19820 KB |
Output is correct |
28 |
Correct |
85 ms |
19820 KB |
Output is correct |
29 |
Correct |
81 ms |
19820 KB |
Output is correct |
30 |
Correct |
156 ms |
22776 KB |
Output is correct |
31 |
Correct |
293 ms |
28780 KB |
Output is correct |
32 |
Correct |
368 ms |
31152 KB |
Output is correct |
33 |
Correct |
565 ms |
44312 KB |
Output is correct |
34 |
Correct |
149 ms |
44312 KB |
Output is correct |
35 |
Correct |
561 ms |
44732 KB |
Output is correct |
36 |
Correct |
547 ms |
44732 KB |
Output is correct |
37 |
Correct |
518 ms |
44732 KB |
Output is correct |
38 |
Correct |
570 ms |
44816 KB |
Output is correct |
39 |
Correct |
642 ms |
44816 KB |
Output is correct |
40 |
Correct |
507 ms |
44816 KB |
Output is correct |
41 |
Correct |
500 ms |
44816 KB |
Output is correct |
42 |
Correct |
476 ms |
44816 KB |
Output is correct |
43 |
Correct |
309 ms |
44816 KB |
Output is correct |
44 |
Correct |
300 ms |
44816 KB |
Output is correct |
45 |
Correct |
374 ms |
44816 KB |
Output is correct |
46 |
Correct |
307 ms |
44816 KB |
Output is correct |
47 |
Correct |
345 ms |
44816 KB |
Output is correct |
48 |
Correct |
384 ms |
44816 KB |
Output is correct |
49 |
Correct |
440 ms |
44816 KB |
Output is correct |