답안 #729542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729542 2023-04-24T08:53:06 Z abcvuitunggio 운세 보기 2 (JOI14_fortune_telling2) C++17
0 / 100
4 ms 5076 KB
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
int n,k,a[200001],b[200001],t[200001],st[800001],ft[400001],pos[200001],res;
vector <int> ve,v[200001];
void update(int node, int l, int r, int x, int val){
    if (ve[l]>x||ve[r]<x||l>r)
        return;
    if (l==r){
        st[node]=val;
        return;
    }
    int mid=(l+r)>>1;
    update(node<<1,l,mid,x,val);
    update(node<<1|1,mid+1,r,x,val);
    st[node]=max(st[node<<1],st[node<<1|1]);
}
int get(int node, int l, int r, int u, int v){
    if (ve[l]>v||ve[r]<u||l>r||u>v)
        return 0;
    if (ve[l]>=u&&ve[r]<=v)
        return st[node];
    int mid=(l+r)>>1;
    return max(get(node<<1,l,mid,u,v),get(node<<1|1,mid+1,r,u,v));
}
void update(int i){
    i=lower_bound(ve.begin(),ve.end(),i)-ve.begin()+1;
    for (;i<=ve.size();i+=i&(-i))
        ft[i]++;
}
int get(int i){
    i=lower_bound(ve.begin(),ve.end(),i)-ve.begin()+1;
    int res=0;
    for (;i;i-=i&(-i))
        res+=ft[i];
    return res;
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> k;
    for (int i=1;i<=n;i++)
        cin >> a[i] >> b[i];
    for (int i=1;i<=k;i++){
        cin >> t[i];
        ve.push_back(t[i]);
    }
    sort(ve.begin(),ve.end());
    ve.resize(unique(ve.begin(),ve.end())-ve.begin());
    for (int i=1;i<=k;i++)
        update(1,0,ve.size()-1,t[i],i);
    for (int i=1;i<=n;i++){
        pos[i]=get(1,0,ve.size()-1,min(a[i],b[i]),max(a[i],b[i])-1);
        v[pos[i]].push_back(i);
        if (pos[i]&&a[i]<b[i])
            swap(a[i],b[i]);
    }
    for (int i=1;i<=n;i++)
        ve.push_back(max(a[i],b[i])-1);
    ve.push_back(INF);
    sort(ve.begin(),ve.end());
    ve.resize(unique(ve.begin(),ve.end())-ve.begin());
    for (int i=k;i>=0;i--){
        for (int j:v[i]){
            int cnt=get(INF)-get(max(a[j],b[j])-1);
            res+=(cnt&1?b[j]:a[j]);
        }
        update(t[i]);
    }
    cout << res;
}

Compilation message

fortune_telling2.cpp: In function 'void update(int)':
fortune_telling2.cpp:28:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (;i<=ve.size();i+=i&(-i))
      |           ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -