답안 #466162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466162 2021-08-18T08:51:06 Z Tenis0206 운세 보기 2 (JOI14_fortune_telling2) C++11
0 / 100
9 ms 10084 KB
#include <bits/stdc++.h>

using namespace std;
int n,k,a[200005],b[200005],t[200005];
vector<int> v;
int rez[200005],cnt[200005];
int auxa[200005],auxb[200005];
vector<pair<int,int>> Q[200005];
class arbore_de_intervale
{
    int ai[2500005];
public:
    void update(int poz, int val, int nod, int a, int b)
    {
        if(a==b)
        {
            ai[nod] = max(ai[nod],val);
            return;
        }
        int mij = (a+b)>>1;
        if(poz<=mij)
        {
            update(poz,val,nod*2,a,mij);
        }
        else
        {
            update(poz,val,nod*2+1,mij+1,b);
        }
        ai[nod] = max(ai[nod*2],ai[nod*2+1]);
    }
    int query(int qa, int qb, int nod, int a, int b)
    {
        if(qa<=a && qb>=b)
        {
            return ai[nod];
        }
        int mij = (a+b)>>1;
        int rez1 = 0, rez2 = 0;
        if(qa<=mij)
        {
            rez1 = query(qa,qb,nod*2,a,mij);
        }
        if(qb>mij)
        {
            rez2 = query(qa,qb,nod*2+1,mij+1,b);
        }
        return max(rez1,rez2);
    }
}ai;
class arbore_indexat_binar
{
    int aib[600005];
private:
    int ub(int x)
    {
        return (x&(-x));
    }
public:
    void update(int poz, int val)
    {
        for(int i=poz;i<=v.back();i+=ub(i))
        {
            aib[poz]+=val;
        }
    }
    int query(int qa, int qb)
    {
        int rez = 0;
        for(int i=qb;i>=1;i-=ub(i))
        {
            rez+=aib[i];
        }
        for(int i=qa-1;i>=1;i-=ub(i))
        {
            rez-=aib[i];
        }
        return rez;
    }
}aib;
int get_poz(int val)
{
    int st = 1;
    int dr = v.size();
    int poz = 0;
    while(st<=dr)
    {
        int mij = (st+dr)>>1;
        if(v[mij-1]>=val)
        {
            poz = mij;
            dr = mij-1;
        }
        else
        {
            st = mij+1;
        }
    }
    return poz;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i]>>b[i];
        auxa[i] = a[i];
        auxb[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());
    for(int i=1; i<=n; i++)
    {
      // a[i] = get_poz(a[i]);
      //  b[i] = get_poz(b[i]);
    }
    for(int i=1; i<=k; i++)
    {
     //   t[i] = get_poz(t[i]);
    }
    for(int i=1; i<=k; i++)
    {
        ai.update(t[i],i,1,1,v.back());
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==b[i])
        {
            continue;
        }
        int poz = ai.query(min(a[i],b[i]),max(a[i],b[i])-1,1,1,v.back());
        if(poz)
        {
            rez[i] = max(a[i],b[i]);
        }
        else
        {
            rez[i] = a[i];
        }
        Q[poz+1].push_back({max(a[i],b[i]),i});
    }
    for(int i=k;i>=1;i--)
    {
        aib.update(t[i],+1);
        for(auto it : Q[i])
        {
            cnt[it.second] = aib.query(it.first,v.back());
        }
    }
    long long sum = 0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==b[i])
        {
            sum+=auxa[i];
            continue;
        }
        if(cnt[i]%2==1)
        {
            if(rez[i]==a[i])
            {
                rez[i] = b[i];
            }
            else
            {
                rez[i] = a[i];
            }
        }
        if(rez[i]==a[i])
        {
            sum+=auxa[i];
        }
        else
        {
            sum+=auxb[i];
        }
    }
    cout<<sum<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 10084 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 10084 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 10084 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -