답안 #413589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413589 2021-05-29T03:10:58 Z cpp219 운세 보기 2 (JOI14_fortune_telling2) C++14
0 / 100
1 ms 332 KB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e6 + 9;
const ll Log2 = 20;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

struct data{
    ll x,y,id,dummy;
};
data a[N];
ll n,k,st[4*N],q[N];

bool lf(data a,data b){
    return max(a.x,a.y) > max(b.x,b.y);
}

void upd(ll id,ll l,ll r,ll u,ll val){
    if (u < l||r < u) return;
    if (l == r){
        st[id] = val; return;
    }
    ll mid = (l + r)/2;
    upd(id*2,l,mid,u,val); upd(id*2 + 1,mid + 1,r,u,val);
    st[id] = max(st[id*2],st[id*2 + 1]);
}
/// last but >= val
ll Walk(ll id,ll l,ll r,ll val){
    if (l == r){
        if (st[id] >= val) return l;
        return 0;
    }
    ll mid = (l + r)/2;
    if (st[id*2 + 1] >= val) return Walk(id*2 + 1,mid + 1,r,val);
    return Walk(id*2,l,mid,val);
}

ll bit[N];

void updBIT(ll p,ll val){
    for (ll i = p;i <= k;i += i & -i) bit[i] += val;
}

ll Get(ll p){
    ll res = 0;
    for (ll i = p;i > 0;i -= i & -i) res += bit[i];
    return res;
}

vector<ll> v;
ll Find(ll x){
    return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}

void compress(){
    sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
    for (ll i = 1;i <= n;i++) a[i].x = Find(a[i].x),a[i].y = Find(a[i].y);
    for (ll i = 1;i <= k;i++) q[i] = Find(q[i]);
}

vector<ll> pos;
bool cmp(ll x,ll y){
    return q[x] > q[y];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "tst"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>k;
    for (ll i = 1;i <= n;i++){
        cin>>a[i].x>>a[i].y,a[i].id = i;
        if (a[i].x < a[i].y) a[i].dummy = 1,swap(a[i].x,a[i].y);
    }
    for (ll i = 1;i <= k;i++) cin>>q[i],upd(1,1,k,i,q[i]),pos.push_back(i);
    sort(a + 1,a + n + 1,lf); sort(pos.begin(),pos.end(),cmp);

    ll cur = 0,kq = 0;
    for (ll i = 1;i <= n;i++){
        while(cur < k&&q[pos[cur]] >= a[i].x){
            upd(1,1,k,pos[cur],-inf); updBIT(pos[cur],1);
            cur++;
        }

        ll nxt = Walk(1,1,k,a[i].y);
        ll ans = a[i].dummy + Get(k) - Get(nxt); ans %= 2;
        //cout<<ans<<" "<<nxt<<" ";
        if (ans) kq += a[i].y;//cout<<a[i].y<<"\n";
        else kq += a[i].x;//cout<<a[i].x<<"\n";

    }
    cout<<kq;
}

Compilation message

fortune_telling2.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
fortune_telling2.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -