답안 #646923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646923 2022-10-01T04:55:42 Z tamthegod 운세 보기 2 (JOI14_fortune_telling2) C++17
0 / 100
44 ms 94412 KB
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, k;
pair<int, int> a[maxN];
int b[maxN];
vector<int> vc;
int st[4 * maxN];
int last[maxN];
vector<int> ST[4 * maxN];
int get_id(int val)
{
    return upper_bound(vc.begin(), vc.end(), val) - vc.begin();
}
void build(int id, int l, int r)
{
    if(l == r)
    {
        st[id] = last[l];
        return;
    }
    int mid = (l + r) / 2;
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
    st[id] = max(st[id * 2], st[id * 2 + 1]);
}
int get(int id, int l, int r, int u, int v)
{
    if(l > v || r < u) return 0;
    if(l >= u && r <= v) return st[id];
    int mid = (l + r) / 2;
    return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
vector<int> combine(vector<int> a, vector<int> b)
{
    vector<int> res;
    for(int v : a) res.pb(v);
    for(int v : b) res.pb(v);
    sort(res.begin(), res.end());
    return res;
}
void Build(int id, int l, int r)
{
    if(l == r)
    {
        ST[id].pb(b[l]);
        return;
    }
    int mid = (l + r) / 2;
    Build(id * 2, l, mid);
    Build(id * 2 + 1, mid + 1, r);
    ST[id] = combine(ST[id * 2], ST[id * 2 + 1]);
}
int Get(int id, int l, int r, int u, int v, int val)
{
    if(l > v || r < u) return 0;
    if(l >= u && r <= v) return ST[id].size() - (lower_bound(ST[id].begin(), ST[id].end(), val) - ST[id].begin());
    int mid = (l + r) / 2;
    return Get(id * 2, l, mid, u, v, val) + Get(id * 2 + 1, mid + 1, r, u, v, val);
}
void ReadInput()
{
    cin >> n >> k;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i].fi >> a[i].se;
        vc.pb(a[i].fi);
        vc.pb(a[i].se - 1);
    }
    for(int i=1; i<=k; i++)
    {
        cin >> b[i];
        vc.pb(b[i]);
    }
    sort(vc.begin(), vc.end());
    vc.erase(unique(vc.begin(), vc.end()), vc.end());
    for(int i=1; i<=k; i++)
    {
        int pos = get_id(b[i]);
        last[pos] = i;
    }
    build(1, 1, 3 * n);
    Build(1, 1, k);
}
void Solve()
{
    int res = 0;
    for(int i=1; i<=n; i++)
    {
        int l = get_id(a[i].fi), r = get_id(a[i].se - 1);
        int id = get(1, 1, 3 * n, l, r) + 1;
        int cnt = Get(1, 1, k, id, k, a[i].se);
        if(cnt & 1)
        {
            if(id == 1) res += a[i].se;
            else res += min(a[i].fi, a[i].se);
        }
        else
        {
            if(id == 1) res += a[i].fi;
            else res += max(a[i].fi, a[i].se);
        }
    }
    cout << res;
}
int32_t main()
{
   // freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 94412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 94412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 94412 KB Output isn't correct
2 Halted 0 ms 0 KB -