#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define N 200005
int s[N][2];
int a[N];
vector<int> t[N << 2];
void build(int id, int l, int r){
if(l == r){
t[id] = {a[l]};
return;
}
int i1 = 0, i2 = 0, id1 = id << 1, id2 = id << 1 | 1, s1, s2, m = (l + r) >> 1;
build(id1, l, m);
build(id2, m + 1, r);
s1 = t[id1].size();
s2 = t[id2].size();
while(i1 != s1 && i2 != s2)
if(t[id1][i1] > t[id2][i2])
t[id].pb(t[id2][i2++]);
else
t[id].pb(t[id1][i1++]);
while(i1 != s1)
t[id].pb(t[id1][i1++]);
while(i2 != s2)
t[id].pb(t[id2][i2++]);
}
pair<int, int> query(int id, int l, int r, int f, int s){
auto it = lower_bound(t[id].begin(), t[id].end(), min(f, s));
if(it == t[id].end())
return {0, 0};
if(*it >= max(f, s))
return {0, t[id].end() - it};
if(l == r)
return {1, 0};
int m = (l + r) >> 1;
auto r2 = query(id << 1 | 1, m + 1, r, f, s);
if(r2.ff) return r2;
auto r1 = query(id << 1, l, m, f, s);
return {r1.ff, r1.ss ^ r2.ss};
}
ll res;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin>>n>>k;
for(int i = 1; i <= n; i++)
cin>>s[i][0]>>s[i][1];
for(int i = 1; i <= k; i++)
cin>>a[i];
build(1, 1, k);
for(int i = 1; i <= n; i++){
auto w = query(1, 1, k, s[i][0], s[i][1]);
if(w.ff && s[i][0] < s[i][1])
swap(s[i][0], s[i][1]);
res += s[i][w.ss & 1];
}
cout<<res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
19320 KB |
Output is correct |
2 |
Correct |
20 ms |
19192 KB |
Output is correct |
3 |
Correct |
21 ms |
19320 KB |
Output is correct |
4 |
Correct |
22 ms |
19192 KB |
Output is correct |
5 |
Correct |
21 ms |
19320 KB |
Output is correct |
6 |
Correct |
22 ms |
19204 KB |
Output is correct |
7 |
Correct |
21 ms |
19320 KB |
Output is correct |
8 |
Correct |
21 ms |
19320 KB |
Output is correct |
9 |
Correct |
21 ms |
19320 KB |
Output is correct |
10 |
Correct |
20 ms |
19448 KB |
Output is correct |
11 |
Correct |
21 ms |
19320 KB |
Output is correct |
12 |
Correct |
21 ms |
19320 KB |
Output is correct |
13 |
Correct |
21 ms |
19320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
19320 KB |
Output is correct |
2 |
Correct |
20 ms |
19192 KB |
Output is correct |
3 |
Correct |
21 ms |
19320 KB |
Output is correct |
4 |
Correct |
22 ms |
19192 KB |
Output is correct |
5 |
Correct |
21 ms |
19320 KB |
Output is correct |
6 |
Correct |
22 ms |
19204 KB |
Output is correct |
7 |
Correct |
21 ms |
19320 KB |
Output is correct |
8 |
Correct |
21 ms |
19320 KB |
Output is correct |
9 |
Correct |
21 ms |
19320 KB |
Output is correct |
10 |
Correct |
20 ms |
19448 KB |
Output is correct |
11 |
Correct |
21 ms |
19320 KB |
Output is correct |
12 |
Correct |
21 ms |
19320 KB |
Output is correct |
13 |
Correct |
21 ms |
19320 KB |
Output is correct |
14 |
Correct |
38 ms |
20728 KB |
Output is correct |
15 |
Correct |
62 ms |
22268 KB |
Output is correct |
16 |
Correct |
93 ms |
23160 KB |
Output is correct |
17 |
Correct |
103 ms |
25464 KB |
Output is correct |
18 |
Correct |
106 ms |
25464 KB |
Output is correct |
19 |
Correct |
104 ms |
25464 KB |
Output is correct |
20 |
Correct |
116 ms |
25464 KB |
Output is correct |
21 |
Correct |
89 ms |
25464 KB |
Output is correct |
22 |
Correct |
72 ms |
25464 KB |
Output is correct |
23 |
Correct |
72 ms |
25448 KB |
Output is correct |
24 |
Correct |
72 ms |
25460 KB |
Output is correct |
25 |
Correct |
73 ms |
25464 KB |
Output is correct |
26 |
Correct |
72 ms |
25308 KB |
Output is correct |
27 |
Correct |
126 ms |
25492 KB |
Output is correct |
28 |
Correct |
74 ms |
25468 KB |
Output is correct |
29 |
Correct |
98 ms |
25464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
19320 KB |
Output is correct |
2 |
Correct |
20 ms |
19192 KB |
Output is correct |
3 |
Correct |
21 ms |
19320 KB |
Output is correct |
4 |
Correct |
22 ms |
19192 KB |
Output is correct |
5 |
Correct |
21 ms |
19320 KB |
Output is correct |
6 |
Correct |
22 ms |
19204 KB |
Output is correct |
7 |
Correct |
21 ms |
19320 KB |
Output is correct |
8 |
Correct |
21 ms |
19320 KB |
Output is correct |
9 |
Correct |
21 ms |
19320 KB |
Output is correct |
10 |
Correct |
20 ms |
19448 KB |
Output is correct |
11 |
Correct |
21 ms |
19320 KB |
Output is correct |
12 |
Correct |
21 ms |
19320 KB |
Output is correct |
13 |
Correct |
21 ms |
19320 KB |
Output is correct |
14 |
Correct |
38 ms |
20728 KB |
Output is correct |
15 |
Correct |
62 ms |
22268 KB |
Output is correct |
16 |
Correct |
93 ms |
23160 KB |
Output is correct |
17 |
Correct |
103 ms |
25464 KB |
Output is correct |
18 |
Correct |
106 ms |
25464 KB |
Output is correct |
19 |
Correct |
104 ms |
25464 KB |
Output is correct |
20 |
Correct |
116 ms |
25464 KB |
Output is correct |
21 |
Correct |
89 ms |
25464 KB |
Output is correct |
22 |
Correct |
72 ms |
25464 KB |
Output is correct |
23 |
Correct |
72 ms |
25448 KB |
Output is correct |
24 |
Correct |
72 ms |
25460 KB |
Output is correct |
25 |
Correct |
73 ms |
25464 KB |
Output is correct |
26 |
Correct |
72 ms |
25308 KB |
Output is correct |
27 |
Correct |
126 ms |
25492 KB |
Output is correct |
28 |
Correct |
74 ms |
25468 KB |
Output is correct |
29 |
Correct |
98 ms |
25464 KB |
Output is correct |
30 |
Correct |
197 ms |
47600 KB |
Output is correct |
31 |
Correct |
285 ms |
47856 KB |
Output is correct |
32 |
Correct |
358 ms |
48344 KB |
Output is correct |
33 |
Correct |
555 ms |
49088 KB |
Output is correct |
34 |
Correct |
183 ms |
47612 KB |
Output is correct |
35 |
Correct |
575 ms |
49152 KB |
Output is correct |
36 |
Correct |
574 ms |
49136 KB |
Output is correct |
37 |
Correct |
563 ms |
49104 KB |
Output is correct |
38 |
Correct |
533 ms |
49136 KB |
Output is correct |
39 |
Correct |
608 ms |
49136 KB |
Output is correct |
40 |
Correct |
426 ms |
49264 KB |
Output is correct |
41 |
Correct |
558 ms |
49264 KB |
Output is correct |
42 |
Correct |
589 ms |
49136 KB |
Output is correct |
43 |
Correct |
305 ms |
49264 KB |
Output is correct |
44 |
Correct |
296 ms |
49180 KB |
Output is correct |
45 |
Correct |
295 ms |
49196 KB |
Output is correct |
46 |
Correct |
324 ms |
49136 KB |
Output is correct |
47 |
Correct |
346 ms |
49136 KB |
Output is correct |
48 |
Correct |
359 ms |
49136 KB |
Output is correct |
49 |
Correct |
322 ms |
49136 KB |
Output is correct |