답안 #894271

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894271 2023-12-28T03:19:32 Z denniskim 치료 계획 (JOI20_treatment) C++17
100 / 100
385 ms 60596 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())

struct gujo
{
	ll T, L, R, C;
};

struct gujo2
{
	ll A, B, C, D, num;
};

ll n, m;
gujo b[500010];
gujo2 a[500010];
vector<pll> vec[500010];
ll dist[500010];
vector<ll> zip;
priority_queue<pll> pq;
ll P[500010];
ll ans = INF;

struct segtree
{
	pll seg[2000010];
	
	void update(ll no, ll s, ll e, ll w, ll v1, ll v2)
	{
		if(e < w || w < s)
			return;
		
		if(s == e)
		{
			seg[no] = {v1, v2};
			return;
		}
		
		update(no << 1, s, (s + e) >> 1, w, v1, v2);
		update(no << 1 | 1, ((s + e) >> 1) + 1, e, w, v1, v2);
		
		seg[no] = min(seg[no << 1], seg[no << 1 | 1]);
	}
	
	pll query(ll no, ll s, ll e, ll l, ll r)
	{
		if(e < l || r < s)
			return {INF, -1};
		
		if(l <= s && e <= r)
			return seg[no];
		
		pll L = query(no << 1, s, (s + e) >> 1, l, r);
		pll R = query(no << 1 | 1, ((s + e) >> 1) + 1, e, l, r);
		
		return min(L, R);
	}
}segt;

int main(void)
{
	//fastio
	
	cin >> n >> m;
	
	for(ll i = 1 ; i <= m ; i++)
	{
		cin >> b[i].T >> b[i].L >> b[i].R >> b[i].C;
		
		a[i].A = b[i].L + b[i].T;
		a[i].B = b[i].R + b[i].T + 1;
		a[i].C = b[i].L - b[i].T;
		a[i].D = b[i].R - b[i].T + 1;
		a[i].num = i;
		zip.push_back(a[i].A), zip.push_back(a[i].B), zip.push_back(a[i].C), zip.push_back(a[i].D);
	}
	
	compress(zip);
	
	for(ll i = 1 ; i <= m ; i++)
	{
		a[i].A = lower_bound(zip.begin(), zip.end(), a[i].A) - zip.begin() + 1;
		a[i].B = lower_bound(zip.begin(), zip.end(), a[i].B) - zip.begin() + 1;
		a[i].C = lower_bound(zip.begin(), zip.end(), a[i].C) - zip.begin() + 1;
		a[i].D = lower_bound(zip.begin(), zip.end(), a[i].D) - zip.begin() + 1;
	}
	
	for(ll i = 1 ; i <= m ; i++)
		dist[i] = INF;
	
	for(ll i = 1 ; i <= m ; i++)
	{
		if(b[i].L == 1)
		{
			dist[i] = b[i].C;
			pq.push({-b[i].C, i});
		}
		
		vec[a[i].C].push_back({a[i].A, a[i].num});
	}
	
	ll siz = (ll)zip.size();
	
	for(ll i = 1 ; i <= siz ; i++)
	{
		sort(vec[i].begin(), vec[i].end());
		
		if(!vec[i].empty())
		{
			P[i] = 1;
			segt.update(1, 1, siz, i, vec[i][0].fi, vec[i][0].se);
		}
		
		else
			segt.update(1, 1, siz, i, INF, -1);
	}
	
	while(!pq.empty())
	{
		pll qq = pq.top();
		pq.pop();
		
		while(1)
		{
			pll gap = segt.query(1, 1, siz, 1, a[qq.se].D);
			
			if(gap.fi > a[qq.se].B)
				break;
			
			if(dist[gap.se] == INF)
			{
				dist[gap.se] = dist[qq.se] + b[gap.se].C;
				pq.push({-dist[gap.se], gap.se});
			}
			
			if(P[a[gap.se].C] >= (ll)vec[a[gap.se].C].size())
				segt.update(1, 1, siz, a[gap.se].C, INF, -1);
			
			else
			{
				segt.update(1, 1, siz, a[gap.se].C, vec[a[gap.se].C][P[a[gap.se].C]].fi, vec[a[gap.se].C][P[a[gap.se].C]].se);
				P[a[gap.se].C]++;
			}
		}
	}
	
	for(ll i = 1 ; i <= m ; i++)
	{
		if(b[i].R == n)
			ans = min(ans, dist[i]);
	}
	
	if(ans == INF)
		cout << -1;
	else
		cout << ans;
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 45752 KB Output is correct
2 Correct 209 ms 45632 KB Output is correct
3 Correct 168 ms 38216 KB Output is correct
4 Correct 167 ms 38324 KB Output is correct
5 Correct 138 ms 38584 KB Output is correct
6 Correct 168 ms 36488 KB Output is correct
7 Correct 159 ms 38104 KB Output is correct
8 Correct 116 ms 34936 KB Output is correct
9 Correct 130 ms 35420 KB Output is correct
10 Correct 138 ms 38312 KB Output is correct
11 Correct 262 ms 58768 KB Output is correct
12 Correct 270 ms 58684 KB Output is correct
13 Correct 308 ms 58272 KB Output is correct
14 Correct 294 ms 58296 KB Output is correct
15 Correct 284 ms 55692 KB Output is correct
16 Correct 277 ms 55156 KB Output is correct
17 Correct 263 ms 55084 KB Output is correct
18 Correct 251 ms 58552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20828 KB Output is correct
2 Correct 3 ms 20828 KB Output is correct
3 Correct 4 ms 20828 KB Output is correct
4 Correct 4 ms 20828 KB Output is correct
5 Correct 4 ms 20828 KB Output is correct
6 Correct 4 ms 20828 KB Output is correct
7 Correct 4 ms 20828 KB Output is correct
8 Correct 4 ms 21084 KB Output is correct
9 Correct 3 ms 20828 KB Output is correct
10 Correct 4 ms 20828 KB Output is correct
11 Correct 4 ms 20828 KB Output is correct
12 Correct 3 ms 20956 KB Output is correct
13 Correct 4 ms 20828 KB Output is correct
14 Correct 4 ms 20828 KB Output is correct
15 Correct 4 ms 21084 KB Output is correct
16 Correct 4 ms 20828 KB Output is correct
17 Correct 5 ms 20828 KB Output is correct
18 Correct 4 ms 20956 KB Output is correct
19 Correct 4 ms 20960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20828 KB Output is correct
2 Correct 3 ms 20828 KB Output is correct
3 Correct 4 ms 20828 KB Output is correct
4 Correct 4 ms 20828 KB Output is correct
5 Correct 4 ms 20828 KB Output is correct
6 Correct 4 ms 20828 KB Output is correct
7 Correct 4 ms 20828 KB Output is correct
8 Correct 4 ms 21084 KB Output is correct
9 Correct 3 ms 20828 KB Output is correct
10 Correct 4 ms 20828 KB Output is correct
11 Correct 4 ms 20828 KB Output is correct
12 Correct 3 ms 20956 KB Output is correct
13 Correct 4 ms 20828 KB Output is correct
14 Correct 4 ms 20828 KB Output is correct
15 Correct 4 ms 21084 KB Output is correct
16 Correct 4 ms 20828 KB Output is correct
17 Correct 5 ms 20828 KB Output is correct
18 Correct 4 ms 20956 KB Output is correct
19 Correct 4 ms 20960 KB Output is correct
20 Correct 13 ms 23512 KB Output is correct
21 Correct 13 ms 23508 KB Output is correct
22 Correct 16 ms 23708 KB Output is correct
23 Correct 15 ms 23512 KB Output is correct
24 Correct 16 ms 23748 KB Output is correct
25 Correct 16 ms 23632 KB Output is correct
26 Correct 15 ms 23512 KB Output is correct
27 Correct 14 ms 23512 KB Output is correct
28 Correct 16 ms 23580 KB Output is correct
29 Correct 18 ms 23512 KB Output is correct
30 Correct 14 ms 23512 KB Output is correct
31 Correct 13 ms 23512 KB Output is correct
32 Correct 17 ms 23768 KB Output is correct
33 Correct 16 ms 23648 KB Output is correct
34 Correct 16 ms 23512 KB Output is correct
35 Correct 16 ms 23720 KB Output is correct
36 Correct 17 ms 23768 KB Output is correct
37 Correct 15 ms 23512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 45752 KB Output is correct
2 Correct 209 ms 45632 KB Output is correct
3 Correct 168 ms 38216 KB Output is correct
4 Correct 167 ms 38324 KB Output is correct
5 Correct 138 ms 38584 KB Output is correct
6 Correct 168 ms 36488 KB Output is correct
7 Correct 159 ms 38104 KB Output is correct
8 Correct 116 ms 34936 KB Output is correct
9 Correct 130 ms 35420 KB Output is correct
10 Correct 138 ms 38312 KB Output is correct
11 Correct 262 ms 58768 KB Output is correct
12 Correct 270 ms 58684 KB Output is correct
13 Correct 308 ms 58272 KB Output is correct
14 Correct 294 ms 58296 KB Output is correct
15 Correct 284 ms 55692 KB Output is correct
16 Correct 277 ms 55156 KB Output is correct
17 Correct 263 ms 55084 KB Output is correct
18 Correct 251 ms 58552 KB Output is correct
19 Correct 4 ms 20828 KB Output is correct
20 Correct 3 ms 20828 KB Output is correct
21 Correct 4 ms 20828 KB Output is correct
22 Correct 4 ms 20828 KB Output is correct
23 Correct 4 ms 20828 KB Output is correct
24 Correct 4 ms 20828 KB Output is correct
25 Correct 4 ms 20828 KB Output is correct
26 Correct 4 ms 21084 KB Output is correct
27 Correct 3 ms 20828 KB Output is correct
28 Correct 4 ms 20828 KB Output is correct
29 Correct 4 ms 20828 KB Output is correct
30 Correct 3 ms 20956 KB Output is correct
31 Correct 4 ms 20828 KB Output is correct
32 Correct 4 ms 20828 KB Output is correct
33 Correct 4 ms 21084 KB Output is correct
34 Correct 4 ms 20828 KB Output is correct
35 Correct 5 ms 20828 KB Output is correct
36 Correct 4 ms 20956 KB Output is correct
37 Correct 4 ms 20960 KB Output is correct
38 Correct 13 ms 23512 KB Output is correct
39 Correct 13 ms 23508 KB Output is correct
40 Correct 16 ms 23708 KB Output is correct
41 Correct 15 ms 23512 KB Output is correct
42 Correct 16 ms 23748 KB Output is correct
43 Correct 16 ms 23632 KB Output is correct
44 Correct 15 ms 23512 KB Output is correct
45 Correct 14 ms 23512 KB Output is correct
46 Correct 16 ms 23580 KB Output is correct
47 Correct 18 ms 23512 KB Output is correct
48 Correct 14 ms 23512 KB Output is correct
49 Correct 13 ms 23512 KB Output is correct
50 Correct 17 ms 23768 KB Output is correct
51 Correct 16 ms 23648 KB Output is correct
52 Correct 16 ms 23512 KB Output is correct
53 Correct 16 ms 23720 KB Output is correct
54 Correct 17 ms 23768 KB Output is correct
55 Correct 15 ms 23512 KB Output is correct
56 Correct 236 ms 44984 KB Output is correct
57 Correct 252 ms 45084 KB Output is correct
58 Correct 219 ms 43960 KB Output is correct
59 Correct 229 ms 44816 KB Output is correct
60 Correct 265 ms 53228 KB Output is correct
61 Correct 227 ms 44736 KB Output is correct
62 Correct 227 ms 44852 KB Output is correct
63 Correct 250 ms 53428 KB Output is correct
64 Correct 243 ms 53156 KB Output is correct
65 Correct 242 ms 47032 KB Output is correct
66 Correct 257 ms 54044 KB Output is correct
67 Correct 288 ms 56012 KB Output is correct
68 Correct 271 ms 56656 KB Output is correct
69 Correct 247 ms 53752 KB Output is correct
70 Correct 290 ms 55988 KB Output is correct
71 Correct 269 ms 56684 KB Output is correct
72 Correct 241 ms 53652 KB Output is correct
73 Correct 302 ms 56760 KB Output is correct
74 Correct 227 ms 55996 KB Output is correct
75 Correct 205 ms 55732 KB Output is correct
76 Correct 305 ms 59060 KB Output is correct
77 Correct 385 ms 60188 KB Output is correct
78 Correct 331 ms 58904 KB Output is correct
79 Correct 330 ms 55912 KB Output is correct
80 Correct 302 ms 55684 KB Output is correct
81 Correct 252 ms 56248 KB Output is correct
82 Correct 286 ms 54712 KB Output is correct
83 Correct 306 ms 55176 KB Output is correct
84 Correct 309 ms 55108 KB Output is correct
85 Correct 286 ms 56756 KB Output is correct
86 Correct 270 ms 55764 KB Output is correct
87 Correct 320 ms 56248 KB Output is correct
88 Correct 278 ms 53736 KB Output is correct
89 Correct 273 ms 55736 KB Output is correct
90 Correct 342 ms 59440 KB Output is correct
91 Correct 314 ms 58036 KB Output is correct
92 Correct 296 ms 56316 KB Output is correct
93 Correct 324 ms 55728 KB Output is correct
94 Correct 291 ms 55480 KB Output is correct
95 Correct 317 ms 55732 KB Output is correct
96 Correct 331 ms 60596 KB Output is correct
97 Correct 336 ms 59572 KB Output is correct
98 Correct 343 ms 59572 KB Output is correct
99 Correct 336 ms 60384 KB Output is correct
100 Correct 298 ms 56504 KB Output is correct
101 Correct 380 ms 60204 KB Output is correct
102 Correct 329 ms 57232 KB Output is correct
103 Correct 286 ms 56656 KB Output is correct