답안 #952837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952837 2024-03-25T02:12:29 Z willychan 별자리 3 (JOI20_constellation3) C++17
100 / 100
452 ms 31312 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
int n;
vector<int> h;
namespace GET{
	const int B = 20;
	vector<int> st[B];
	void init_get(){
		for(int i=0;i<B;i++) st[i].resize(n+1);
		for(int i=1;i<=n;i++) st[0][i]=h[i];
		for(int j=1;j<B;j++){
			for(int i=1;i+(1<<j)-1<=n;i++){
				st[j][i] = max(st[j-1][i],st[j-1][i+(1<<(j-1))]);
			}
		}
	}
	int minn(int l,int r){
		if(l==r) return st[0][l];
		int len = (r-l+1);
		int p = __lg(len);
		return max(st[p][l],st[p][r-(1<<p)+1]);
	}
	pair<int,int> get(int x,int h){
		int rl,rr;
		rl=0;rr=0;
		int l = x;int r = n+1;		
		while(r-l>1){
			int m = (l+r)/2;
			if(minn(x,m)>=h) r = m;
			else l = m;
		}
		rr = l;
		l = 0;r = x;
		while(r-l>1){
			int m = (l+r)/2;
			if(minn(m,x)>=h) l = m;
			else r = m;
		}
		rl = r;
		return {rl,rr};
	}
} 

struct p_range{
	int x;
	int y;
	pair<int,int> r;
	int cost;
	ll dp;
};

struct BIT{
	int n;
	vector<ll> arr;
	void init(int _n){
		n = _n;
		arr.resize(n+1,0);
	}
	void add(int x,ll v){
		while(x<=n){
			arr[x]+=v;
			x+=(x&-x);
		}
	}
	void modify(int l,int r,ll v){
		if(l>r) return;
		add(l,v);
		add(r+1,-v);
	}
	ll query(int x){
		ll r=0;
		while(x){
			r+=arr[x];
			x-=(x&-x);
		}
		return r;
	}
};

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;	
	h.resize(n+1);
	for(int i=1;i<=n;i++) cin>>h[i];
	GET::init_get();
	int m;cin>>m;
	vector<p_range> stars(m+1);			
	ll ans = 0;
	for(int i=0;i<m;i++){
		cin>>stars[i].x>>stars[i].y;
		cin>>stars[i].cost;
		stars[i].r  = GET::get(stars[i].x,stars[i].y);
		ans+=stars[i].cost;
	}
	stars[m].x=1;
	stars[m].y=n+1;
	stars[m].r = GET::get(1,n+1);
	stars[m].cost=0;
	sort(stars.begin(),stars.end(),[](const p_range &a,const p_range &b){return a.y<b.y;});
	set<pair<int,int> > rgs;	
	BIT bit;	
	bit.init(n);
	for(int i=0;i<=m;i++){
		ll sum=0;
		vector<int> k;
		while(rgs.size()){
			auto f = rgs.lower_bound({stars[i].r.first,-1});
			if(f==rgs.end() || f->first>stars[i].r.second) break;
			k.push_back(f->second);
			rgs.erase(f);
		}
		for(auto g : k){
			sum+=stars[g].dp;
		}
		bit.modify(stars[i].r.first,stars[i].r.second,sum);
		for(auto g : k){
			bit.modify(stars[g].r.first,stars[g].r.second,-stars[g].dp);
		}
		stars[i].dp = max(sum,bit.query(stars[i].x)+stars[i].cost);
		rgs.insert({stars[i].r.first,i});
	}
	cout<<ans-stars[m].dp<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 500 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 356 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 356 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 756 KB Output is correct
19 Correct 1 ms 356 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 500 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 356 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 356 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 756 KB Output is correct
19 Correct 1 ms 356 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 2 ms 612 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 608 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 3 ms 608 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 600 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 2 ms 720 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 500 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 356 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 356 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 756 KB Output is correct
19 Correct 1 ms 356 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 2 ms 612 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 608 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 3 ms 608 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 600 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 2 ms 720 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 434 ms 31312 KB Output is correct
46 Correct 375 ms 31280 KB Output is correct
47 Correct 372 ms 31228 KB Output is correct
48 Correct 384 ms 31060 KB Output is correct
49 Correct 350 ms 30788 KB Output is correct
50 Correct 452 ms 30420 KB Output is correct
51 Correct 381 ms 30988 KB Output is correct
52 Correct 385 ms 31236 KB Output is correct
53 Correct 433 ms 31056 KB Output is correct
54 Correct 219 ms 30032 KB Output is correct
55 Correct 223 ms 29780 KB Output is correct
56 Correct 228 ms 29264 KB Output is correct
57 Correct 218 ms 29152 KB Output is correct
58 Correct 215 ms 29060 KB Output is correct
59 Correct 226 ms 29276 KB Output is correct
60 Correct 157 ms 29264 KB Output is correct
61 Correct 317 ms 29848 KB Output is correct
62 Correct 215 ms 29452 KB Output is correct
63 Correct 274 ms 29524 KB Output is correct
64 Correct 366 ms 28884 KB Output is correct
65 Correct 211 ms 29320 KB Output is correct
66 Correct 261 ms 29620 KB Output is correct