# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1102237 |
2024-10-17T18:16:46 Z |
imarn |
Nile (IOI24_nile) |
C++17 |
|
76 ms |
12848 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(q1[id1].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){
| ~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
608 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
2 ms |
608 KB |
Output is correct |
5 |
Correct |
1 ms |
608 KB |
Output is correct |
6 |
Correct |
1 ms |
608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
9696 KB |
Output is correct |
2 |
Correct |
36 ms |
12104 KB |
Output is correct |
3 |
Correct |
42 ms |
11988 KB |
Output is correct |
4 |
Correct |
49 ms |
12184 KB |
Output is correct |
5 |
Correct |
38 ms |
11984 KB |
Output is correct |
6 |
Correct |
39 ms |
11992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
9676 KB |
Output is correct |
2 |
Correct |
36 ms |
10508 KB |
Output is correct |
3 |
Correct |
45 ms |
9820 KB |
Output is correct |
4 |
Correct |
47 ms |
9776 KB |
Output is correct |
5 |
Correct |
58 ms |
10156 KB |
Output is correct |
6 |
Correct |
52 ms |
9688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
608 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
2 ms |
608 KB |
Output is correct |
5 |
Correct |
1 ms |
608 KB |
Output is correct |
6 |
Correct |
1 ms |
608 KB |
Output is correct |
7 |
Correct |
2 ms |
608 KB |
Output is correct |
8 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
608 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
2 ms |
608 KB |
Output is correct |
5 |
Correct |
1 ms |
608 KB |
Output is correct |
6 |
Correct |
1 ms |
608 KB |
Output is correct |
7 |
Correct |
36 ms |
9696 KB |
Output is correct |
8 |
Correct |
36 ms |
12104 KB |
Output is correct |
9 |
Correct |
42 ms |
11988 KB |
Output is correct |
10 |
Correct |
49 ms |
12184 KB |
Output is correct |
11 |
Correct |
38 ms |
11984 KB |
Output is correct |
12 |
Correct |
39 ms |
11992 KB |
Output is correct |
13 |
Correct |
39 ms |
9676 KB |
Output is correct |
14 |
Correct |
36 ms |
10508 KB |
Output is correct |
15 |
Correct |
45 ms |
9820 KB |
Output is correct |
16 |
Correct |
47 ms |
9776 KB |
Output is correct |
17 |
Correct |
58 ms |
10156 KB |
Output is correct |
18 |
Correct |
52 ms |
9688 KB |
Output is correct |
19 |
Correct |
2 ms |
608 KB |
Output is correct |
20 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
9676 KB |
Output is correct |
2 |
Correct |
36 ms |
10508 KB |
Output is correct |
3 |
Correct |
45 ms |
9820 KB |
Output is correct |
4 |
Correct |
47 ms |
9776 KB |
Output is correct |
5 |
Correct |
58 ms |
10156 KB |
Output is correct |
6 |
Correct |
52 ms |
9688 KB |
Output is correct |
7 |
Correct |
62 ms |
12848 KB |
Output is correct |
8 |
Correct |
61 ms |
12604 KB |
Output is correct |
9 |
Correct |
67 ms |
12008 KB |
Output is correct |
10 |
Correct |
66 ms |
11972 KB |
Output is correct |
11 |
Correct |
67 ms |
11972 KB |
Output is correct |
12 |
Correct |
66 ms |
11972 KB |
Output is correct |
13 |
Correct |
68 ms |
11972 KB |
Output is correct |
14 |
Correct |
64 ms |
11984 KB |
Output is correct |
15 |
Correct |
76 ms |
11972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
608 KB |
Output is correct |
4 |
Correct |
1 ms |
608 KB |
Output is correct |
5 |
Correct |
2 ms |
608 KB |
Output is correct |
6 |
Correct |
1 ms |
608 KB |
Output is correct |
7 |
Correct |
1 ms |
608 KB |
Output is correct |
8 |
Correct |
36 ms |
9696 KB |
Output is correct |
9 |
Correct |
36 ms |
12104 KB |
Output is correct |
10 |
Correct |
42 ms |
11988 KB |
Output is correct |
11 |
Correct |
49 ms |
12184 KB |
Output is correct |
12 |
Correct |
38 ms |
11984 KB |
Output is correct |
13 |
Correct |
39 ms |
11992 KB |
Output is correct |
14 |
Correct |
39 ms |
9676 KB |
Output is correct |
15 |
Correct |
36 ms |
10508 KB |
Output is correct |
16 |
Correct |
45 ms |
9820 KB |
Output is correct |
17 |
Correct |
47 ms |
9776 KB |
Output is correct |
18 |
Correct |
58 ms |
10156 KB |
Output is correct |
19 |
Correct |
52 ms |
9688 KB |
Output is correct |
20 |
Correct |
2 ms |
608 KB |
Output is correct |
21 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |