답안 #1102238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102238 2024-10-17T18:17:55 Z imarn 나일강 (IOI24_nile) C++17
100 / 100
92 ms 14052 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
using namespace std;
const int mxn=1e5+5;
int mx[mxn]{0},sz[mxn]{0},pr[mxn]{0};
int vl[mxn][2]{0};
int get(int r){
    return pr[r]==r?r:pr[r]=get(pr[r]);
}
int cal(int u){
    if(sz[u]%2==0)return 0;
    return max(vl[u][u&1],mx[u]);
}
std::vector<long long> calculate_costs(std::vector<int> W, std::vector<int> A,std::vector<int> B, std::vector<int> E){
    vector<pair<int,pii>>v;int n=W.size(),m=E.size();
    for(int i=0;i<n;i++)v.pb({W[i],{A[i],B[i]}});sort(all(v));
    for(int i=0;i<n;i++)W[i]=v[i].f,A[i]=v[i].s.f,B[i]=v[i].s.s;
    vector<pii>q1,q2;for(int i=0;i<n;i++)pr[i]=i,sz[i]=1,vl[i][i&1]=B[i]-A[i],mx[i]=-2e9,vl[i][(i+1)&1]=-2e9;
    for(int i=0;i<n-1;i++)q1.pb({W[i+1]-W[i],i});
    for(int i=1;i<n-1;i++)q2.pb({W[i+1]-W[i-1],i});
    sort(all(q1));sort(all(q2));
    ll rs=0;for(int i=0;i<n;i++)rs+=A[i];
    vector<pii>qr;for(int i=0;i<m;i++)qr.pb({E[i],i});
    sort(all(qr));int id1=0,id2=0;
    vector<ll>res(m,0);
    for(auto [d,i]:qr){
        while(id1<q1.size()&&q1[id1].f<=d){
            int u=get(q1[id1].s);
            int v=get(q1[id1].s+1);
            rs+=cal(u);
            rs+=cal(v);
            pr[u]=v;
            sz[v]+=sz[u];
            vl[v][0]=max(vl[v][0],vl[u][0]);
            vl[v][1]=max(vl[v][1],vl[u][1]);
            mx[v]=max(mx[v],mx[u]);
            rs-=cal(v);id1++;
        }
        while(id2<q2.size()&&q2[id2].f<=d){
            int u=get(q2[id2].s);
            rs+=cal(u);
            mx[u]=max(mx[u],B[q2[id2].s]-A[q2[id2].s]);
            rs-=cal(u);id2++;
        }
        res[i]=rs;
    }
    return res;
}

Compilation message

nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:26:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   26 |     for(int i=0;i<n;i++)v.pb({W[i],{A[i],B[i]}});sort(all(v));
      |     ^~~
nile.cpp:26:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   26 |     for(int i=0;i<n;i++)v.pb({W[i],{A[i],B[i]}});sort(all(v));
      |                                                  ^~~~
nile.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         while(id1<q1.size()&&q1[id1].f<=d){
      |               ~~~^~~~~~~~~~
nile.cpp:49:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         while(id2<q2.size()&&q2[id2].f<=d){
      |               ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 1 ms 764 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 9664 KB Output is correct
2 Correct 33 ms 9684 KB Output is correct
3 Correct 38 ms 9664 KB Output is correct
4 Correct 49 ms 9672 KB Output is correct
5 Correct 37 ms 9560 KB Output is correct
6 Correct 37 ms 9664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 9160 KB Output is correct
2 Correct 35 ms 8972 KB Output is correct
3 Correct 44 ms 8392 KB Output is correct
4 Correct 45 ms 8384 KB Output is correct
5 Correct 44 ms 8896 KB Output is correct
6 Correct 60 ms 8468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 1 ms 764 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 608 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 1 ms 764 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 36 ms 9664 KB Output is correct
8 Correct 33 ms 9684 KB Output is correct
9 Correct 38 ms 9664 KB Output is correct
10 Correct 49 ms 9672 KB Output is correct
11 Correct 37 ms 9560 KB Output is correct
12 Correct 37 ms 9664 KB Output is correct
13 Correct 33 ms 9160 KB Output is correct
14 Correct 35 ms 8972 KB Output is correct
15 Correct 44 ms 8392 KB Output is correct
16 Correct 45 ms 8384 KB Output is correct
17 Correct 44 ms 8896 KB Output is correct
18 Correct 60 ms 8468 KB Output is correct
19 Correct 2 ms 760 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 608 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 42 ms 11608 KB Output is correct
26 Correct 41 ms 11972 KB Output is correct
27 Correct 51 ms 11204 KB Output is correct
28 Correct 53 ms 11204 KB Output is correct
29 Correct 52 ms 11460 KB Output is correct
30 Correct 60 ms 11308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 9160 KB Output is correct
2 Correct 35 ms 8972 KB Output is correct
3 Correct 44 ms 8392 KB Output is correct
4 Correct 45 ms 8384 KB Output is correct
5 Correct 44 ms 8896 KB Output is correct
6 Correct 60 ms 8468 KB Output is correct
7 Correct 55 ms 10688 KB Output is correct
8 Correct 54 ms 10692 KB Output is correct
9 Correct 65 ms 9924 KB Output is correct
10 Correct 66 ms 9920 KB Output is correct
11 Correct 66 ms 9920 KB Output is correct
12 Correct 70 ms 9932 KB Output is correct
13 Correct 65 ms 9928 KB Output is correct
14 Correct 69 ms 10432 KB Output is correct
15 Correct 71 ms 9932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 1 ms 764 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 36 ms 9664 KB Output is correct
9 Correct 33 ms 9684 KB Output is correct
10 Correct 38 ms 9664 KB Output is correct
11 Correct 49 ms 9672 KB Output is correct
12 Correct 37 ms 9560 KB Output is correct
13 Correct 37 ms 9664 KB Output is correct
14 Correct 33 ms 9160 KB Output is correct
15 Correct 35 ms 8972 KB Output is correct
16 Correct 44 ms 8392 KB Output is correct
17 Correct 45 ms 8384 KB Output is correct
18 Correct 44 ms 8896 KB Output is correct
19 Correct 60 ms 8468 KB Output is correct
20 Correct 2 ms 760 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 2 ms 608 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 42 ms 11608 KB Output is correct
27 Correct 41 ms 11972 KB Output is correct
28 Correct 51 ms 11204 KB Output is correct
29 Correct 53 ms 11204 KB Output is correct
30 Correct 52 ms 11460 KB Output is correct
31 Correct 60 ms 11308 KB Output is correct
32 Correct 55 ms 10688 KB Output is correct
33 Correct 54 ms 10692 KB Output is correct
34 Correct 65 ms 9924 KB Output is correct
35 Correct 66 ms 9920 KB Output is correct
36 Correct 66 ms 9920 KB Output is correct
37 Correct 70 ms 9932 KB Output is correct
38 Correct 65 ms 9928 KB Output is correct
39 Correct 69 ms 10432 KB Output is correct
40 Correct 71 ms 9932 KB Output is correct
41 Correct 66 ms 13772 KB Output is correct
42 Correct 69 ms 14052 KB Output is correct
43 Correct 82 ms 13520 KB Output is correct
44 Correct 77 ms 13508 KB Output is correct
45 Correct 92 ms 13388 KB Output is correct
46 Correct 79 ms 13508 KB Output is correct
47 Correct 76 ms 13500 KB Output is correct
48 Correct 75 ms 13520 KB Output is correct
49 Correct 80 ms 13520 KB Output is correct