Submission #584825

# Submission time Handle Problem Language Result Execution time Memory
584825 2022-06-28T04:26:07 Z Hanksburger Fortune Telling 2 (JOI14_fortune_telling2) C++17
100 / 100
1197 ms 85288 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[200005], b[200005], t[200005];
vector<int> s[800005];
map<int, int> mp;
void f(int i, int l, int r)
{
    sort(s[i].begin(), s[i].end());
    if (l<r)
    {
        int mid=(l+r)/2;
        f(i*2, l, mid);
        f(i*2+1, mid+1, r);
    }
}
void upd(int i, int l, int r, int q, int x)
{
    s[i].push_back(x);
    if (l<r)
    {
        int mid=(l+r)/2;
        if (l<=q && q<=mid)
            upd(i*2, l, mid, q, x);
        else
            upd(i*2+1, mid+1, r, q, x);
    }
}
int queMax(int i, int l, int r, int ql, int qr)
{
    if (ql<=l && r<qr)
    {
        if (s[i].empty())
            return 0;
        return s[i][s[i].size()-1];
    }
    int mid=(l+r)/2, res=0;
    if (ql<=mid && l<qr)
        res=max(res, queMax(i*2, l, mid, ql, qr));
    if (ql<=r && mid+1<qr)
        res=max(res, queMax(i*2+1, mid+1, r, ql, qr));
    return res;
}
int queCnt(int i, int l, int r, int q, int x)
{
    if (q<=l)
    {
        int ind=upper_bound(s[i].begin(), s[i].end(), x)-s[i].begin();
        return s[i].size()-ind;
    }
    int mid=(l+r)/2, res=0;
    if (q<=mid)
        res+=queCnt(i*2, l, mid, q, x);
    if (q<=r)
        res+=queCnt(i*2+1, mid+1, r, q, x);
    return res;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, q, sz=0, ans=0;
    cin >> n >> q;
    for (int i=1; i<=n; i++)
        cin >> a[i] >> b[i];
    for (int i=1; i<=q; i++)
    {
        cin >> t[i];
        mp[t[i]]=1;
    }
    for (auto itr=mp.begin(); itr!=mp.end(); itr++)
    {
        sz++;
        itr->second=sz;
    }
    for (int i=1; i<=q; i++)
        upd(1, 1, sz, mp[t[i]], i);
    f(1, 1, sz);
    for (int i=1; i<=n; i++)
    {
        auto itr1=mp.lower_bound(a[i]), itr2=mp.lower_bound(b[i]);
        int x=(itr1==mp.end()?1e9:itr1->second), y=(itr2==mp.end()?1e9:itr2->second);
        if (x>y)
            swap(x, y);
        int res1=queMax(1, 1, sz, x, y);
        int res2=queCnt(1, 1, sz, y, res1);
        if (!res1)
        {
            if (res2&1)
                ans+=b[i];
            else
                ans+=a[i];
        }
        else
        {
            if (res2&1)
                ans+=min(a[i], b[i]);
            else
                ans+=max(a[i], b[i]);
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19284 KB Output is correct
2 Correct 11 ms 19264 KB Output is correct
3 Correct 11 ms 19260 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
5 Correct 11 ms 19284 KB Output is correct
6 Correct 11 ms 19256 KB Output is correct
7 Correct 11 ms 19260 KB Output is correct
8 Correct 11 ms 19284 KB Output is correct
9 Correct 10 ms 19252 KB Output is correct
10 Correct 11 ms 19284 KB Output is correct
11 Correct 11 ms 19284 KB Output is correct
12 Correct 11 ms 19284 KB Output is correct
13 Correct 11 ms 19260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19284 KB Output is correct
2 Correct 11 ms 19264 KB Output is correct
3 Correct 11 ms 19260 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
5 Correct 11 ms 19284 KB Output is correct
6 Correct 11 ms 19256 KB Output is correct
7 Correct 11 ms 19260 KB Output is correct
8 Correct 11 ms 19284 KB Output is correct
9 Correct 10 ms 19252 KB Output is correct
10 Correct 11 ms 19284 KB Output is correct
11 Correct 11 ms 19284 KB Output is correct
12 Correct 11 ms 19284 KB Output is correct
13 Correct 11 ms 19260 KB Output is correct
14 Correct 31 ms 22356 KB Output is correct
15 Correct 58 ms 25676 KB Output is correct
16 Correct 94 ms 27724 KB Output is correct
17 Correct 143 ms 32472 KB Output is correct
18 Correct 131 ms 32404 KB Output is correct
19 Correct 138 ms 32576 KB Output is correct
20 Correct 147 ms 32384 KB Output is correct
21 Correct 122 ms 32396 KB Output is correct
22 Correct 83 ms 30788 KB Output is correct
23 Correct 84 ms 30400 KB Output is correct
24 Correct 91 ms 30184 KB Output is correct
25 Correct 83 ms 30896 KB Output is correct
26 Correct 132 ms 32200 KB Output is correct
27 Correct 118 ms 32496 KB Output is correct
28 Correct 97 ms 32448 KB Output is correct
29 Correct 118 ms 32404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19284 KB Output is correct
2 Correct 11 ms 19264 KB Output is correct
3 Correct 11 ms 19260 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
5 Correct 11 ms 19284 KB Output is correct
6 Correct 11 ms 19256 KB Output is correct
7 Correct 11 ms 19260 KB Output is correct
8 Correct 11 ms 19284 KB Output is correct
9 Correct 10 ms 19252 KB Output is correct
10 Correct 11 ms 19284 KB Output is correct
11 Correct 11 ms 19284 KB Output is correct
12 Correct 11 ms 19284 KB Output is correct
13 Correct 11 ms 19260 KB Output is correct
14 Correct 31 ms 22356 KB Output is correct
15 Correct 58 ms 25676 KB Output is correct
16 Correct 94 ms 27724 KB Output is correct
17 Correct 143 ms 32472 KB Output is correct
18 Correct 131 ms 32404 KB Output is correct
19 Correct 138 ms 32576 KB Output is correct
20 Correct 147 ms 32384 KB Output is correct
21 Correct 122 ms 32396 KB Output is correct
22 Correct 83 ms 30788 KB Output is correct
23 Correct 84 ms 30400 KB Output is correct
24 Correct 91 ms 30184 KB Output is correct
25 Correct 83 ms 30896 KB Output is correct
26 Correct 132 ms 32200 KB Output is correct
27 Correct 118 ms 32496 KB Output is correct
28 Correct 97 ms 32448 KB Output is correct
29 Correct 118 ms 32404 KB Output is correct
30 Correct 656 ms 78688 KB Output is correct
31 Correct 675 ms 79944 KB Output is correct
32 Correct 890 ms 81964 KB Output is correct
33 Correct 1189 ms 85168 KB Output is correct
34 Correct 572 ms 78088 KB Output is correct
35 Correct 1175 ms 85172 KB Output is correct
36 Correct 1181 ms 85288 KB Output is correct
37 Correct 1128 ms 85120 KB Output is correct
38 Correct 1164 ms 85232 KB Output is correct
39 Correct 1187 ms 85244 KB Output is correct
40 Correct 967 ms 85132 KB Output is correct
41 Correct 1197 ms 85044 KB Output is correct
42 Correct 1146 ms 85164 KB Output is correct
43 Correct 758 ms 84592 KB Output is correct
44 Correct 715 ms 84480 KB Output is correct
45 Correct 702 ms 84308 KB Output is correct
46 Correct 637 ms 76636 KB Output is correct
47 Correct 574 ms 74236 KB Output is correct
48 Correct 874 ms 85136 KB Output is correct
49 Correct 857 ms 85108 KB Output is correct