//In His Name
#include <bits/stdc++.h>
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2")
using namespace std;
#define ll long long
//#define int ll
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
#define bug(x) cout << "Ah shit , here we go again : " << x <<endl
#define all(x) x.begin() , x.end()
const int maxn = 2e5 , MOD = 1e9 + 7;
const ll INF = 1e18 + 100;
int n , k , q[maxn];
ll ans;
pii c[maxn];
vector<int> tree[4*maxn];
void Build(int id = 1, int L = 1 , int R = k+1){
if(L+1 == R){
tree[id].pb(q[L]);
return;
}
int mid = (L+R) >> 1 , lc = id << 1 , rc = lc | 1;
Build(lc , L , mid) , Build(rc , mid , R);
for(int i : tree[lc]) tree[id].pb(i);
for(int i : tree[rc]) tree[id].pb(i);
sort(all(tree[id]));
}
int Find(int id , int L , int R , int l , int r){
if(L+1 == R) return L;
int mid = (L+R) >> 1 , lc = id << 1 , rc = lc | 1;
int low = lower_bound(all(tree[id]) , l) - tree[id].begin();
if(low == tree[id].size() or tree[id][low] >= r) return 0;
low = lower_bound(all(tree[rc]) , l) - tree[rc].begin();
if(low < tree[rc].size() and tree[rc][low] < r) return Find(rc , mid , R , l , r);
else return Find(lc , L , mid , l , r);
}
int Get(int id , int L , int R , int l , int r , int val){
if(L == l and R == r) return tree[id].end() - lower_bound(all(tree[id]) , val);
int mid = (L+R) >> 1 , lc = id << 1 , rc = lc | 1 , res = 0;
if(l < mid) res += Get(lc , L , mid , l , min(mid , r) , val);
if(r > mid) res += Get(rc , mid , R , max(l , mid) , r , val);
return res;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0) , cout.tie(0);
cin >> n >> k;
for(int i = 1 ; i <= n ; i++) cin >> c[i].F >> c[i].S;
for(int i = 1 ; i <= k ; i++) cin >> q[i];
Build();
for(int i = 1 ; i <= n ; i++){
int l = min(c[i].F , c[i].S);
int r = max(c[i].F , c[i].S);
int tah = Find(1 , 1 , k+1 , l , r);
if(tah == k){
ans += r;
continue;
}
int num = Get(1 , 1 , k+1 , tah+1 , k+1 , r);
if(tah == 0) ans += (num & 1 ? c[i].S : c[i].F);
else{
if(c[i].F >= c[i].S) ans += (num & 1 ? c[i].S : c[i].F);
else ans += (num & 1 ? c[i].F : c[i].S);
}
}
cout << ans;
}
Compilation message
fortune_telling2.cpp: In function 'int Find(int, int, int, int, int)':
fortune_telling2.cpp:38:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | if(low == tree[id].size() or tree[id][low] >= r) return 0;
| ~~~~^~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:40:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if(low < tree[rc].size() and tree[rc][low] < r) return Find(rc , mid , R , l , r);
| ~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
21080 KB |
Output is correct |
2 |
Correct |
5 ms |
21084 KB |
Output is correct |
3 |
Correct |
6 ms |
21084 KB |
Output is correct |
4 |
Correct |
6 ms |
21084 KB |
Output is correct |
5 |
Correct |
7 ms |
21104 KB |
Output is correct |
6 |
Correct |
6 ms |
21172 KB |
Output is correct |
7 |
Correct |
6 ms |
21084 KB |
Output is correct |
8 |
Correct |
7 ms |
21104 KB |
Output is correct |
9 |
Correct |
5 ms |
21084 KB |
Output is correct |
10 |
Correct |
5 ms |
21124 KB |
Output is correct |
11 |
Correct |
6 ms |
21084 KB |
Output is correct |
12 |
Correct |
5 ms |
21120 KB |
Output is correct |
13 |
Correct |
6 ms |
21172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
21080 KB |
Output is correct |
2 |
Correct |
5 ms |
21084 KB |
Output is correct |
3 |
Correct |
6 ms |
21084 KB |
Output is correct |
4 |
Correct |
6 ms |
21084 KB |
Output is correct |
5 |
Correct |
7 ms |
21104 KB |
Output is correct |
6 |
Correct |
6 ms |
21172 KB |
Output is correct |
7 |
Correct |
6 ms |
21084 KB |
Output is correct |
8 |
Correct |
7 ms |
21104 KB |
Output is correct |
9 |
Correct |
5 ms |
21084 KB |
Output is correct |
10 |
Correct |
5 ms |
21124 KB |
Output is correct |
11 |
Correct |
6 ms |
21084 KB |
Output is correct |
12 |
Correct |
5 ms |
21120 KB |
Output is correct |
13 |
Correct |
6 ms |
21172 KB |
Output is correct |
14 |
Correct |
21 ms |
22620 KB |
Output is correct |
15 |
Correct |
42 ms |
24412 KB |
Output is correct |
16 |
Correct |
64 ms |
25436 KB |
Output is correct |
17 |
Correct |
90 ms |
27776 KB |
Output is correct |
18 |
Correct |
90 ms |
27856 KB |
Output is correct |
19 |
Correct |
86 ms |
27856 KB |
Output is correct |
20 |
Correct |
94 ms |
27996 KB |
Output is correct |
21 |
Correct |
81 ms |
27856 KB |
Output is correct |
22 |
Correct |
55 ms |
27476 KB |
Output is correct |
23 |
Correct |
54 ms |
27404 KB |
Output is correct |
24 |
Correct |
56 ms |
27484 KB |
Output is correct |
25 |
Correct |
51 ms |
27472 KB |
Output is correct |
26 |
Correct |
62 ms |
27792 KB |
Output is correct |
27 |
Correct |
99 ms |
27984 KB |
Output is correct |
28 |
Correct |
60 ms |
27868 KB |
Output is correct |
29 |
Correct |
72 ms |
27876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
21080 KB |
Output is correct |
2 |
Correct |
5 ms |
21084 KB |
Output is correct |
3 |
Correct |
6 ms |
21084 KB |
Output is correct |
4 |
Correct |
6 ms |
21084 KB |
Output is correct |
5 |
Correct |
7 ms |
21104 KB |
Output is correct |
6 |
Correct |
6 ms |
21172 KB |
Output is correct |
7 |
Correct |
6 ms |
21084 KB |
Output is correct |
8 |
Correct |
7 ms |
21104 KB |
Output is correct |
9 |
Correct |
5 ms |
21084 KB |
Output is correct |
10 |
Correct |
5 ms |
21124 KB |
Output is correct |
11 |
Correct |
6 ms |
21084 KB |
Output is correct |
12 |
Correct |
5 ms |
21120 KB |
Output is correct |
13 |
Correct |
6 ms |
21172 KB |
Output is correct |
14 |
Correct |
21 ms |
22620 KB |
Output is correct |
15 |
Correct |
42 ms |
24412 KB |
Output is correct |
16 |
Correct |
64 ms |
25436 KB |
Output is correct |
17 |
Correct |
90 ms |
27776 KB |
Output is correct |
18 |
Correct |
90 ms |
27856 KB |
Output is correct |
19 |
Correct |
86 ms |
27856 KB |
Output is correct |
20 |
Correct |
94 ms |
27996 KB |
Output is correct |
21 |
Correct |
81 ms |
27856 KB |
Output is correct |
22 |
Correct |
55 ms |
27476 KB |
Output is correct |
23 |
Correct |
54 ms |
27404 KB |
Output is correct |
24 |
Correct |
56 ms |
27484 KB |
Output is correct |
25 |
Correct |
51 ms |
27472 KB |
Output is correct |
26 |
Correct |
62 ms |
27792 KB |
Output is correct |
27 |
Correct |
99 ms |
27984 KB |
Output is correct |
28 |
Correct |
60 ms |
27868 KB |
Output is correct |
29 |
Correct |
72 ms |
27876 KB |
Output is correct |
30 |
Runtime error |
1723 ms |
45496 KB |
Execution killed with signal 11 |
31 |
Halted |
0 ms |
0 KB |
- |