Submission #118676

# Submission time Handle Problem Language Result Execution time Memory
118676 2019-06-19T10:56:09 Z evpipis Fortune Telling 2 (JOI14_fortune_telling2) C++17
35 / 100
3000 ms 203744 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int, int> ii;
typedef long long ll;

const int len = 2e5+5, mx = 1e9;
ii arr[len];
int num[len], n, m;

struct node{
    int sum;
    node *left, *right;

    node(int s = 0, node *l = NULL, node *r = NULL){
        sum = s;
        left = l;
        right = r;
    }
};

typedef node* pnode;

pnode suf[len], null = new node();

pnode add(pnode t, int l, int r, int i){
    if (l == r)
        return new node(t->sum+1, null, null);

    int mid = (l+r)/2;
    if (i <= mid)
        return new node(t->sum+1, add(t->left, l, mid, i), t->right);
    return new node(t->sum+1, t->left, add(t->right, mid+1, r, i));
}

int ask(pnode t, int l, int r, int i, int j){
    if (r < i || j < l)
        return 0;
    if (i <= l && r <= j)
        return t->sum;

    int mid = (l+r)/2;
    return ask(t->left, l, mid, i, j)+ask(t->right, mid+1, r, i, j);
}

int bs(int a, int b){
    if (a > b)
        return 0;

    int l = 1, r = m, ans = 0;
    while (l <= r){
        int mid = (l+r)/2;
        if (ask(suf[mid], 1, mx, a, b) > 0)
            ans = mid, l = mid+1;
        else
            r = mid-1;
    }

    return ans;
}

int main(){
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%d %d", &arr[i].fi, &arr[i].se);

    for (int i = 1; i <= m; i++)
        scanf("%d", &num[i]);

    suf[m+1] = null->left = null->right = null;
    for (int i = m; i >= 1; i--)
        suf[i] = add(suf[i+1], 1, mx, num[i]);

    ll ans = 0;
    for (int i = 1; i <= n; i++){
        int l = arr[i].fi, r = arr[i].se;
        int pos = bs(min(l, r), max(l, r)-1);
        int cnt = ask(suf[pos+1], 1, mx, max(l, r), mx);

        if (pos == 0){
            if (cnt%2 == 0)
                ans += l;
            else
                ans += r;
        }
        else{
            if (cnt%2 == 0)
                ans += max(l, r);
            else
                ans += min(l, r);
        }
    }

    printf("%lld\n", ans);
    return 0;
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
fortune_telling2.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &arr[i].fi, &arr[i].se);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &num[i]);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 6 ms 1280 KB Output is correct
3 Correct 8 ms 1408 KB Output is correct
4 Correct 8 ms 1280 KB Output is correct
5 Correct 7 ms 1280 KB Output is correct
6 Correct 8 ms 1408 KB Output is correct
7 Correct 7 ms 1408 KB Output is correct
8 Correct 8 ms 1408 KB Output is correct
9 Correct 7 ms 1280 KB Output is correct
10 Correct 6 ms 1280 KB Output is correct
11 Correct 7 ms 1280 KB Output is correct
12 Correct 7 ms 1280 KB Output is correct
13 Correct 7 ms 1404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 6 ms 1280 KB Output is correct
3 Correct 8 ms 1408 KB Output is correct
4 Correct 8 ms 1280 KB Output is correct
5 Correct 7 ms 1280 KB Output is correct
6 Correct 8 ms 1408 KB Output is correct
7 Correct 7 ms 1408 KB Output is correct
8 Correct 8 ms 1408 KB Output is correct
9 Correct 7 ms 1280 KB Output is correct
10 Correct 6 ms 1280 KB Output is correct
11 Correct 7 ms 1280 KB Output is correct
12 Correct 7 ms 1280 KB Output is correct
13 Correct 7 ms 1404 KB Output is correct
14 Correct 77 ms 10564 KB Output is correct
15 Correct 163 ms 20828 KB Output is correct
16 Correct 267 ms 30932 KB Output is correct
17 Correct 412 ms 41060 KB Output is correct
18 Correct 371 ms 41076 KB Output is correct
19 Correct 367 ms 40952 KB Output is correct
20 Correct 372 ms 41080 KB Output is correct
21 Correct 332 ms 40952 KB Output is correct
22 Correct 243 ms 40572 KB Output is correct
23 Correct 236 ms 40568 KB Output is correct
24 Correct 237 ms 40752 KB Output is correct
25 Correct 241 ms 40568 KB Output is correct
26 Correct 287 ms 40824 KB Output is correct
27 Correct 348 ms 41080 KB Output is correct
28 Correct 316 ms 40952 KB Output is correct
29 Correct 406 ms 41140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 6 ms 1280 KB Output is correct
3 Correct 8 ms 1408 KB Output is correct
4 Correct 8 ms 1280 KB Output is correct
5 Correct 7 ms 1280 KB Output is correct
6 Correct 8 ms 1408 KB Output is correct
7 Correct 7 ms 1408 KB Output is correct
8 Correct 8 ms 1408 KB Output is correct
9 Correct 7 ms 1280 KB Output is correct
10 Correct 6 ms 1280 KB Output is correct
11 Correct 7 ms 1280 KB Output is correct
12 Correct 7 ms 1280 KB Output is correct
13 Correct 7 ms 1404 KB Output is correct
14 Correct 77 ms 10564 KB Output is correct
15 Correct 163 ms 20828 KB Output is correct
16 Correct 267 ms 30932 KB Output is correct
17 Correct 412 ms 41060 KB Output is correct
18 Correct 371 ms 41076 KB Output is correct
19 Correct 367 ms 40952 KB Output is correct
20 Correct 372 ms 41080 KB Output is correct
21 Correct 332 ms 40952 KB Output is correct
22 Correct 243 ms 40572 KB Output is correct
23 Correct 236 ms 40568 KB Output is correct
24 Correct 237 ms 40752 KB Output is correct
25 Correct 241 ms 40568 KB Output is correct
26 Correct 287 ms 40824 KB Output is correct
27 Correct 348 ms 41080 KB Output is correct
28 Correct 316 ms 40952 KB Output is correct
29 Correct 406 ms 41140 KB Output is correct
30 Correct 583 ms 198616 KB Output is correct
31 Correct 1119 ms 199784 KB Output is correct
32 Correct 1740 ms 201064 KB Output is correct
33 Correct 2950 ms 203744 KB Output is correct
34 Correct 489 ms 198264 KB Output is correct
35 Correct 2965 ms 203744 KB Output is correct
36 Execution timed out 3038 ms 203728 KB Time limit exceeded
37 Halted 0 ms 0 KB -