Submission #76733

# Submission time Handle Problem Language Result Execution time Memory
76733 2018-09-16T18:23:22 Z kdh9949 Fortune Telling 2 (JOI14_fortune_telling2) C++17
100 / 100
859 ms 59956 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define all(v) (v).begin(),(v).end()

const int N = 200005, sz = 262144;
int n, m, a[N], b[N], c[N], t[N], x[N];
ll r;

struct Seg{
    vector<int> v[2 * sz];
    int u(int x, int y){
        for(x += sz; x; x >>= 1) v[x].push_back(y);
    }
    int m(int s, int e){
        int r = 0;
        for(s += sz, e += sz; s <= e; s >>= 1, e >>= 1){
            if( s & 1){ if(!v[s].empty()) r = max(r, v[s].back()); s++; }
            if(~e & 1){ if(!v[e].empty()) r = max(r, v[e].back()); e--; }
        }
        return r;
    }
    int c(int s, int e, int x){
        int r = 0;
        for(s += sz, e += sz; s <= e; s >>= 1, e >>= 1){
            if( s & 1){ r ^= int(v[s].end() - lower_bound(all(v[s]), x)); s++; }
            if(~e & 1){ r ^= int(v[e].end() - lower_bound(all(v[e]), x)); e--; }
        }
        return r & 1;
    }
} S;

int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++){
        scanf("%d%d", a + i, b + i);
        if(a[i] > b[i]){ c[i] = 1; swap(a[i], b[i]); }
    }
    for(int i = 1; i <= m; i++){
        scanf("%d", t + i);
        x[i - 1] = t[i];
    }
    sort(x, x + m);
    for(int i = 1; i <= m; i++){
        t[i] = int(lower_bound(x, x + m, t[i]) - x + 1);
        S.u(t[i], i);
    }
    for(int i = 1; i <= n; i++){
        int p = int(lower_bound(x, x + m, a[i]) - x + 1);
        int q = int(lower_bound(x, x + m, b[i]) - x);
        int t = S.m(p, q);
        r += (S.c(q + 1, m, t + 1) ^ (!t & !c[i])) ? a[i] : b[i];
    }
    printf("%lld\n", r);
}

Compilation message

fortune_telling2.cpp: In member function 'int Seg::u(int, int)':
fortune_telling2.cpp:15:5: warning: no return statement in function returning non-void [-Wreturn-type]
     }
     ^
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:35: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:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", a + i, b + i);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", t + i);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12792 KB Output is correct
2 Correct 13 ms 12796 KB Output is correct
3 Correct 14 ms 12876 KB Output is correct
4 Correct 14 ms 12904 KB Output is correct
5 Correct 14 ms 13068 KB Output is correct
6 Correct 20 ms 13144 KB Output is correct
7 Correct 14 ms 13144 KB Output is correct
8 Correct 14 ms 13144 KB Output is correct
9 Correct 13 ms 13304 KB Output is correct
10 Correct 14 ms 13304 KB Output is correct
11 Correct 13 ms 13304 KB Output is correct
12 Correct 13 ms 13304 KB Output is correct
13 Correct 15 ms 13304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12792 KB Output is correct
2 Correct 13 ms 12796 KB Output is correct
3 Correct 14 ms 12876 KB Output is correct
4 Correct 14 ms 12904 KB Output is correct
5 Correct 14 ms 13068 KB Output is correct
6 Correct 20 ms 13144 KB Output is correct
7 Correct 14 ms 13144 KB Output is correct
8 Correct 14 ms 13144 KB Output is correct
9 Correct 13 ms 13304 KB Output is correct
10 Correct 14 ms 13304 KB Output is correct
11 Correct 13 ms 13304 KB Output is correct
12 Correct 13 ms 13304 KB Output is correct
13 Correct 15 ms 13304 KB Output is correct
14 Correct 32 ms 14988 KB Output is correct
15 Correct 61 ms 17072 KB Output is correct
16 Correct 91 ms 19188 KB Output is correct
17 Correct 107 ms 21816 KB Output is correct
18 Correct 106 ms 23024 KB Output is correct
19 Correct 108 ms 24072 KB Output is correct
20 Correct 121 ms 25236 KB Output is correct
21 Correct 136 ms 26416 KB Output is correct
22 Correct 85 ms 27048 KB Output is correct
23 Correct 80 ms 27712 KB Output is correct
24 Correct 84 ms 27712 KB Output is correct
25 Correct 81 ms 27784 KB Output is correct
26 Correct 92 ms 27788 KB Output is correct
27 Correct 142 ms 27916 KB Output is correct
28 Correct 95 ms 27916 KB Output is correct
29 Correct 106 ms 27916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12792 KB Output is correct
2 Correct 13 ms 12796 KB Output is correct
3 Correct 14 ms 12876 KB Output is correct
4 Correct 14 ms 12904 KB Output is correct
5 Correct 14 ms 13068 KB Output is correct
6 Correct 20 ms 13144 KB Output is correct
7 Correct 14 ms 13144 KB Output is correct
8 Correct 14 ms 13144 KB Output is correct
9 Correct 13 ms 13304 KB Output is correct
10 Correct 14 ms 13304 KB Output is correct
11 Correct 13 ms 13304 KB Output is correct
12 Correct 13 ms 13304 KB Output is correct
13 Correct 15 ms 13304 KB Output is correct
14 Correct 32 ms 14988 KB Output is correct
15 Correct 61 ms 17072 KB Output is correct
16 Correct 91 ms 19188 KB Output is correct
17 Correct 107 ms 21816 KB Output is correct
18 Correct 106 ms 23024 KB Output is correct
19 Correct 108 ms 24072 KB Output is correct
20 Correct 121 ms 25236 KB Output is correct
21 Correct 136 ms 26416 KB Output is correct
22 Correct 85 ms 27048 KB Output is correct
23 Correct 80 ms 27712 KB Output is correct
24 Correct 84 ms 27712 KB Output is correct
25 Correct 81 ms 27784 KB Output is correct
26 Correct 92 ms 27788 KB Output is correct
27 Correct 142 ms 27916 KB Output is correct
28 Correct 95 ms 27916 KB Output is correct
29 Correct 106 ms 27916 KB Output is correct
30 Correct 470 ms 48220 KB Output is correct
31 Correct 524 ms 48664 KB Output is correct
32 Correct 674 ms 49296 KB Output is correct
33 Correct 825 ms 50516 KB Output is correct
34 Correct 425 ms 50516 KB Output is correct
35 Correct 844 ms 50560 KB Output is correct
36 Correct 814 ms 50560 KB Output is correct
37 Correct 809 ms 51188 KB Output is correct
38 Correct 859 ms 51188 KB Output is correct
39 Correct 827 ms 51640 KB Output is correct
40 Correct 684 ms 57216 KB Output is correct
41 Correct 770 ms 57812 KB Output is correct
42 Correct 774 ms 57892 KB Output is correct
43 Correct 406 ms 57892 KB Output is correct
44 Correct 433 ms 57892 KB Output is correct
45 Correct 417 ms 57892 KB Output is correct
46 Correct 505 ms 57892 KB Output is correct
47 Correct 583 ms 57892 KB Output is correct
48 Correct 651 ms 57912 KB Output is correct
49 Correct 650 ms 59956 KB Output is correct