Submission #52218

# Submission time Handle Problem Language Result Execution time Memory
52218 2018-06-25T05:08:04 Z 강태규(#1345) Fortune Telling 2 (JOI14_fortune_telling2) C++11
100 / 100
278 ms 9472 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

struct card {
    int a, b, t;
    void scan() {
        scanf("%d%d", &a, &b);
        if (a > b) swap(a, b), t = 1;
        else t = 0;
    }
    bool operator<(const card &c) const {
        return a > c.a;
    }
};

const int MAXN = 2e5 + 1;
int n, k;
card cs[MAXN];
int t[MAXN];
pii ct[MAXN];
int segm[1 << 19];
int segs[1 << 19];

int queryMax(int i, int s, int e, int x) {
    if (x <= segm[i]) return 0;
    if (s == e) return s;
    int m = (s + e) / 2;
    int ret = queryMax(i << 1 | 1, m + 1, e, x);
    if (ret) return ret;
    return queryMax(i << 1, s, m, x);
}

void update(int i, int s, int e, int x, int v) {
    if (s == e) {
        segm[i] = v;
        segs[i] = 1;
        return;
    }
    int m = (s + e) / 2;
    if (x <= m) update(i << 1, s, m, x, v);
    else update(i << 1 | 1, m + 1, e, x, v);
    segm[i] = min(segm[i << 1], segm[i << 1 | 1]);
    segs[i] = segs[i << 1] + segs[i << 1 | 1];
}

int querySum(int i, int s, int e, int x, int y) {
    if (e < x || y < s) return 0;
    if (x <= s && e <= y) return segs[i];
    int m = (s + e) / 2;
    return querySum(i << 1, s, m, x, y) + querySum(i << 1 | 1, m + 1, e, x, y);
}

const int inf = 1e9 + 7;
int main() {
    for (int i = 0; i < (1 << 19); ++i) segm[i] = inf;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i) {
        cs[i].scan();
    }
    for (int i = 1; i <= k; ++i) {
        scanf("%d", t + i);
        ct[i - 1] = { t[i], i };
    }
    sort(cs, cs + n);
    sort(ct, ct + k, greater<pii>());
    llong ans = 0;
    for (int i = 0, j = 0; i < n; ++i) {
        while (j < k && cs[i].a <= ct[j].first) {
            update(1, 1, k, ct[j].second, ct[j].first);
            ++j;
        }
        int x = queryMax(1, 1, k, cs[i].b);
        if (x) cs[i].t = 1;
        int cnt = querySum(1, 1, k, x + 1, k) % 2;
        if (cnt ^ cs[i].t) ans += cs[i].b;
        else ans += cs[i].a;
    }
    printf("%lld\n", ans);
	return 0;
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
fortune_telling2.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", t + i);
         ~~~~~^~~~~~~~~~~~~
fortune_telling2.cpp: In member function 'void card::scan()':
fortune_telling2.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2428 KB Output is correct
2 Correct 4 ms 2532 KB Output is correct
3 Correct 4 ms 2612 KB Output is correct
4 Correct 4 ms 2612 KB Output is correct
5 Correct 5 ms 2612 KB Output is correct
6 Correct 4 ms 2612 KB Output is correct
7 Correct 4 ms 2612 KB Output is correct
8 Correct 4 ms 2612 KB Output is correct
9 Correct 4 ms 2684 KB Output is correct
10 Correct 4 ms 2684 KB Output is correct
11 Correct 5 ms 2684 KB Output is correct
12 Correct 4 ms 2684 KB Output is correct
13 Correct 5 ms 2684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2428 KB Output is correct
2 Correct 4 ms 2532 KB Output is correct
3 Correct 4 ms 2612 KB Output is correct
4 Correct 4 ms 2612 KB Output is correct
5 Correct 5 ms 2612 KB Output is correct
6 Correct 4 ms 2612 KB Output is correct
7 Correct 4 ms 2612 KB Output is correct
8 Correct 4 ms 2612 KB Output is correct
9 Correct 4 ms 2684 KB Output is correct
10 Correct 4 ms 2684 KB Output is correct
11 Correct 5 ms 2684 KB Output is correct
12 Correct 4 ms 2684 KB Output is correct
13 Correct 5 ms 2684 KB Output is correct
14 Correct 13 ms 2980 KB Output is correct
15 Correct 24 ms 3280 KB Output is correct
16 Correct 35 ms 3536 KB Output is correct
17 Correct 49 ms 4048 KB Output is correct
18 Correct 65 ms 4048 KB Output is correct
19 Correct 48 ms 4076 KB Output is correct
20 Correct 56 ms 4076 KB Output is correct
21 Correct 49 ms 4092 KB Output is correct
22 Correct 35 ms 4092 KB Output is correct
23 Correct 36 ms 4092 KB Output is correct
24 Correct 40 ms 4092 KB Output is correct
25 Correct 38 ms 4152 KB Output is correct
26 Correct 39 ms 4152 KB Output is correct
27 Correct 48 ms 4152 KB Output is correct
28 Correct 51 ms 4152 KB Output is correct
29 Correct 45 ms 4152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2428 KB Output is correct
2 Correct 4 ms 2532 KB Output is correct
3 Correct 4 ms 2612 KB Output is correct
4 Correct 4 ms 2612 KB Output is correct
5 Correct 5 ms 2612 KB Output is correct
6 Correct 4 ms 2612 KB Output is correct
7 Correct 4 ms 2612 KB Output is correct
8 Correct 4 ms 2612 KB Output is correct
9 Correct 4 ms 2684 KB Output is correct
10 Correct 4 ms 2684 KB Output is correct
11 Correct 5 ms 2684 KB Output is correct
12 Correct 4 ms 2684 KB Output is correct
13 Correct 5 ms 2684 KB Output is correct
14 Correct 13 ms 2980 KB Output is correct
15 Correct 24 ms 3280 KB Output is correct
16 Correct 35 ms 3536 KB Output is correct
17 Correct 49 ms 4048 KB Output is correct
18 Correct 65 ms 4048 KB Output is correct
19 Correct 48 ms 4076 KB Output is correct
20 Correct 56 ms 4076 KB Output is correct
21 Correct 49 ms 4092 KB Output is correct
22 Correct 35 ms 4092 KB Output is correct
23 Correct 36 ms 4092 KB Output is correct
24 Correct 40 ms 4092 KB Output is correct
25 Correct 38 ms 4152 KB Output is correct
26 Correct 39 ms 4152 KB Output is correct
27 Correct 48 ms 4152 KB Output is correct
28 Correct 51 ms 4152 KB Output is correct
29 Correct 45 ms 4152 KB Output is correct
30 Correct 132 ms 7208 KB Output is correct
31 Correct 153 ms 7676 KB Output is correct
32 Correct 201 ms 8168 KB Output is correct
33 Correct 273 ms 9368 KB Output is correct
34 Correct 124 ms 9368 KB Output is correct
35 Correct 273 ms 9368 KB Output is correct
36 Correct 252 ms 9424 KB Output is correct
37 Correct 270 ms 9468 KB Output is correct
38 Correct 263 ms 9468 KB Output is correct
39 Correct 278 ms 9468 KB Output is correct
40 Correct 255 ms 9472 KB Output is correct
41 Correct 263 ms 9472 KB Output is correct
42 Correct 257 ms 9472 KB Output is correct
43 Correct 188 ms 9472 KB Output is correct
44 Correct 192 ms 9472 KB Output is correct
45 Correct 213 ms 9472 KB Output is correct
46 Correct 210 ms 9472 KB Output is correct
47 Correct 219 ms 9472 KB Output is correct
48 Correct 246 ms 9472 KB Output is correct
49 Correct 277 ms 9472 KB Output is correct