Submission #691840

# Submission time Handle Problem Language Result Execution time Memory
691840 2023-01-31T17:40:03 Z Antekb Worst Reporter 4 (JOI21_worst_reporter4) C++14
79 / 100
1126 ms 212924 KB
#include<bits/stdc++.h>
 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
 
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp(x) pop_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
 
using namespace std;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~~
 
template <typename H, typename T> 
ostream& operator<<(ostream& os, pair<H, T> m){
	return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H> 
ostream& operator<<(ostream& os, vector<H> V){
	os<<"{";
	for(int i=0; i<V.size(); i++){
		if(i)os<<" ";
		os<<V[i];
	}
	os<<"}";
	return os;
}
 
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
//#define deb(x...) ;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

 
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const int N=1<<19, INF=1e9+5, mod=1e9+7, mod2=998244353;

struct modint{
	int n=0;
	modint(){}
	modint(ll x){
		n=x%mod;
		if(n<0)n+=mod;
	}
	operator int(){
		return n;
	}
	modint operator+(modint a){a.n = n+a.n; if(a.n>=mod)a.n-=mod;return a;}
	modint operator+=(modint a){return (*this)=(*this)+a;}
	modint operator-(modint a){a.n = n-a.n; if(a.n<0)a.n+=mod;return a;}
	modint operator-=(modint a){return (*this)=(*this)-a;}
	modint operator*(modint a){a.n = (n*1ll*a.n)%mod; return a;}
	modint operator*=(modint a){return (*this)=(*this)*a;}
	modint operator^(const ll &m)const{
		modint a(1);
		if(m==0)return a;
		if(m==1)return (*this);
		a=(*this)^(m/2);
		a*=a;
		return a*((*this)^(m&1));
	}
	modint odw(){
		return (*this)^((ll)mod-2);
	}
	modint operator/(modint a){return (*this)*a.odw();}
	modint operator/=(modint a){return (*this)=(*this)/a;}
	bool operator==(modint a){return a.n==n;}
	friend ostream& operator<<(ostream& os, modint m) {
		return os << m.n; 
	}
};
modint fact[N], fact2[N];
typedef vector<modint> vm;
void factinit(){
    fact[0]=1;
    for(int i=1; i<N; i++){
        fact[i]=(fact[i-1]*modint(i))%mod;
    }
    fact2[N-1]=fact[N-1].odw();
    for(int i=N-2; i>=0; i--){
    	fact2[i]=(fact2[i+1]*modint(i+1))%mod;
    }
}
modint npok(int _n, int _k){
    return fact[_n]*fact2[_k]*fact2[_n-_k];
}
int deg[N], A[N], H[N], C[N], czy[N];
vi E[N];
struct node{
	node *l=nullptr,*r=nullptr;
	ll val=0, lazy=0;
	node(){};
	void prop(){
		//deb(val, lazy, l, r);
		if(l){
			assert(l);
			l->val=max(l->val+lazy, val);
			l->lazy+=lazy;
		}
		if(r){
			r->val=max(r->val+lazy, val);
			r->lazy+=lazy;
		}
		lazy=0;
	}
};
node* merge(node*u, node*v){
	if(!u)return v;
	if(!v)return u;
	if(!u->l){
		v->val+=u->val;
		v->lazy+=u->val;
		delete u;
		return v;
	}
	if(!v->l){
		u->val+=v->val;
		u->lazy+=v->val;
		delete v;
		return u;
	}
	u->prop();
	v->prop();
	u->l=merge(u->l, v->l);
	u->r=merge(u->r, v->r);
	delete v;
	return u;
}
void add(node* v, int L, int R, int l, int r, ll c){
	if(l==L && r==R){
		v->val=max(c, v->val);
		return;
	}
	if(!v->l){
		v->l=(new node);
		v->r=(new node);
	}
	v->prop();
	int M=(L+R)>>1;
	if(l<=M)add(v->l, L, M, l, min(M,r), c);
	if(r>M)add(v->r, M+1, R, max(l, M+1), r, c);
	return;
}
ll get_val(node* v, int L, int R, int t){
	if(!v->l)return v->val;
	v->prop();
	int M=(L+R)>>1;
	if(t<=M)return max(v->val, get_val(v->l, L, M, t));
	else return max(v->val, get_val(v->r, M+1, R, t));
}
node* dfs(int v){
	//deb(v);
	node* root=0;
	ll sum=C[v];
	for(int u:E[v]){
		node *w=dfs(u);
		assert(w);
		sum+=get_val(w, 0, N-1, H[v]);
		root=merge(root, w);
	}
	if(!root)root=new node;
	add(root, 0, N-1, 0, H[v], sum);
	return root;
}
int main(){
	//factinit();
	//BOOST;
	int n; 
	cin>>n;
	vector<int> ska;
	ll sum=0;
	for(int i=1; i<=n; i++){
		cin>>A[i]>>H[i]>>C[i];
		deg[A[i]]++;
		ska.pb(H[i]);
		sum+=C[i];
	}
	sor(ska);
	ska.resize(unique(all(ska))- ska.begin());
	for(int i=1; i<=n; i++){
		H[i]=lower_bound(all(ska), H[i])-ska.begin();
	}
	vi V;
	for(int i=1; i<=n; i++){
		if(deg[i]==0){
			V.pb(i);
		}
	}
	for(int i=0; i<V.size(); i++){
		int v=V[i];
		if(!--deg[A[v]]){
			V.pb(A[v]);
		}
		E[A[v]].pb(v);
	}
	//deb(V);
	node* root=dfs(1);
	cout<<sum-get_val(root, 0, N-1, 0);
}

Compilation message

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:220:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  220 |  for(int i=0; i<V.size(); i++){
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16720 KB Output is correct
2 Correct 8 ms 16724 KB Output is correct
3 Correct 8 ms 16724 KB Output is correct
4 Correct 34 ms 16716 KB Output is correct
5 Correct 27 ms 18116 KB Output is correct
6 Correct 19 ms 17184 KB Output is correct
7 Correct 18 ms 17116 KB Output is correct
8 Correct 23 ms 17968 KB Output is correct
9 Correct 21 ms 17124 KB Output is correct
10 Correct 18 ms 17012 KB Output is correct
11 Correct 17 ms 17108 KB Output is correct
12 Correct 18 ms 17868 KB Output is correct
13 Correct 16 ms 17436 KB Output is correct
14 Correct 17 ms 17868 KB Output is correct
15 Correct 23 ms 17188 KB Output is correct
16 Correct 21 ms 18040 KB Output is correct
17 Correct 18 ms 17120 KB Output is correct
18 Correct 17 ms 17000 KB Output is correct
19 Correct 22 ms 21456 KB Output is correct
20 Correct 21 ms 21564 KB Output is correct
21 Correct 22 ms 21600 KB Output is correct
22 Correct 21 ms 17364 KB Output is correct
23 Correct 20 ms 16980 KB Output is correct
24 Correct 17 ms 17632 KB Output is correct
25 Correct 18 ms 17248 KB Output is correct
26 Correct 16 ms 17924 KB Output is correct
27 Correct 22 ms 20444 KB Output is correct
28 Correct 29 ms 20052 KB Output is correct
29 Correct 18 ms 19028 KB Output is correct
30 Correct 17 ms 17764 KB Output is correct
31 Correct 15 ms 17748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16720 KB Output is correct
2 Correct 8 ms 16724 KB Output is correct
3 Correct 8 ms 16724 KB Output is correct
4 Correct 34 ms 16716 KB Output is correct
5 Correct 27 ms 18116 KB Output is correct
6 Correct 19 ms 17184 KB Output is correct
7 Correct 18 ms 17116 KB Output is correct
8 Correct 23 ms 17968 KB Output is correct
9 Correct 21 ms 17124 KB Output is correct
10 Correct 18 ms 17012 KB Output is correct
11 Correct 17 ms 17108 KB Output is correct
12 Correct 18 ms 17868 KB Output is correct
13 Correct 16 ms 17436 KB Output is correct
14 Correct 17 ms 17868 KB Output is correct
15 Correct 23 ms 17188 KB Output is correct
16 Correct 21 ms 18040 KB Output is correct
17 Correct 18 ms 17120 KB Output is correct
18 Correct 17 ms 17000 KB Output is correct
19 Correct 22 ms 21456 KB Output is correct
20 Correct 21 ms 21564 KB Output is correct
21 Correct 22 ms 21600 KB Output is correct
22 Correct 21 ms 17364 KB Output is correct
23 Correct 20 ms 16980 KB Output is correct
24 Correct 17 ms 17632 KB Output is correct
25 Correct 18 ms 17248 KB Output is correct
26 Correct 16 ms 17924 KB Output is correct
27 Correct 22 ms 20444 KB Output is correct
28 Correct 29 ms 20052 KB Output is correct
29 Correct 18 ms 19028 KB Output is correct
30 Correct 17 ms 17764 KB Output is correct
31 Correct 15 ms 17748 KB Output is correct
32 Correct 35 ms 17972 KB Output is correct
33 Correct 1126 ms 70500 KB Output is correct
34 Correct 518 ms 30884 KB Output is correct
35 Correct 883 ms 71740 KB Output is correct
36 Correct 508 ms 31028 KB Output is correct
37 Correct 434 ms 29832 KB Output is correct
38 Correct 424 ms 29556 KB Output is correct
39 Correct 383 ms 64100 KB Output is correct
40 Correct 305 ms 45360 KB Output is correct
41 Correct 294 ms 45308 KB Output is correct
42 Correct 410 ms 66020 KB Output is correct
43 Correct 318 ms 39280 KB Output is correct
44 Correct 798 ms 65800 KB Output is correct
45 Correct 454 ms 29964 KB Output is correct
46 Correct 371 ms 29276 KB Output is correct
47 Correct 744 ms 209228 KB Output is correct
48 Correct 641 ms 209184 KB Output is correct
49 Correct 535 ms 212924 KB Output is correct
50 Correct 517 ms 44396 KB Output is correct
51 Correct 451 ms 26440 KB Output is correct
52 Correct 508 ms 54732 KB Output is correct
53 Correct 394 ms 36068 KB Output is correct
54 Correct 318 ms 64364 KB Output is correct
55 Correct 657 ms 185052 KB Output is correct
56 Correct 458 ms 124300 KB Output is correct
57 Correct 422 ms 93152 KB Output is correct
58 Correct 316 ms 57156 KB Output is correct
59 Correct 310 ms 57188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16720 KB Output is correct
2 Correct 8 ms 16724 KB Output is correct
3 Correct 8 ms 16724 KB Output is correct
4 Correct 34 ms 16716 KB Output is correct
5 Correct 27 ms 18116 KB Output is correct
6 Correct 19 ms 17184 KB Output is correct
7 Correct 18 ms 17116 KB Output is correct
8 Correct 23 ms 17968 KB Output is correct
9 Correct 21 ms 17124 KB Output is correct
10 Correct 18 ms 17012 KB Output is correct
11 Correct 17 ms 17108 KB Output is correct
12 Correct 18 ms 17868 KB Output is correct
13 Correct 16 ms 17436 KB Output is correct
14 Correct 17 ms 17868 KB Output is correct
15 Correct 23 ms 17188 KB Output is correct
16 Correct 21 ms 18040 KB Output is correct
17 Correct 18 ms 17120 KB Output is correct
18 Correct 17 ms 17000 KB Output is correct
19 Correct 22 ms 21456 KB Output is correct
20 Correct 21 ms 21564 KB Output is correct
21 Correct 22 ms 21600 KB Output is correct
22 Correct 21 ms 17364 KB Output is correct
23 Correct 20 ms 16980 KB Output is correct
24 Correct 17 ms 17632 KB Output is correct
25 Correct 18 ms 17248 KB Output is correct
26 Correct 16 ms 17924 KB Output is correct
27 Correct 22 ms 20444 KB Output is correct
28 Correct 29 ms 20052 KB Output is correct
29 Correct 18 ms 19028 KB Output is correct
30 Correct 17 ms 17764 KB Output is correct
31 Correct 15 ms 17748 KB Output is correct
32 Correct 35 ms 17972 KB Output is correct
33 Correct 1126 ms 70500 KB Output is correct
34 Correct 518 ms 30884 KB Output is correct
35 Correct 883 ms 71740 KB Output is correct
36 Correct 508 ms 31028 KB Output is correct
37 Correct 434 ms 29832 KB Output is correct
38 Correct 424 ms 29556 KB Output is correct
39 Correct 383 ms 64100 KB Output is correct
40 Correct 305 ms 45360 KB Output is correct
41 Correct 294 ms 45308 KB Output is correct
42 Correct 410 ms 66020 KB Output is correct
43 Correct 318 ms 39280 KB Output is correct
44 Correct 798 ms 65800 KB Output is correct
45 Correct 454 ms 29964 KB Output is correct
46 Correct 371 ms 29276 KB Output is correct
47 Correct 744 ms 209228 KB Output is correct
48 Correct 641 ms 209184 KB Output is correct
49 Correct 535 ms 212924 KB Output is correct
50 Correct 517 ms 44396 KB Output is correct
51 Correct 451 ms 26440 KB Output is correct
52 Correct 508 ms 54732 KB Output is correct
53 Correct 394 ms 36068 KB Output is correct
54 Correct 318 ms 64364 KB Output is correct
55 Correct 657 ms 185052 KB Output is correct
56 Correct 458 ms 124300 KB Output is correct
57 Correct 422 ms 93152 KB Output is correct
58 Correct 316 ms 57156 KB Output is correct
59 Correct 310 ms 57188 KB Output is correct
60 Correct 9 ms 16724 KB Output is correct
61 Incorrect 8 ms 16724 KB Output isn't correct
62 Halted 0 ms 0 KB -