답안 #1052844

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052844 2024-08-11T04:34:23 Z phong 운세 보기 2 (JOI14_fortune_telling2) C++17
100 / 100
103 ms 17216 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

#define ll long long
const int nmax = 2e5 + 5, N = 1e6;
const ll oo = 1e9 + 5, base = 311;
const int lg = 17, tx = 26;
const ll mod = 998244353;
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;

int n, k;
pii  c[nmax];
struct node{
    int first, second, id;
}a[nmax];
int L[nmax];

struct SEG{
    int tree[nmax << 2];
    void update(int id, int l, int r, int u, int val){
        if(l > u|| r < u)return;
        if(l >= u && r <= u){
            tree[id] = val;
            return;
        }
        int mid = r + l >> 1;
        update(id << 1, l, mid, u, val);
        update(id << 1 | 1, mid + 1, r, u, val);
        tree[id] = max(tree[id << 1], tree[id << 1 | 1]);
    }
    int get(int val){
        if(tree[1] < val) return 0;
        int id = 1, l = 1, r = k;
        while(l != r){
            int mid = r + l >> 1;
            if(tree[id << 1 | 1] >= val){
                id = id << 1 | 1;
                l = mid + 1;
            }
            else{
                id = id << 1;
                r = mid;
            }
        }
        return l;
    }
}tree;
struct BIT{
    int f[nmax];
    void update(int u, int val){
        for(; u; u -= u&-u) f[u] += val;
    }
    int get(int u){
        int res = 0;
        for(; u <= k; u += u&-u) res += f[u];
        return res;
    }
}F;
int d[nmax];

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen("code.inp", "r", stdin);
//    freopen("code.out", "w", stdout);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) cin >> a[i].fi >> a[i].se, a[i].id = i;
    for(int i = 1; i <= k; ++i) cin >> c[i].fi, c[i].se = i, d[i] = c[i].fi;
    sort(a + 1, a + 1 + n, [](node a, node b){
         return max(a.fi, a.se) < max(b.fi, b.se);
         });
    sort(c + 1, c + 1 + k);
    int pos = 1;//
    for(int i = 1; i <= n; ++i){
        while(pos <= k && c[pos].fi < max(a[i].fi, a[i].se)){
            tree.update(1, 1, k, c[pos].se, c[pos].fi);
            ++pos;
        }
        L[i] = tree.get(min(a[i].fi, a[i].se));
    }
    pos = k;//
    ll ans = 0;
    for(int i = n; i >= 1; --i){
        while(pos >= 1 && c[pos].fi >= max(a[i].fi, a[i].se)){
            F.update(c[pos].se, 1);
            --pos;
        }
        int x = L[i];
        bool idx = 0;
        int val = F.get(L[i] + 1);

        if(L[i] > 0){
            if(d[L[i]] >= a[i].fi){
                idx = 1;
            }
            else{
                idx = 0;
            }
        }
        if(val & 1) idx ^= 1;
        if(!idx) ans += a[i].fi;
        else ans += a[i].se;
//        cout << a[i].id << ' ' << val << endl;
    }
    cout << ans;
}
/*
2 3
1 4
4 1
2 6 5
*/

Compilation message

fortune_telling2.cpp: In member function 'void SEG::update(int, int, int, int, int)':
fortune_telling2.cpp:33:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |         int mid = r + l >> 1;
      |                   ~~^~~
fortune_telling2.cpp: In member function 'int SEG::get(int)':
fortune_telling2.cpp:42:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |             int mid = r + l >> 1;
      |                       ~~^~~
fortune_telling2.cpp: At global scope:
fortune_telling2.cpp:68:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   68 | main(){
      | ^~~~
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:95:13: warning: unused variable 'x' [-Wunused-variable]
   95 |         int x = L[i];
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6656 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 6596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6656 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 6596 KB Output is correct
14 Correct 5 ms 6744 KB Output is correct
15 Correct 9 ms 7260 KB Output is correct
16 Correct 13 ms 7516 KB Output is correct
17 Correct 17 ms 9820 KB Output is correct
18 Correct 17 ms 9820 KB Output is correct
19 Correct 20 ms 9816 KB Output is correct
20 Correct 17 ms 9820 KB Output is correct
21 Correct 16 ms 9816 KB Output is correct
22 Correct 13 ms 9288 KB Output is correct
23 Correct 14 ms 9308 KB Output is correct
24 Correct 13 ms 9304 KB Output is correct
25 Correct 13 ms 9308 KB Output is correct
26 Correct 15 ms 9820 KB Output is correct
27 Correct 17 ms 9992 KB Output is correct
28 Correct 18 ms 9816 KB Output is correct
29 Correct 20 ms 8532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6656 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 6596 KB Output is correct
14 Correct 5 ms 6744 KB Output is correct
15 Correct 9 ms 7260 KB Output is correct
16 Correct 13 ms 7516 KB Output is correct
17 Correct 17 ms 9820 KB Output is correct
18 Correct 17 ms 9820 KB Output is correct
19 Correct 20 ms 9816 KB Output is correct
20 Correct 17 ms 9820 KB Output is correct
21 Correct 16 ms 9816 KB Output is correct
22 Correct 13 ms 9288 KB Output is correct
23 Correct 14 ms 9308 KB Output is correct
24 Correct 13 ms 9304 KB Output is correct
25 Correct 13 ms 9308 KB Output is correct
26 Correct 15 ms 9820 KB Output is correct
27 Correct 17 ms 9992 KB Output is correct
28 Correct 18 ms 9816 KB Output is correct
29 Correct 20 ms 8532 KB Output is correct
30 Correct 53 ms 13396 KB Output is correct
31 Correct 59 ms 14300 KB Output is correct
32 Correct 72 ms 15188 KB Output is correct
33 Correct 90 ms 17148 KB Output is correct
34 Correct 43 ms 13144 KB Output is correct
35 Correct 92 ms 16972 KB Output is correct
36 Correct 92 ms 16980 KB Output is correct
37 Correct 94 ms 16980 KB Output is correct
38 Correct 89 ms 17092 KB Output is correct
39 Correct 90 ms 16980 KB Output is correct
40 Correct 103 ms 16880 KB Output is correct
41 Correct 102 ms 17080 KB Output is correct
42 Correct 94 ms 16980 KB Output is correct
43 Correct 71 ms 16468 KB Output is correct
44 Correct 83 ms 16316 KB Output is correct
45 Correct 71 ms 16472 KB Output is correct
46 Correct 73 ms 15336 KB Output is correct
47 Correct 74 ms 14932 KB Output is correct
48 Correct 86 ms 17216 KB Output is correct
49 Correct 85 ms 17088 KB Output is correct