답안 #146044

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146044 2019-08-21T16:52:43 Z osaaateiasavtnl 운세 보기 2 (JOI14_fortune_telling2) C++14
100 / 100
475 ms 51796 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
const int N = 2e5 + 7, C = 3 * N;
int n, k; int a[N], b[N], t[N], r[C], mx[C << 2];
void build(int v, int tl, int tr) {
    if (tl == tr) { mx[v] = r[tl]; return; }
    int tm = (tl + tr) >> 1;
    build(v * 2 + 1, tl, tm); build(v * 2 + 2, tm + 1, tr);
    mx[v] = max(mx[v * 2 + 1], mx[v * 2 + 2]);
}
int get(int v, int tl, int tr, int l, int r) {
    if (tr < l || r < tl) return -1;
    if (l <= tl && tr <= r) return mx[v];
    int tm = (tl + tr) >> 1;
    return max(get(v * 2 + 1, tl, tm, l, r), get(v * 2 + 2, tm + 1, tr, l, r));
}
vector <int> c;
int pos(int x) { return lower_bound(c.begin(), c.end(), x) - c.begin(); }
int last[N], d[N];
vector <int> card[N];
int f[C];
void upd(int i) { i = C - i - 1; for (; i < C; i |= i + 1) ++f[i]; }
int get(int i) { i = C - i - 1; int ans = 0; for (; i >= 0; i &= i + 1, --i) ans += f[i]; return ans; }
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    for (int i = 0; i < C; ++i) r[i] = -1;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i]; c.app(a[i]); c.app(b[i]); }
    for (int i = 0; i < k; ++i) { cin >> t[i]; c.app(t[i]); }
    sort(all(c)); c.resize(unique(all(c)) - c.begin());
    for (int i = 0; i < n; ++i) { a[i] = pos(a[i]); b[i] = pos(b[i]); }
    for (int i = 0; i < k; ++i) { t[i] = pos(t[i]); r[t[i]] = i; }
    build(0, 0, C - 1);
    for (int i = 0; i < n; ++i) {
        last[i] = get(0, 0, C - 1, min(a[i], b[i]), max(a[i], b[i]) - 1);
        card[last[i] + 1].app(i);
    }
    for (int i = k - 1; i >= 0; --i) {
        upd(t[i]);
        for (int c : card[i]) {
            d[c] = get(max(a[c], b[c]));
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] < b[i] && last[i] == -1) ++d[i];
        if (d[i] & 1) { ans += c[min(a[i], b[i])]; }
        else { ans += c[max(a[i], b[i])]; }
    }
    cout << ans << '\n';
}   
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 26232 KB Output is correct
2 Correct 26 ms 26232 KB Output is correct
3 Correct 28 ms 26360 KB Output is correct
4 Correct 27 ms 26360 KB Output is correct
5 Correct 27 ms 26360 KB Output is correct
6 Correct 27 ms 26296 KB Output is correct
7 Correct 27 ms 26332 KB Output is correct
8 Correct 27 ms 26360 KB Output is correct
9 Correct 27 ms 26332 KB Output is correct
10 Correct 27 ms 26360 KB Output is correct
11 Correct 27 ms 26360 KB Output is correct
12 Correct 27 ms 26308 KB Output is correct
13 Correct 27 ms 26360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 26232 KB Output is correct
2 Correct 26 ms 26232 KB Output is correct
3 Correct 28 ms 26360 KB Output is correct
4 Correct 27 ms 26360 KB Output is correct
5 Correct 27 ms 26360 KB Output is correct
6 Correct 27 ms 26296 KB Output is correct
7 Correct 27 ms 26332 KB Output is correct
8 Correct 27 ms 26360 KB Output is correct
9 Correct 27 ms 26332 KB Output is correct
10 Correct 27 ms 26360 KB Output is correct
11 Correct 27 ms 26360 KB Output is correct
12 Correct 27 ms 26308 KB Output is correct
13 Correct 27 ms 26360 KB Output is correct
14 Correct 42 ms 27556 KB Output is correct
15 Correct 60 ms 28856 KB Output is correct
16 Correct 78 ms 30012 KB Output is correct
17 Correct 99 ms 31336 KB Output is correct
18 Correct 99 ms 31212 KB Output is correct
19 Correct 96 ms 31344 KB Output is correct
20 Correct 97 ms 31344 KB Output is correct
21 Correct 98 ms 31600 KB Output is correct
22 Correct 74 ms 30320 KB Output is correct
23 Correct 73 ms 30196 KB Output is correct
24 Correct 72 ms 30168 KB Output is correct
25 Correct 76 ms 30576 KB Output is correct
26 Correct 78 ms 30324 KB Output is correct
27 Correct 90 ms 30932 KB Output is correct
28 Correct 84 ms 31088 KB Output is correct
29 Correct 90 ms 31088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 26232 KB Output is correct
2 Correct 26 ms 26232 KB Output is correct
3 Correct 28 ms 26360 KB Output is correct
4 Correct 27 ms 26360 KB Output is correct
5 Correct 27 ms 26360 KB Output is correct
6 Correct 27 ms 26296 KB Output is correct
7 Correct 27 ms 26332 KB Output is correct
8 Correct 27 ms 26360 KB Output is correct
9 Correct 27 ms 26332 KB Output is correct
10 Correct 27 ms 26360 KB Output is correct
11 Correct 27 ms 26360 KB Output is correct
12 Correct 27 ms 26308 KB Output is correct
13 Correct 27 ms 26360 KB Output is correct
14 Correct 42 ms 27556 KB Output is correct
15 Correct 60 ms 28856 KB Output is correct
16 Correct 78 ms 30012 KB Output is correct
17 Correct 99 ms 31336 KB Output is correct
18 Correct 99 ms 31212 KB Output is correct
19 Correct 96 ms 31344 KB Output is correct
20 Correct 97 ms 31344 KB Output is correct
21 Correct 98 ms 31600 KB Output is correct
22 Correct 74 ms 30320 KB Output is correct
23 Correct 73 ms 30196 KB Output is correct
24 Correct 72 ms 30168 KB Output is correct
25 Correct 76 ms 30576 KB Output is correct
26 Correct 78 ms 30324 KB Output is correct
27 Correct 90 ms 30932 KB Output is correct
28 Correct 84 ms 31088 KB Output is correct
29 Correct 90 ms 31088 KB Output is correct
30 Correct 138 ms 33900 KB Output is correct
31 Correct 204 ms 37560 KB Output is correct
32 Correct 287 ms 42204 KB Output is correct
33 Correct 464 ms 51752 KB Output is correct
34 Correct 121 ms 33000 KB Output is correct
35 Correct 469 ms 51796 KB Output is correct
36 Correct 468 ms 51412 KB Output is correct
37 Correct 475 ms 51512 KB Output is correct
38 Correct 457 ms 51668 KB Output is correct
39 Correct 473 ms 51412 KB Output is correct
40 Correct 452 ms 51084 KB Output is correct
41 Correct 463 ms 51380 KB Output is correct
42 Correct 462 ms 51284 KB Output is correct
43 Correct 306 ms 48216 KB Output is correct
44 Correct 307 ms 48700 KB Output is correct
45 Correct 310 ms 49364 KB Output is correct
46 Correct 302 ms 46804 KB Output is correct
47 Correct 293 ms 46164 KB Output is correct
48 Correct 370 ms 50004 KB Output is correct
49 Correct 345 ms 50260 KB Output is correct