답안 #930457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930457 2024-02-19T20:29:49 Z parlimoos 운세 보기 2 (JOI14_fortune_telling2) C++14
100 / 100
369 ms 59848 KB
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<ll , x>
#define endl '\n'

int n , q;
vector<arr(2)> a;
vector<int> ops;
vector<int> seg[800001];
int seginf[800001][2];

void buildSeg(int l = 0 , int r = q - 1 , int i = 1){
    seginf[i][0] = l , seginf[i][1] = r;
    if(l == r) seg[i].pb(ops[l]);
    else{
        int c = (r + l - 1) >> 1;
        buildSeg(l , c , i << 1) , buildSeg(c + 1 , r , (i << 1) | 1);
        seg[i].resize(r - l + 1);
        merge(seg[i << 1].bg() , seg[i << 1].end() , seg[(i << 1) | 1].bg() , seg[(i << 1) | 1].end() , seg[i].bg());
    }
}
int bsSeg(int i , int l , int r){
    if(i == 1){
        auto itr = lb(seg[i].bg() , seg[i].end() , l);
        if(itr == seg[i].end() or *itr > r) return seginf[i][0];
    }
    if(seginf[i][0] == seginf[i][1]) return seginf[i][1] + 1;
    auto itr = lb(seg[(i << 1) | 1].bg() , seg[(i << 1) | 1].end() , l);
    if(itr != seg[(i << 1) | 1].end() and *itr <= r) return bsSeg((i << 1) | 1 , l , r);
    return bsSeg(i << 1 , l , r);
}
int cntSeg(int l , int r , int i , int val){
    if(seginf[i][0] >= l and seginf[i][1] <= r) return (seginf[i][1] - seginf[i][0] + 1 - int(lb(seg[i].bg() , seg[i].end() , val) - seg[i].bg()));
    if(seginf[i][1] >= l and seginf[i][0] <= r) return (cntSeg(l , r , i << 1 , val) + cntSeg(l , r , (i << 1) | 1 , val));
    return 0;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> q;
    for(int i = 0 ; i < n ; i++){
        int d1 , d2;
        cin >> d1 >> d2;
        a.pb({d1 , d2});
    }
    for(int i = 0 ; i < q ; i++){
        int d;
        cin >> d;
        ops.pb(d);
    }
    ll o = 0;
    buildSeg();
    for(auto el : a){
        if(el[0] == el[1]){
            o += el[0];
        }else if(el[0] < el[1]){
            int inx = bsSeg(1 , el[0] , el[1] - 1);
            int d = 0;
            if(inx < q) d = cntSeg(inx , q - 1 , 1 , el[1]);
            if(inx == 0){
                if((d & 1)) o += el[1];
                else o += el[0];
            }else{
                if((d & 1)) o += el[0];
                else o += el[1];
            }
        }else if(el[1] < el[0]){
            int inx = bsSeg(1 , el[1] , el[0] - 1);
            int d = 0;
            if(inx < q) d = cntSeg(inx , q - 1 , 1 , el[0]);
            if((d & 1)) o += el[1];
            else o += el[0];
        }
    }
    cout << o;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 21084 KB Output is correct
2 Correct 7 ms 21340 KB Output is correct
3 Correct 7 ms 21192 KB Output is correct
4 Correct 7 ms 21180 KB Output is correct
5 Correct 8 ms 21340 KB Output is correct
6 Correct 8 ms 21356 KB Output is correct
7 Correct 8 ms 21336 KB Output is correct
8 Correct 10 ms 21176 KB Output is correct
9 Correct 7 ms 21340 KB Output is correct
10 Correct 7 ms 21340 KB Output is correct
11 Correct 8 ms 21340 KB Output is correct
12 Correct 7 ms 21340 KB Output is correct
13 Correct 10 ms 21592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 21084 KB Output is correct
2 Correct 7 ms 21340 KB Output is correct
3 Correct 7 ms 21192 KB Output is correct
4 Correct 7 ms 21180 KB Output is correct
5 Correct 8 ms 21340 KB Output is correct
6 Correct 8 ms 21356 KB Output is correct
7 Correct 8 ms 21336 KB Output is correct
8 Correct 10 ms 21176 KB Output is correct
9 Correct 7 ms 21340 KB Output is correct
10 Correct 7 ms 21340 KB Output is correct
11 Correct 8 ms 21340 KB Output is correct
12 Correct 7 ms 21340 KB Output is correct
13 Correct 10 ms 21592 KB Output is correct
14 Correct 19 ms 24540 KB Output is correct
15 Correct 32 ms 25820 KB Output is correct
16 Correct 43 ms 27140 KB Output is correct
17 Correct 57 ms 28632 KB Output is correct
18 Correct 57 ms 28632 KB Output is correct
19 Correct 59 ms 28544 KB Output is correct
20 Correct 62 ms 28628 KB Output is correct
21 Correct 48 ms 28632 KB Output is correct
22 Correct 35 ms 28632 KB Output is correct
23 Correct 40 ms 28632 KB Output is correct
24 Correct 38 ms 28364 KB Output is correct
25 Correct 33 ms 28628 KB Output is correct
26 Correct 36 ms 28376 KB Output is correct
27 Correct 60 ms 28620 KB Output is correct
28 Correct 37 ms 28632 KB Output is correct
29 Correct 51 ms 28528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 21084 KB Output is correct
2 Correct 7 ms 21340 KB Output is correct
3 Correct 7 ms 21192 KB Output is correct
4 Correct 7 ms 21180 KB Output is correct
5 Correct 8 ms 21340 KB Output is correct
6 Correct 8 ms 21356 KB Output is correct
7 Correct 8 ms 21336 KB Output is correct
8 Correct 10 ms 21176 KB Output is correct
9 Correct 7 ms 21340 KB Output is correct
10 Correct 7 ms 21340 KB Output is correct
11 Correct 8 ms 21340 KB Output is correct
12 Correct 7 ms 21340 KB Output is correct
13 Correct 10 ms 21592 KB Output is correct
14 Correct 19 ms 24540 KB Output is correct
15 Correct 32 ms 25820 KB Output is correct
16 Correct 43 ms 27140 KB Output is correct
17 Correct 57 ms 28632 KB Output is correct
18 Correct 57 ms 28632 KB Output is correct
19 Correct 59 ms 28544 KB Output is correct
20 Correct 62 ms 28628 KB Output is correct
21 Correct 48 ms 28632 KB Output is correct
22 Correct 35 ms 28632 KB Output is correct
23 Correct 40 ms 28632 KB Output is correct
24 Correct 38 ms 28364 KB Output is correct
25 Correct 33 ms 28628 KB Output is correct
26 Correct 36 ms 28376 KB Output is correct
27 Correct 60 ms 28620 KB Output is correct
28 Correct 37 ms 28632 KB Output is correct
29 Correct 51 ms 28528 KB Output is correct
30 Correct 86 ms 49996 KB Output is correct
31 Correct 149 ms 53836 KB Output is correct
32 Correct 208 ms 55288 KB Output is correct
33 Correct 338 ms 58816 KB Output is correct
34 Correct 73 ms 51852 KB Output is correct
35 Correct 345 ms 58808 KB Output is correct
36 Correct 340 ms 59848 KB Output is correct
37 Correct 343 ms 59492 KB Output is correct
38 Correct 334 ms 58828 KB Output is correct
39 Correct 369 ms 58772 KB Output is correct
40 Correct 249 ms 59284 KB Output is correct
41 Correct 360 ms 59024 KB Output is correct
42 Correct 365 ms 58888 KB Output is correct
43 Correct 159 ms 58892 KB Output is correct
44 Correct 153 ms 59072 KB Output is correct
45 Correct 156 ms 59068 KB Output is correct
46 Correct 181 ms 57628 KB Output is correct
47 Correct 196 ms 57536 KB Output is correct
48 Correct 199 ms 58808 KB Output is correct
49 Correct 181 ms 59068 KB Output is correct