Submission #938428

# Submission time Handle Problem Language Result Execution time Memory
938428 2024-03-05T06:28:21 Z Mohammadamin__Sh Fortune Telling 2 (JOI14_fortune_telling2) C++17
100 / 100
615 ms 54832 KB
//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+10 , 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);
      |        ~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 7 ms 21112 KB Output is correct
5 Correct 5 ms 21084 KB Output is correct
6 Correct 5 ms 21084 KB Output is correct
7 Correct 6 ms 21084 KB Output is correct
8 Correct 5 ms 21084 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 5 ms 21084 KB Output is correct
12 Correct 5 ms 21096 KB Output is correct
13 Correct 5 ms 21080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 7 ms 21112 KB Output is correct
5 Correct 5 ms 21084 KB Output is correct
6 Correct 5 ms 21084 KB Output is correct
7 Correct 6 ms 21084 KB Output is correct
8 Correct 5 ms 21084 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 5 ms 21084 KB Output is correct
12 Correct 5 ms 21096 KB Output is correct
13 Correct 5 ms 21080 KB Output is correct
14 Correct 22 ms 22364 KB Output is correct
15 Correct 42 ms 23920 KB Output is correct
16 Correct 64 ms 24684 KB Output is correct
17 Correct 93 ms 26716 KB Output is correct
18 Correct 92 ms 26680 KB Output is correct
19 Correct 86 ms 26708 KB Output is correct
20 Correct 96 ms 26628 KB Output is correct
21 Correct 74 ms 26716 KB Output is correct
22 Correct 53 ms 26704 KB Output is correct
23 Correct 55 ms 26744 KB Output is correct
24 Correct 56 ms 26704 KB Output is correct
25 Correct 53 ms 26688 KB Output is correct
26 Correct 55 ms 26708 KB Output is correct
27 Correct 104 ms 26728 KB Output is correct
28 Correct 54 ms 26716 KB Output is correct
29 Correct 72 ms 26716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 7 ms 21112 KB Output is correct
5 Correct 5 ms 21084 KB Output is correct
6 Correct 5 ms 21084 KB Output is correct
7 Correct 6 ms 21084 KB Output is correct
8 Correct 5 ms 21084 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 5 ms 21084 KB Output is correct
12 Correct 5 ms 21096 KB Output is correct
13 Correct 5 ms 21080 KB Output is correct
14 Correct 22 ms 22364 KB Output is correct
15 Correct 42 ms 23920 KB Output is correct
16 Correct 64 ms 24684 KB Output is correct
17 Correct 93 ms 26716 KB Output is correct
18 Correct 92 ms 26680 KB Output is correct
19 Correct 86 ms 26708 KB Output is correct
20 Correct 96 ms 26628 KB Output is correct
21 Correct 74 ms 26716 KB Output is correct
22 Correct 53 ms 26704 KB Output is correct
23 Correct 55 ms 26744 KB Output is correct
24 Correct 56 ms 26704 KB Output is correct
25 Correct 53 ms 26688 KB Output is correct
26 Correct 55 ms 26708 KB Output is correct
27 Correct 104 ms 26728 KB Output is correct
28 Correct 54 ms 26716 KB Output is correct
29 Correct 72 ms 26716 KB Output is correct
30 Correct 201 ms 48936 KB Output is correct
31 Correct 291 ms 52048 KB Output is correct
32 Correct 369 ms 52708 KB Output is correct
33 Correct 568 ms 54648 KB Output is correct
34 Correct 178 ms 50896 KB Output is correct
35 Correct 586 ms 54776 KB Output is correct
36 Correct 561 ms 54620 KB Output is correct
37 Correct 576 ms 54672 KB Output is correct
38 Correct 557 ms 54728 KB Output is correct
39 Correct 609 ms 54796 KB Output is correct
40 Correct 480 ms 54832 KB Output is correct
41 Correct 610 ms 54732 KB Output is correct
42 Correct 615 ms 54700 KB Output is correct
43 Correct 291 ms 54396 KB Output is correct
44 Correct 286 ms 53960 KB Output is correct
45 Correct 288 ms 54004 KB Output is correct
46 Correct 319 ms 52936 KB Output is correct
47 Correct 340 ms 52680 KB Output is correct
48 Correct 336 ms 54732 KB Output is correct
49 Correct 317 ms 54732 KB Output is correct