답안 #939783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939783 2024-03-06T18:25:00 Z AdamGS Truck Driver (IOI23_deliveries) C++17
100 / 100
885 ms 48688 KB
#include "deliveries.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e5+7;
vector<pair<ll,ll>>V[LIM];
ll trma[4*LIM], trsum[4*LIM], trwag[4*LIM], lazy[4*LIM], N=1, n;
ll odl[LIM], jaki[LIM], kto[LIM], ile[LIM], oc[LIM], sci[LIM], W[LIM], akt, aktans, aktile;
void DFS(int x, int o) {
  ile[x]=1;
  for(auto i : V[x]) if(i.st!=o) {
    odl[i.st]=odl[x]+i.nd;
    DFS(i.st, x);
    ile[x]+=ile[i.st];
  }
  rep(i, V[x].size()) if(V[x][0].st==o || (V[x][i].st!=o && ile[V[x][0].st]<ile[V[x][i].st])) swap(V[x][i], V[x][0]);
}
void DFS2(int x, int o) {
  jaki[x]=akt;
  kto[akt]=x;
  ++akt;
  oc[x]=o;
  for(auto i : V[x]) if(i.st==o) trwag[N+akt-1]=i.nd;
  if(V[x].size()==1 && V[x][0].st==o) return;
  sci[V[x][0].st]=sci[x];
  DFS2(V[x][0].st, x);
  for(auto i : V[x]) if(i.st!=V[x][0].st && i.st!=o) DFS2(i.st, x);
}
void spl(int v) {
  trma[2*v]+=lazy[v];
  trma[2*v+1]+=lazy[v];
  trsum[2*v]+=lazy[v]*trwag[2*v];
  trsum[2*v+1]+=lazy[v]*trwag[2*v+1];
  lazy[2*v]+=lazy[v];
  lazy[2*v+1]+=lazy[v];
  lazy[v]=0;
}
void upd(int v, int l, int r, int a, int b, ll x) {
  if(r<a || b<l) return;
  if(a<=l && r<=b) {
    trma[v]+=x;
    trsum[v]+=trwag[v]*x;
    lazy[v]+=x;
    return;
  }
  if(lazy[v]) spl(v);
  int mid=(l+r)/2;
  upd(2*v, l, mid, a, b, x);
  upd(2*v+1, mid+1, r, a, b, x);
  trma[v]=max(trma[2*v], trma[2*v+1]);
  trsum[v]=trsum[2*v]+trsum[2*v+1];
}
ll cnt(int v, int l, int r, int a, int b) {
  if(r<a || b<l) return 0;
  if(a<=l && r<=b) return trsum[v];
  if(lazy[v]) spl(v);
  int mid=(l+r)/2;
  return cnt(2*v, l, mid, a, b)+cnt(2*v+1, mid+1, r, a, b);
}
void zmiana(int v, ll x) {
  W[v]+=x;
  aktile+=x;
  aktans+=odl[v]*x;
  while(sci[v]!=0) {
    upd(1, 0, N-1, jaki[sci[v]], jaki[v], x);
    v=oc[sci[v]];
  }
  upd(1, 0, N-1, jaki[sci[v]], jaki[v], x);
}
ll licz(int v) {
  ll ans=0;
  while(sci[v]!=0) {
    ans+=cnt(1, 0, N-1, jaki[sci[v]], jaki[v]);
    v=oc[sci[v]];
  }
  ans+=cnt(1, 0, N-1, jaki[sci[v]], jaki[v]);
  return ans;
}
void init(int _N, vector<int>_U, vector<int>_V, vector<int>_T, vector<int>_W) {
  n=_N;
  while(N<n) N*=2;
  rep(i, n-1) {
    V[_U[i]].pb({_V[i], _T[i]});
    V[_V[i]].pb({_U[i], _T[i]});
  }
  rep(i, n) sci[i]=i;
  DFS(0, 0);
  DFS2(0, 0);
  for(int i=N-1; i; --i) trwag[i]=trwag[2*i]+trwag[2*i+1];
  ++_W[0];
  rep(i, n) zmiana(i, _W[i]);
}
ll max_time(int S, int X) {
  if(!S) ++X;
  zmiana(S, X-W[S]);
  ll v=1;
  while(v<N) {
    if(lazy[v]) spl(v);
    v=2*v+1;
    if(trma[v]<=aktile/2) --v;
  }
  v-=N;
  v=kto[v];
  return 2*(aktans+aktile*odl[v]-2*licz(v));
}

Compilation message

deliveries.cpp: In function 'void DFS(int, int)':
deliveries.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
deliveries.cpp:21:3: note: in expansion of macro 'rep'
   21 |   rep(i, V[x].size()) if(V[x][0].st==o || (V[x][i].st!=o && ile[V[x][0].st]<ile[V[x][i].st])) swap(V[x][i], V[x][0]);
      |   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 26452 KB Output is correct
2 Correct 78 ms 26260 KB Output is correct
3 Correct 78 ms 26448 KB Output is correct
4 Correct 78 ms 26196 KB Output is correct
5 Correct 82 ms 26416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16476 KB Output is correct
2 Correct 5 ms 16472 KB Output is correct
3 Correct 4 ms 16476 KB Output is correct
4 Correct 4 ms 16636 KB Output is correct
5 Correct 4 ms 16476 KB Output is correct
6 Correct 4 ms 16604 KB Output is correct
7 Correct 4 ms 16476 KB Output is correct
8 Correct 4 ms 16476 KB Output is correct
9 Correct 4 ms 16476 KB Output is correct
10 Correct 4 ms 16620 KB Output is correct
11 Correct 5 ms 16476 KB Output is correct
12 Correct 4 ms 16476 KB Output is correct
13 Correct 4 ms 16476 KB Output is correct
14 Correct 4 ms 16476 KB Output is correct
15 Correct 4 ms 16476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 26452 KB Output is correct
2 Correct 78 ms 26260 KB Output is correct
3 Correct 78 ms 26448 KB Output is correct
4 Correct 78 ms 26196 KB Output is correct
5 Correct 82 ms 26416 KB Output is correct
6 Correct 3 ms 16476 KB Output is correct
7 Correct 7 ms 16476 KB Output is correct
8 Correct 59 ms 18552 KB Output is correct
9 Correct 805 ms 37640 KB Output is correct
10 Correct 798 ms 37724 KB Output is correct
11 Correct 885 ms 37596 KB Output is correct
12 Correct 619 ms 40240 KB Output is correct
13 Correct 643 ms 40116 KB Output is correct
14 Correct 631 ms 40240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 26452 KB Output is correct
2 Correct 78 ms 26260 KB Output is correct
3 Correct 78 ms 26448 KB Output is correct
4 Correct 78 ms 26196 KB Output is correct
5 Correct 82 ms 26416 KB Output is correct
6 Correct 3 ms 16476 KB Output is correct
7 Correct 4 ms 16732 KB Output is correct
8 Correct 26 ms 19280 KB Output is correct
9 Correct 267 ms 45360 KB Output is correct
10 Correct 267 ms 45372 KB Output is correct
11 Correct 278 ms 45360 KB Output is correct
12 Correct 263 ms 48432 KB Output is correct
13 Correct 266 ms 48688 KB Output is correct
14 Correct 233 ms 44592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 26452 KB Output is correct
2 Correct 78 ms 26260 KB Output is correct
3 Correct 78 ms 26448 KB Output is correct
4 Correct 78 ms 26196 KB Output is correct
5 Correct 82 ms 26416 KB Output is correct
6 Correct 3 ms 16476 KB Output is correct
7 Correct 5 ms 16472 KB Output is correct
8 Correct 4 ms 16476 KB Output is correct
9 Correct 4 ms 16636 KB Output is correct
10 Correct 4 ms 16476 KB Output is correct
11 Correct 4 ms 16604 KB Output is correct
12 Correct 4 ms 16476 KB Output is correct
13 Correct 4 ms 16476 KB Output is correct
14 Correct 4 ms 16476 KB Output is correct
15 Correct 4 ms 16620 KB Output is correct
16 Correct 5 ms 16476 KB Output is correct
17 Correct 4 ms 16476 KB Output is correct
18 Correct 4 ms 16476 KB Output is correct
19 Correct 4 ms 16476 KB Output is correct
20 Correct 4 ms 16476 KB Output is correct
21 Correct 3 ms 16476 KB Output is correct
22 Correct 7 ms 16476 KB Output is correct
23 Correct 59 ms 18552 KB Output is correct
24 Correct 805 ms 37640 KB Output is correct
25 Correct 798 ms 37724 KB Output is correct
26 Correct 885 ms 37596 KB Output is correct
27 Correct 619 ms 40240 KB Output is correct
28 Correct 643 ms 40116 KB Output is correct
29 Correct 631 ms 40240 KB Output is correct
30 Correct 3 ms 16476 KB Output is correct
31 Correct 4 ms 16732 KB Output is correct
32 Correct 26 ms 19280 KB Output is correct
33 Correct 267 ms 45360 KB Output is correct
34 Correct 267 ms 45372 KB Output is correct
35 Correct 278 ms 45360 KB Output is correct
36 Correct 263 ms 48432 KB Output is correct
37 Correct 266 ms 48688 KB Output is correct
38 Correct 233 ms 44592 KB Output is correct
39 Correct 3 ms 16476 KB Output is correct
40 Correct 5 ms 16732 KB Output is correct
41 Correct 28 ms 19272 KB Output is correct
42 Correct 354 ms 41848 KB Output is correct
43 Correct 341 ms 42804 KB Output is correct
44 Correct 336 ms 43824 KB Output is correct
45 Correct 305 ms 44336 KB Output is correct
46 Correct 293 ms 45072 KB Output is correct
47 Correct 317 ms 44084 KB Output is correct
48 Correct 308 ms 45128 KB Output is correct
49 Correct 287 ms 45824 KB Output is correct
50 Correct 283 ms 46432 KB Output is correct
51 Correct 272 ms 47152 KB Output is correct
52 Correct 516 ms 39768 KB Output is correct
53 Correct 487 ms 39728 KB Output is correct
54 Correct 520 ms 39724 KB Output is correct
55 Correct 263 ms 43528 KB Output is correct
56 Correct 249 ms 44080 KB Output is correct
57 Correct 248 ms 44080 KB Output is correct