답안 #757740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757740 2023-06-13T17:20:20 Z karrigan 운세 보기 2 (JOI14_fortune_telling2) C++14
100 / 100
1089 ms 68528 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
using pii=pair<int,int>;
using pli=pair<long long,int>;
using pil=pair<int,long long>;
using pll=pair<long long,long long>;
const int maxn=2e5+9;
int st[maxn*4*3];
void update(int id,int l,int r,int u,int val){
if (l>u||r<u)return;
if (l==r){
    st[id]=val;
    return;
}
int mid=(l+r)/2;
update(id*2,l,mid,u,val);
update(id*2+1,mid+1,r,u,val);
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||u>v)return 0;
if (u<=l&&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));
}
int m;
int bit[maxn*3];
void add(int pos,int val){
for(;pos<=m;pos+=(pos-(pos&(pos-1))))bit[pos]+=val;
}
int get(int pos){
if (pos==0)return 0;
int sum=0;
for(;pos>=1;pos-=(pos-(pos&(pos-1))))sum+=bit[pos];
return sum;
}
int a[maxn*3],b[maxn*3];
int c[maxn*3];
bool flip[maxn*3];
int d[maxn*3];
int ren[maxn*3];
vector<int>query[maxn*3];
signed main(){
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("usaco.INP","r",stdin);
    //freopen("usaco.OUT","w",stdout);
    int n,q;
    cin>>n>>q;
    vector<int>num;
    num.pb(0);
    for1(i,1,n){
    cin>>a[i]>>b[i];
    num.pb(a[i]);
    num.pb(b[i]);
    }
    for1(i,1,q){
    cin>>c[i];
    num.pb(c[i]);
    }
    sort(all(num));
    map<int,int>nen;
    m=0;
    for1(i,1,sz(num)-1){
    if (num[i]>num[i-1]){
        nen[num[i]]=nen[num[i-1]]+1;
        m=nen[num[i]];
        ren[m]=num[i];
    }
    }
    for1(i,1,n){
    a[i]=nen[a[i]];
    b[i]=nen[b[i]];
    }
    for1(i,1,q)c[i]=nen[c[i]];
    for1(i,1,q){
    update(1,1,m,c[i],i);
    }
    for1(i,1,n){
    int x=min(a[i],b[i]),y=max(a[i],b[i]);
    int vcl=get(1,1,m,x,y-1);
    if (vcl==0){
        continue;
    }
    query[vcl].pb(i);
    if (a[i]<b[i]){
        flip[i]=1;
    }
    }
    for1(i,1,q){
    add(c[i],1);
    for (auto v:query[i]){
        d[v]=-get(m)+get(max(a[v],b[v])-1);
    }
    }
    long long sum=0;
    for1(i,1,n){
    d[i]+=get(m)-get(max(a[i],b[i])-1);
    d[i]%=2;
    flip[i]^=d[i];
    if (!flip[i]){
       sum+=ren[a[i]];
    }
    else sum+=ren[b[i]];
    }
    cout<<sum;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14464 KB Output is correct
2 Correct 9 ms 14548 KB Output is correct
3 Correct 10 ms 14676 KB Output is correct
4 Correct 9 ms 14660 KB Output is correct
5 Correct 10 ms 14732 KB Output is correct
6 Correct 10 ms 14676 KB Output is correct
7 Correct 9 ms 14676 KB Output is correct
8 Correct 9 ms 14688 KB Output is correct
9 Correct 9 ms 14684 KB Output is correct
10 Correct 9 ms 14548 KB Output is correct
11 Correct 9 ms 14548 KB Output is correct
12 Correct 9 ms 14560 KB Output is correct
13 Correct 9 ms 14676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14464 KB Output is correct
2 Correct 9 ms 14548 KB Output is correct
3 Correct 10 ms 14676 KB Output is correct
4 Correct 9 ms 14660 KB Output is correct
5 Correct 10 ms 14732 KB Output is correct
6 Correct 10 ms 14676 KB Output is correct
7 Correct 9 ms 14676 KB Output is correct
8 Correct 9 ms 14688 KB Output is correct
9 Correct 9 ms 14684 KB Output is correct
10 Correct 9 ms 14548 KB Output is correct
11 Correct 9 ms 14548 KB Output is correct
12 Correct 9 ms 14560 KB Output is correct
13 Correct 9 ms 14676 KB Output is correct
14 Correct 36 ms 16960 KB Output is correct
15 Correct 65 ms 19468 KB Output is correct
16 Correct 97 ms 22264 KB Output is correct
17 Correct 136 ms 24524 KB Output is correct
18 Correct 134 ms 24612 KB Output is correct
19 Correct 136 ms 24580 KB Output is correct
20 Correct 148 ms 24596 KB Output is correct
21 Correct 130 ms 24624 KB Output is correct
22 Correct 85 ms 21844 KB Output is correct
23 Correct 82 ms 20428 KB Output is correct
24 Correct 73 ms 19504 KB Output is correct
25 Correct 94 ms 22740 KB Output is correct
26 Correct 90 ms 21660 KB Output is correct
27 Correct 108 ms 22544 KB Output is correct
28 Correct 105 ms 22404 KB Output is correct
29 Correct 115 ms 23488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14464 KB Output is correct
2 Correct 9 ms 14548 KB Output is correct
3 Correct 10 ms 14676 KB Output is correct
4 Correct 9 ms 14660 KB Output is correct
5 Correct 10 ms 14732 KB Output is correct
6 Correct 10 ms 14676 KB Output is correct
7 Correct 9 ms 14676 KB Output is correct
8 Correct 9 ms 14688 KB Output is correct
9 Correct 9 ms 14684 KB Output is correct
10 Correct 9 ms 14548 KB Output is correct
11 Correct 9 ms 14548 KB Output is correct
12 Correct 9 ms 14560 KB Output is correct
13 Correct 9 ms 14676 KB Output is correct
14 Correct 36 ms 16960 KB Output is correct
15 Correct 65 ms 19468 KB Output is correct
16 Correct 97 ms 22264 KB Output is correct
17 Correct 136 ms 24524 KB Output is correct
18 Correct 134 ms 24612 KB Output is correct
19 Correct 136 ms 24580 KB Output is correct
20 Correct 148 ms 24596 KB Output is correct
21 Correct 130 ms 24624 KB Output is correct
22 Correct 85 ms 21844 KB Output is correct
23 Correct 82 ms 20428 KB Output is correct
24 Correct 73 ms 19504 KB Output is correct
25 Correct 94 ms 22740 KB Output is correct
26 Correct 90 ms 21660 KB Output is correct
27 Correct 108 ms 22544 KB Output is correct
28 Correct 105 ms 22404 KB Output is correct
29 Correct 115 ms 23488 KB Output is correct
30 Correct 301 ms 32456 KB Output is correct
31 Correct 403 ms 40764 KB Output is correct
32 Correct 590 ms 48448 KB Output is correct
33 Correct 1049 ms 68136 KB Output is correct
34 Correct 235 ms 30964 KB Output is correct
35 Correct 1069 ms 68152 KB Output is correct
36 Correct 1022 ms 68256 KB Output is correct
37 Correct 1089 ms 68108 KB Output is correct
38 Correct 1032 ms 68132 KB Output is correct
39 Correct 1006 ms 68124 KB Output is correct
40 Correct 880 ms 68528 KB Output is correct
41 Correct 983 ms 68196 KB Output is correct
42 Correct 1010 ms 68116 KB Output is correct
43 Correct 583 ms 63172 KB Output is correct
44 Correct 636 ms 63764 KB Output is correct
45 Correct 609 ms 65128 KB Output is correct
46 Correct 452 ms 45716 KB Output is correct
47 Correct 352 ms 37844 KB Output is correct
48 Correct 631 ms 53020 KB Output is correct
49 Correct 609 ms 53312 KB Output is correct