답안 #916121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
916121 2024-01-25T10:43:55 Z emptypringlescan Truck Driver (IOI23_deliveries) C++17
50 / 100
5500 ms 56200 KB
#include <bits/stdc++.h>
using namespace std;
#include "deliveries.h"
vector<pair<int,long long> > adj[100005];
long long subsz[100005],arr[100005],ans;
void fsz(int x, int p){
	subsz[x]=arr[x];
	for(pair<int,long long> i:adj[x]){
		if(i.first==p) continue;
		fsz(i.first,x);
		subsz[x]+=subsz[i.first];
	}
}
void dfs(int x, int p){
	for(pair<int,long long> i:adj[x]){
		if(i.first==p) continue;
		ans+=i.second*min(subsz[i.first],1+subsz[0]-subsz[i.first]);
		dfs(i.first,x);
	}
}
long long pref[100005];
struct noode{
	int s,e,m;
	long long val;
	noode *l, *r;
	noode(int S, int E){
		s=S; e=E; m=(s+e)/2;
		if(s!=e){
			l=new noode(s,m);
			r=new noode(m+1,e);
			val=l->val+r->val;
		}
		else{
			val=arr[s];
		}
	}
	void update(int S, long long V){
		if(s==e){
			val+=V;
			return;
		}
		if(S<=m) l->update(S,V);
		else r->update(S,V);
		val=l->val+r->val;
	}
	int bsta(long long V){
		if(s==e) return s;
		if(l->val>V) return l->bsta(V);
		else return r->bsta(V-l->val);
	}
} *r1;
struct node{
	int s,e,m;
	long long val,lazy;
	node *l, *r;
	node(int S, int E){
		s=S; e=E; m=(s+e)/2;
		val=lazy=0;
		if(s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	void prop(){
		if(lazy==0||s==e) return;
		l->val+=lazy*(pref[m]-pref[s-1]);
		l->lazy+=lazy;
		r->val+=lazy*(pref[e]-pref[m]);
		r->lazy+=lazy;
		lazy=0;
	}
	void update(int S, int E, long long V){
		if(S<=s&&e<=E){
			val+=V*(pref[e]-pref[s-1]);
			lazy+=V;
			return;
		}
		prop();
		if(E<=m) l->update(S,E,V);
		else if(S>m) r->update(S,E,V);
		else l->update(S,m,V),r->update(m+1,E,V);
		val=l->val+r->val;
	}
	long long query(int S, int E){
		if(S<=s&&e<=E) return val;
		prop();
		if(E<=m) return l->query(S,E);
		else if(S>m) return r->query(S,E);
		else return l->query(S,m)+r->query(m+1,E);
	}
} *r2,*r3;
int st=1,n;
long long tot;
void init(int N, vector<int> u, vector<int> v, vector<int> t, vector<int> w){
	n=N;
	bool can=true;
	for(int i=0; i<n-1; i++){
		if(u[i]!=i||v[i]!=i+1) can=false;
		adj[u[i]].push_back({v[i],t[i]});
		adj[v[i]].push_back({u[i],t[i]});
	}
	if(can){
		st=4;
		for(int i=0; i<n-1; i++) pref[i+1]=pref[i]+t[i];
		pref[n]=pref[n-1];
	}
	for(int i=0; i<n; i++){
		arr[i]=w[i];
		tot+=w[i];
	}
	if(can){
		arr[0]++;
		r1=new noode(0,n-1);
		r2=new node(1,n-1);
		r3=new node(1,n-1);
		for(int i=0; i<n; i++){
			if(i<n-1) r2->update(i+1,n-1,arr[i]);
			if(i) r3->update(1,i,arr[i]);
		}
	}
}
long long max_time(int s, int x){
	if(st==1){
		arr[s]=x;
		fsz(0,-1);
		ans=0;
		dfs(0,-1);
		return ans*2ll;
	}
	if(s==0) x++;
	long long cha=x-arr[s];
	arr[s]=x;
	tot+=cha;
	r1->update(s,cha);
	if(s<n-1) r2->update(s+1,n-1,cha);
	if(s) r3->update(1,s,cha);
	int mid=r1->bsta(tot/2);
	long long ret=0;
	if(mid) ret+=r2->query(1,mid);
	if(mid<n-1) ret+=r3->query(mid+1,n-1);
	return ret*2ll;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 12112 KB Output is correct
2 Correct 78 ms 12116 KB Output is correct
3 Correct 74 ms 12116 KB Output is correct
4 Correct 74 ms 12160 KB Output is correct
5 Correct 75 ms 12372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 9 ms 5052 KB Output is correct
3 Correct 12 ms 4952 KB Output is correct
4 Correct 16 ms 5084 KB Output is correct
5 Correct 15 ms 4956 KB Output is correct
6 Correct 15 ms 4952 KB Output is correct
7 Correct 15 ms 4956 KB Output is correct
8 Correct 15 ms 4956 KB Output is correct
9 Correct 15 ms 4956 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Correct 12 ms 5060 KB Output is correct
12 Correct 16 ms 5052 KB Output is correct
13 Correct 15 ms 4956 KB Output is correct
14 Correct 20 ms 4956 KB Output is correct
15 Correct 21 ms 5108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 12112 KB Output is correct
2 Correct 78 ms 12116 KB Output is correct
3 Correct 74 ms 12116 KB Output is correct
4 Correct 74 ms 12160 KB Output is correct
5 Correct 75 ms 12372 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 32 ms 4956 KB Output is correct
8 Correct 3081 ms 6536 KB Output is correct
9 Execution timed out 5547 ms 16696 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 12112 KB Output is correct
2 Correct 78 ms 12116 KB Output is correct
3 Correct 74 ms 12116 KB Output is correct
4 Correct 74 ms 12160 KB Output is correct
5 Correct 75 ms 12372 KB Output is correct
6 Correct 1 ms 5164 KB Output is correct
7 Correct 4 ms 5212 KB Output is correct
8 Correct 35 ms 9960 KB Output is correct
9 Correct 610 ms 54604 KB Output is correct
10 Correct 622 ms 54316 KB Output is correct
11 Correct 665 ms 54624 KB Output is correct
12 Correct 720 ms 56200 KB Output is correct
13 Correct 775 ms 56028 KB Output is correct
14 Correct 349 ms 54576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 12112 KB Output is correct
2 Correct 78 ms 12116 KB Output is correct
3 Correct 74 ms 12116 KB Output is correct
4 Correct 74 ms 12160 KB Output is correct
5 Correct 75 ms 12372 KB Output is correct
6 Correct 3 ms 4952 KB Output is correct
7 Correct 9 ms 5052 KB Output is correct
8 Correct 12 ms 4952 KB Output is correct
9 Correct 16 ms 5084 KB Output is correct
10 Correct 15 ms 4956 KB Output is correct
11 Correct 15 ms 4952 KB Output is correct
12 Correct 15 ms 4956 KB Output is correct
13 Correct 15 ms 4956 KB Output is correct
14 Correct 15 ms 4956 KB Output is correct
15 Correct 3 ms 5212 KB Output is correct
16 Correct 12 ms 5060 KB Output is correct
17 Correct 16 ms 5052 KB Output is correct
18 Correct 15 ms 4956 KB Output is correct
19 Correct 20 ms 4956 KB Output is correct
20 Correct 21 ms 5108 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 32 ms 4956 KB Output is correct
23 Correct 3081 ms 6536 KB Output is correct
24 Execution timed out 5547 ms 16696 KB Time limit exceeded
25 Halted 0 ms 0 KB -