답안 #729543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729543 2023-04-24T08:53:31 Z abcvuitunggio 운세 보기 2 (JOI14_fortune_telling2) C++17
100 / 100
480 ms 30136 KB
#include <bits/stdc++.h>
#define int long long
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;
}
int32_t 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(long long int)':
fortune_telling2.cpp:29:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (;i<=ve.size();i+=i&(-i))
      |           ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5040 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 3 ms 5164 KB Output is correct
7 Correct 4 ms 5168 KB Output is correct
8 Correct 4 ms 5164 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 4 ms 5164 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 5 ms 5076 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5040 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 3 ms 5164 KB Output is correct
7 Correct 4 ms 5168 KB Output is correct
8 Correct 4 ms 5164 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 4 ms 5164 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 5 ms 5076 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 16 ms 6440 KB Output is correct
15 Correct 30 ms 7560 KB Output is correct
16 Correct 52 ms 8536 KB Output is correct
17 Correct 58 ms 10184 KB Output is correct
18 Correct 69 ms 10172 KB Output is correct
19 Correct 74 ms 10152 KB Output is correct
20 Correct 57 ms 10204 KB Output is correct
21 Correct 55 ms 10440 KB Output is correct
22 Correct 45 ms 8912 KB Output is correct
23 Correct 45 ms 8964 KB Output is correct
24 Correct 47 ms 9000 KB Output is correct
25 Correct 52 ms 9584 KB Output is correct
26 Correct 52 ms 9664 KB Output is correct
27 Correct 53 ms 10160 KB Output is correct
28 Correct 56 ms 10192 KB Output is correct
29 Correct 59 ms 10312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5040 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 3 ms 5164 KB Output is correct
7 Correct 4 ms 5168 KB Output is correct
8 Correct 4 ms 5164 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 4 ms 5164 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 5 ms 5076 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 16 ms 6440 KB Output is correct
15 Correct 30 ms 7560 KB Output is correct
16 Correct 52 ms 8536 KB Output is correct
17 Correct 58 ms 10184 KB Output is correct
18 Correct 69 ms 10172 KB Output is correct
19 Correct 74 ms 10152 KB Output is correct
20 Correct 57 ms 10204 KB Output is correct
21 Correct 55 ms 10440 KB Output is correct
22 Correct 45 ms 8912 KB Output is correct
23 Correct 45 ms 8964 KB Output is correct
24 Correct 47 ms 9000 KB Output is correct
25 Correct 52 ms 9584 KB Output is correct
26 Correct 52 ms 9664 KB Output is correct
27 Correct 53 ms 10160 KB Output is correct
28 Correct 56 ms 10192 KB Output is correct
29 Correct 59 ms 10312 KB Output is correct
30 Correct 160 ms 16492 KB Output is correct
31 Correct 188 ms 19280 KB Output is correct
32 Correct 263 ms 22712 KB Output is correct
33 Correct 361 ms 29964 KB Output is correct
34 Correct 142 ms 15800 KB Output is correct
35 Correct 480 ms 29876 KB Output is correct
36 Correct 469 ms 29644 KB Output is correct
37 Correct 422 ms 29548 KB Output is correct
38 Correct 374 ms 29796 KB Output is correct
39 Correct 415 ms 29572 KB Output is correct
40 Correct 401 ms 29008 KB Output is correct
41 Correct 391 ms 29524 KB Output is correct
42 Correct 386 ms 29424 KB Output is correct
43 Correct 262 ms 27316 KB Output is correct
44 Correct 280 ms 27500 KB Output is correct
45 Correct 276 ms 27792 KB Output is correct
46 Correct 257 ms 26348 KB Output is correct
47 Correct 265 ms 23224 KB Output is correct
48 Correct 309 ms 29704 KB Output is correct
49 Correct 306 ms 30136 KB Output is correct