Submission #277677

# Submission time Handle Problem Language Result Execution time Memory
277677 2020-08-21T06:46:58 Z tmwilliamlin168 Constellation 3 (JOI20_constellation3) C++14
35 / 100
422 ms 49784 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=2e5;
int n, m, a[mxN];
ar<int, 3> b[mxN];
ll s, dp2[mxN];

struct ds1 {
	ar<int, 2> st[2*mxN];
	void init() {
		for(int i=0; i<n; ++i)
			st[i+n]={a[i], i};
		for(int i=n-1; i; --i)
			st[i]=max(st[2*i], st[2*i+1]);
	}
	ar<int, 2> qry(int l, int r) {
		ar<int, 2> b{};
		for(l+=n, r+=n+1; l<r; ++l/=2, r/=2) {
			if(l&1)
				b=max(st[l], b);
			if(r&1)
				b=max(st[r-1], b);
		}
		return b;
	}
} ds1;

struct ds2 {
	ar<int, 3> st[2*mxN];
	void init() {
		for(int i=0; i<m; ++i)
			st[i+m]={b[i][1], b[i][0], b[i][2]};
		for(int i=m-1; i; --i)
			st[i]=min(st[2*i], st[2*i+1]);
	}
	ar<int, 3> qry(int l, int r) {
		ar<int, 3> b{n+1};
		for(l+=m, r+=m+1; l<r; ++l/=2, r/=2) {
			if(l&1)
				b=min(st[l], b);
			if(r&1)
				b=min(st[r-1], b);
		}
		return b;
	}
	void upd(int i, ar<int, 3> x) {
		for(st[i+=m]=x; i/=2; )
			st[i]=min(st[2*i], st[2*i+1]);
	}
} ds2;

struct ds3 {
	ll ft[mxN+1];
	void upd(int i, ll x) {
		for(++i; i<=n; i+=i&-i)
			ft[i]+=x;
	}
	void upd(int l, int r, ll x) {
		upd(l, x);
		upd(r+1, -x);
	}
	ll qry(int i) {
		ll r=0;
		for(++i; i; i-=i&-i)
			r+=ft[i];
		return r;
	}
} ds3;

int dfs(int l, int r, int mx) {
	if(l>r)
		return -1;
	int m2=ds1.qry(l, r)[1];
	int lc=dfs(l, m2-1, a[m2]), rc=dfs(m2+1, r, a[m2]);
	dp2[m2]=(~lc?dp2[lc]:0)+(~rc?dp2[rc]:0);
	int l2=lower_bound(b, b+m, ar<int, 3>{l})-b, r2=lower_bound(b, b+m, ar<int, 3>{r+1})-b-1;
	while(1) {
		ar<int, 3> d=ds2.qry(l2, r2);
		if(d[0]>mx)
			break;
		if(d[1]<m2) {
			dp2[m2]=max(d[2]+(~lc?ds3.qry(d[1]):0)+(~rc?dp2[rc]:0), dp2[m2]);
		} else if(d[1]>m2) {
			dp2[m2]=max(d[2]+(~lc?dp2[lc]:0)+(~rc?ds3.qry(d[1]):0), dp2[m2]);
		} else {
			dp2[m2]=max(d[2]+(~lc?dp2[lc]:0)+(~rc?dp2[rc]:0), dp2[m2]);
		}
		ds2.upd(lower_bound(b, b+m, ar<int, 3>{d[1], d[0], d[2]})-b, {n+1});
	}
	ds3.upd(l, m2, dp2[rc]);
	ds3.upd(m2, r, dp2[lc]);
	return m2;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> a[i];
	ds1.init();
	cin >> m;
	for(int i=0; i<m; ++i) {
		cin >> b[i][0] >> b[i][1] >> b[i][2], --b[i][0];
		s+=b[i][2];
	}
	sort(b, b+m);
	ds2.init();
	int rt=dfs(0, n-1, n);
	cout << s-dp2[rt];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
33 Correct 3 ms 768 KB Output is correct
34 Correct 4 ms 640 KB Output is correct
35 Correct 3 ms 640 KB Output is correct
36 Correct 3 ms 768 KB Output is correct
37 Correct 3 ms 768 KB Output is correct
38 Correct 3 ms 896 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 3 ms 768 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 768 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
33 Correct 3 ms 768 KB Output is correct
34 Correct 4 ms 640 KB Output is correct
35 Correct 3 ms 640 KB Output is correct
36 Correct 3 ms 768 KB Output is correct
37 Correct 3 ms 768 KB Output is correct
38 Correct 3 ms 896 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 3 ms 768 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 768 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 246 ms 15076 KB Output is correct
46 Correct 247 ms 14712 KB Output is correct
47 Correct 252 ms 14968 KB Output is correct
48 Correct 242 ms 14964 KB Output is correct
49 Correct 250 ms 14712 KB Output is correct
50 Correct 246 ms 14592 KB Output is correct
51 Correct 237 ms 14832 KB Output is correct
52 Correct 244 ms 15040 KB Output is correct
53 Correct 240 ms 14776 KB Output is correct
54 Correct 422 ms 37996 KB Output is correct
55 Correct 384 ms 31612 KB Output is correct
56 Correct 361 ms 28080 KB Output is correct
57 Correct 347 ms 25732 KB Output is correct
58 Correct 333 ms 30764 KB Output is correct
59 Correct 377 ms 30840 KB Output is correct
60 Incorrect 281 ms 49784 KB Output isn't correct
61 Halted 0 ms 0 KB -