Submission #1210694

#TimeUsernameProblemLanguageResultExecution timeMemory
1210694salmonWorst Reporter 4 (JOI21_worst_reporter4)C++20
14 / 100
639 ms589824 KiB
#include <bits/stdc++.h>
using namespace std;

int N;
vector<int> children[200100];
int parent[200100];
int sise[200100];
int lst[200100];
int cost[200100];
int bound = 1.1e9;

struct node{
	
	int s,e,m;
	node *l,*r;
	long long int lazy;
	long long int v;
	
	node(int S, int E){
		s = S;
		e = E;
		m = (s + e)/2;
		
		lazy = 0;
		v = 0;
		
		l = NULL;
		r = NULL;
	}
	
	void merge(node* n){
		v += n -> v;
		lazy += n -> lazy;
		
		if(l == NULL) l = n -> l;
		else if(n -> l != NULL) l -> merge(n -> l);
		
		if(r == NULL) r = n -> r;
		else if(n -> r != NULL) r -> merge(n -> r);
	}
	
	long long int query(int i){
		if(i <= m){
			if(l == NULL) return lazy;
			else return lazy + l -> query(i);
		}
		else{
			if(r == NULL) return lazy;
			else return lazy + r -> query(i);
		}
	}
	
	int queryin(long long int i){
		if(s == e){
			return s;
		}
		
		if(l != NULL && l -> v >= i - lazy){
			return l -> queryin(i - lazy);
		}
		else{
			if(r == NULL) return s;
			return r -> queryin(i - lazy);
		}
	}	
	
	void update(int S, int E, int k){
		lazy += k;
		v += k;
	}
	
	void flapdate(int S, int E, long long int k){
		if(S <= s && e <= E){
			l = NULL;
			r = NULL;
			v = k;
			lazy = k;
			return;
		}
		
		if(l == NULL){
			l = new node(s,m);
			r = new node(m + 1, e);
		}
			
		if(S <= m){
			if(l == NULL) l = new node(s,m);
			l -> flapdate(S,E,k - lazy);
		}
		if(m < E){
			if(r == NULL) r = new node(m + 1, e);
			r -> flapdate(S,E,k - lazy);
		}
		
		if(r == NULL) v = lazy;
		else v = r -> v + lazy;
	}
	
};

node* solve(int i){// printf("%d\n",i);
	node* n = new node(0,bound);
	
	for(int j : children[i]){
		if(j == i) continue;
		n -> merge(solve(j));
	}
	
	int pos = n -> queryin(n -> query(lst[i]) - cost[i]);
	
	n -> flapdate(pos,lst[i],n -> query(lst[i]) - cost[i]);
	n -> update(0,bound,cost[i]);
	//printf("%d\n",i);
	return n;
}

int main(){
	
	scanf(" %d",&N);
	
	for(int i = 1; i <= N; i++){
		scanf(" %d",&parent[i]);
		scanf(" %d",&lst[i]); 
		scanf(" %d",&cost[i]);
	
		children[parent[i]].push_back(i);
	}
	
	printf("%lld\n",solve(1) -> query(1));
	
}

Compilation message (stderr)

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:119:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |         scanf(" %d",&N);
      |         ~~~~~^~~~~~~~~~
worst_reporter2.cpp:122:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |                 scanf(" %d",&parent[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~
worst_reporter2.cpp:123:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |                 scanf(" %d",&lst[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~
worst_reporter2.cpp:124:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  124 |                 scanf(" %d",&cost[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...