Submission #636059

# Submission time Handle Problem Language Result Execution time Memory
636059 2022-08-27T21:09:48 Z MasterTaster Fortune Telling 2 (JOI14_fortune_telling2) C++14
4 / 100
3000 ms 5416 KB
#include <iostream>
#include <vector>
#include <set>
#include <iterator>
#include <algorithm>

#define ll long long
#define MAXN 200010
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back

using namespace std;

int n, k, a[MAXN], b[MAXN], t[MAXN], last[MAXN];
int cnt[MAXN];
int bit[4*MAXN+5], seg[12*MAXN];
bool sw[MAXN];
pii c[MAXN];
vector<pii> tmp;

void build(int node, int l, int r)
{
    if (l==r) { seg[node]=c[l].yy; return; }

    int mid=l+(r-l)/2;
    build(2*node, l, mid);
    build(2*node+1, mid+1, r);
    seg[node]=max(seg[2*node], seg[2*node+1]);
}
int maxQuery(int node, int l, int r, int levo, int desno)
{
    if (levo>r ||  desno<l) return -1;
    if (levo<=l && desno>=r) return seg[node];

    int mid=l+(r-l)/2;
    return max(maxQuery(2*node, l, mid, levo, desno),
               maxQuery(2*node+1, mid+1, r, levo, desno));
}

void upd(int x, int val)
{
    while (x<MAXN)
    {
        bit[x]+=val;
        x+=x&(-x);
    }
    return;
}
int sum(int x)
{
    if (x<=0) return 0;
    int ret=0;
    while (x)
    {
        ret+=bit[x];
        x-=x&(-x);
    }
    return ret;
}

int main() {
    cin>>n>>k;

    for (int i=1; i<=n; i++) { cin>>a[i]>>b[i]; if (a[i]>b[i]) { sw[i]=true; swap(a[i], b[i]); } }

    for (int i=1; i<=k; i++) cin>>t[i];

    for (int i=1; i<=k; i++) { pii par={t[i], i}; c[i]=par; }
    sort(c+1, c+k+1);

    ///for (int i=1; i<=k; i++) { cout<<c[i].xx<<" "<<c[i].yy<<endl; }

    build(1, 1, k);

    for (int i=1; i<=n; i++) {
        pii minpar = {a[i], 0}, maxpar = {b[i], 0};
        int l = distance(c + 1, lower_bound(c + 1, c + k + 1, minpar));
        int r = distance(c + 1, lower_bound(c + 1, c + k + 1, maxpar));
        r--;

        l++; r++;
        ///cout<<i<<": "<<l<<" lr "<<r<<endl;
        if (l > r) last[i] = 0;
        else last[i] = maxQuery(1, 1, k, l, r);
    }

    for (int i=1; i<=n; i++) tmp.pb({last[i], i});
    sort(tmp.begin(), tmp.end()/*, greater<pii>()*/);

    //for (int i=0; i<tmp.size(); i++) cout<<tmp[i].xx<<" tmp "<<tmp[i].yy<<endl;

    int j=tmp.size()-1;
    multiset<int> s;
    for (int i=k; i>=0; i--)
    {
        ///cout<<"i "<<i<<endl;
        if (i) s.insert(t[i]);
        while (j>=0 && tmp[j].xx==i) { /*cout<<i<<" ij "<<j<<endl;*/ cnt[tmp[j].yy]=distance(s.begin(), s.lower_bound(a[tmp[j].yy])); j--; }
        ///cout<<j<<" j"<<endl;
    }

    ll ans=0;
    for (int i=1; i<=n; i++)
    {
        int kolko=k-last[i]-cnt[i];
        if (last[i]==0 && sw[i]) swap(a[i], b[i]);
        ///cout<<i<<" "<<last[i]<<" "<<cnt[i]<<endl;
        if (last[i]==0) { if (kolko%2) ans+=(ll)b[i]; else ans+=(ll)a[i]; }
        else { if (kolko%2) ans+=(ll)a[i]; else ans+=(ll)b[i]; }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 3 ms 448 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 5 ms 340 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 5 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 3 ms 448 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 5 ms 340 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 5 ms 440 KB Output is correct
14 Correct 19 ms 1468 KB Output is correct
15 Correct 39 ms 2760 KB Output is correct
16 Correct 59 ms 3888 KB Output is correct
17 Correct 79 ms 5260 KB Output is correct
18 Correct 80 ms 5220 KB Output is correct
19 Correct 86 ms 5416 KB Output is correct
20 Correct 107 ms 5244 KB Output is correct
21 Correct 75 ms 5316 KB Output is correct
22 Correct 59 ms 4788 KB Output is correct
23 Correct 59 ms 4880 KB Output is correct
24 Correct 59 ms 4796 KB Output is correct
25 Correct 62 ms 4788 KB Output is correct
26 Execution timed out 3080 ms 4108 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 3 ms 448 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 5 ms 340 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 5 ms 440 KB Output is correct
14 Correct 19 ms 1468 KB Output is correct
15 Correct 39 ms 2760 KB Output is correct
16 Correct 59 ms 3888 KB Output is correct
17 Correct 79 ms 5260 KB Output is correct
18 Correct 80 ms 5220 KB Output is correct
19 Correct 86 ms 5416 KB Output is correct
20 Correct 107 ms 5244 KB Output is correct
21 Correct 75 ms 5316 KB Output is correct
22 Correct 59 ms 4788 KB Output is correct
23 Correct 59 ms 4880 KB Output is correct
24 Correct 59 ms 4796 KB Output is correct
25 Correct 62 ms 4788 KB Output is correct
26 Execution timed out 3080 ms 4108 KB Time limit exceeded
27 Halted 0 ms 0 KB -