Submission #1100722

# Submission time Handle Problem Language Result Execution time Memory
1100722 2024-10-14T13:55:58 Z vjudge1 Fortune Telling 2 (JOI14_fortune_telling2) C++17
100 / 100
233 ms 180400 KB
#include <bits/stdc++.h>
#define ll long long
#define task ""
using namespace std;
const ll maxn = 1e6 + 2, LG = 20, mod = 1e9 + 7, inf = 1e18;
ll n, m, k, a[maxn], b[maxn], t[maxn], fw[maxn], st[LG][maxn], res = 0;
vector<ll> v, events[maxn];
int rmq (int l, int r)
{
    if (l > r) return 0;
    int k = __lg(r - l + 1);
    return max(st[k][l], st[k][r - (1 << k) + 1]);
}
void upd (int idx)
{
    while (idx <= m)
    {
        fw[idx]++;
        idx += (idx & (-idx));
    }
}
int get (int idx)
{
    int res = 0;
    while (idx > 0)
    {
        res += fw[idx];
        idx -= (idx & (-idx));
    }
    return res;
}
int main()
{
    //freopen(task".INP", "r", stdin);
    //freopen(task".OUT", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i];
        v.push_back(a[i]);
        v.push_back(b[i]);
    }
    for (int i = 1; i <= k; i++)
    {
        cin >> t[i];
        v.push_back(t[i]);
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    m = v.size();
    //for (int i : v) cout << i << " ";
    //cout << '\n';
    for (int i = 1; i <= n; i++)
    {
        //cout << "before " << a[i] << " " << b[i] << '\n';
        a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
        b[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin() + 1;
        //cout << "after " << a[i] << " " << b[i] << '\n';
    }
    for (int i = 1; i <= k; i++)
    {
        t[i] = lower_bound(v.begin(), v.end(), t[i]) - v.begin() + 1;
        st[0][t[i]] = i;
    }
    for (int j = 1; j < LG; j++)
        for (int i = 1; i <= m - (1 << (j - 1)); i++)
            st[j][i] = max(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
    for (int i = 1; i <= n; i++)
        events[rmq(min(a[i], b[i]), max(a[i], b[i]) - 1)].push_back(i);
    for (int i = k; i >= 0; i--)
    {
        for (int j : events[i])
        {
            if (i != 0)
            {
                if (a[j] < b[j]) swap(a[j], b[j]);
            }
            ll debug;
            res += (debug = (((get(m) - get(max(a[j], b[j]) - 1)) & 1) ? v[b[j] - 1] : v[a[j] - 1]));
            //cout << i << " " << j << " " << v[a[j] - 1] << " " << v[b[j] - 1] << " " << debug << '\n';
        }
        if (i != 0) upd(t[i]);
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 53840 KB Output is correct
2 Correct 7 ms 53840 KB Output is correct
3 Correct 8 ms 55888 KB Output is correct
4 Correct 8 ms 56144 KB Output is correct
5 Correct 8 ms 55888 KB Output is correct
6 Correct 9 ms 56144 KB Output is correct
7 Correct 9 ms 56136 KB Output is correct
8 Correct 8 ms 56144 KB Output is correct
9 Correct 7 ms 55888 KB Output is correct
10 Correct 7 ms 53840 KB Output is correct
11 Correct 8 ms 55888 KB Output is correct
12 Correct 8 ms 55888 KB Output is correct
13 Correct 8 ms 57936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 53840 KB Output is correct
2 Correct 7 ms 53840 KB Output is correct
3 Correct 8 ms 55888 KB Output is correct
4 Correct 8 ms 56144 KB Output is correct
5 Correct 8 ms 55888 KB Output is correct
6 Correct 9 ms 56144 KB Output is correct
7 Correct 9 ms 56136 KB Output is correct
8 Correct 8 ms 56144 KB Output is correct
9 Correct 7 ms 55888 KB Output is correct
10 Correct 7 ms 53840 KB Output is correct
11 Correct 8 ms 55888 KB Output is correct
12 Correct 8 ms 55888 KB Output is correct
13 Correct 8 ms 57936 KB Output is correct
14 Correct 15 ms 66944 KB Output is correct
15 Correct 27 ms 73680 KB Output is correct
16 Correct 34 ms 80124 KB Output is correct
17 Correct 43 ms 82864 KB Output is correct
18 Correct 47 ms 82884 KB Output is correct
19 Correct 42 ms 82884 KB Output is correct
20 Correct 42 ms 82928 KB Output is correct
21 Correct 41 ms 83148 KB Output is correct
22 Correct 31 ms 78540 KB Output is correct
23 Correct 34 ms 74292 KB Output is correct
24 Correct 33 ms 71924 KB Output is correct
25 Correct 35 ms 81092 KB Output is correct
26 Correct 36 ms 79812 KB Output is correct
27 Correct 44 ms 79816 KB Output is correct
28 Correct 39 ms 79820 KB Output is correct
29 Correct 47 ms 83940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 53840 KB Output is correct
2 Correct 7 ms 53840 KB Output is correct
3 Correct 8 ms 55888 KB Output is correct
4 Correct 8 ms 56144 KB Output is correct
5 Correct 8 ms 55888 KB Output is correct
6 Correct 9 ms 56144 KB Output is correct
7 Correct 9 ms 56136 KB Output is correct
8 Correct 8 ms 56144 KB Output is correct
9 Correct 7 ms 55888 KB Output is correct
10 Correct 7 ms 53840 KB Output is correct
11 Correct 8 ms 55888 KB Output is correct
12 Correct 8 ms 55888 KB Output is correct
13 Correct 8 ms 57936 KB Output is correct
14 Correct 15 ms 66944 KB Output is correct
15 Correct 27 ms 73680 KB Output is correct
16 Correct 34 ms 80124 KB Output is correct
17 Correct 43 ms 82864 KB Output is correct
18 Correct 47 ms 82884 KB Output is correct
19 Correct 42 ms 82884 KB Output is correct
20 Correct 42 ms 82928 KB Output is correct
21 Correct 41 ms 83148 KB Output is correct
22 Correct 31 ms 78540 KB Output is correct
23 Correct 34 ms 74292 KB Output is correct
24 Correct 33 ms 71924 KB Output is correct
25 Correct 35 ms 81092 KB Output is correct
26 Correct 36 ms 79812 KB Output is correct
27 Correct 44 ms 79816 KB Output is correct
28 Correct 39 ms 79820 KB Output is correct
29 Correct 47 ms 83940 KB Output is correct
30 Correct 81 ms 104896 KB Output is correct
31 Correct 113 ms 122404 KB Output is correct
32 Correct 148 ms 140360 KB Output is correct
33 Correct 230 ms 178096 KB Output is correct
34 Correct 70 ms 104128 KB Output is correct
35 Correct 231 ms 178016 KB Output is correct
36 Correct 231 ms 177708 KB Output is correct
37 Correct 228 ms 177584 KB Output is correct
38 Correct 223 ms 179376 KB Output is correct
39 Correct 232 ms 177584 KB Output is correct
40 Correct 233 ms 180400 KB Output is correct
41 Correct 221 ms 177592 KB Output is correct
42 Correct 226 ms 177580 KB Output is correct
43 Correct 159 ms 179380 KB Output is correct
44 Correct 157 ms 179120 KB Output is correct
45 Correct 155 ms 179764 KB Output is correct
46 Correct 145 ms 128392 KB Output is correct
47 Correct 145 ms 110772 KB Output is correct
48 Correct 170 ms 148308 KB Output is correct
49 Correct 168 ms 147376 KB Output is correct