Submission #863175

# Submission time Handle Problem Language Result Execution time Memory
863175 2023-10-19T17:53:33 Z denniskim Overtaking (IOI23_overtaking) C++17
100 / 100
2518 ms 153260 KB
#include "overtaking.h"
#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())

ll n, m, x;
ll LL;
ll w[2010];
ll S[2010][2010];
ll spd[2010];
ll siz;
vector<pll> qry;
vector<ll> zip;
ll won[8000010];

struct lazysegtree
{
	ll lazy[8000010];
	ll seg[8000010];
	
	void prop(ll no, ll s, ll e)
	{
		if(!lazy[no])
			return;
		
		seg[no] = max(seg[no], lazy[no]);
		
		if(s != e)
		{
			lazy[no << 1] = max(lazy[no << 1], lazy[no]);
			lazy[no << 1 | 1] = max(lazy[no << 1 | 1], lazy[no]);
		}
		
		lazy[no] = 0;
	}
	
	void update(ll no, ll s, ll e, ll l, ll r, ll v)
	{
		prop(no, s, e);
		
		if(e < l || r < s)
			return;
		
		if(l <= s && e <= r)
		{
			seg[no] = max(seg[no], v);
			
			if(s != e)
			{
				lazy[no << 1] = max(lazy[no << 1], v);
				lazy[no << 1 | 1] = max(lazy[no << 1 | 1], v);
			}
			
			return;
		}
		
		update(no << 1, s, (s + e) >> 1, l, r, v);
		update(no << 1 | 1, ((s + e) >> 1) + 1, e, l, r, v);
		
		seg[no] = max(seg[no << 1], seg[no << 1 | 1]);
	}
	
	ll query(ll no, ll s, ll e, ll l, ll r)
	{
		prop(no, s, e);
		
		if(e < l || r < s)
			return -INF;
		
		if(l <= s && e <= r)
			return seg[no];
		
		return max(query(no << 1, s, (s + e) >> 1, l, r), query(no << 1 | 1, ((s + e) >> 1) + 1, e, l, r));
	}
}segt;

ll num(ll X)
{
	return lower_bound(zip.begin(), zip.end(), X) - zip.begin() + 1;
}

void init(int L, int N, vector<ll> T, vector<int> W, int X, int M, vector<int> SS)
{
	x = X, LL = L;
	
	for(ll i = 0 ; i < N ; i++)
	{
		if(W[i] <= X)
			continue;
		
		spd[++n] = W[i] - X;
		S[1][n] = T[i];
	}
	
	for(ll i = 0 ; i < M ; i++)
		w[++m] = SS[i];
	
	for(ll i = 1 ; i < m ; i++)
	{
		vector< pair<pll, ll> > vv;
		
		for(ll j = 1 ; j <= n ; j++)
			vv.push_back({{S[i][j], spd[j]}, j});
		
		sort(vv.begin(), vv.end());
		
		ll maxx = 0;
		ll dist = w[i + 1] - w[i];
		
		for(auto &j : vv)
		{
			S[i + 1][j.se] = max(S[i][j.se] + dist * spd[j.se], maxx);
			maxx = max(maxx, S[i + 1][j.se]);
		}
	}
	
	for(ll i = 1 ; i < m ; i++)
	{
		vector<pll> vv;
		
		for(ll j = 1 ; j <= n ; j++)
			vv.push_back({S[i][j], S[i + 1][j]});
		
		sort(vv.begin(), vv.end());
		reverse(vv.begin(), vv.end());
		
		for(ll j = 0 ; j < n ; j++)
			qry.push_back(vv[j]);
	}
	
	for(auto &i : qry)
	{
		zip.push_back(i.fi + 1);
		zip.push_back(i.se);
	}
	
	zip.push_back(0);
	compress(zip);
	
	siz = (ll)zip.size();
	
	for(auto &i : zip)
		segt.update(1, 1, siz, num(i), num(i), i);
	
	for(ll i = (ll)qry.size() - 1 ; i >= 0 ; i--)
	{
		ll gap = segt.query(1, 1, siz, num(qry[i].se), num(qry[i].se));
		segt.update(1, 1, siz, num(qry[i].fi + 1), num(qry[i].se), gap);
	}
}

ll arrival_time(ll Y)
{
	ll idx = upper_bound(zip.begin(), zip.end(), Y) - zip.begin();
	ll gap = segt.query(1, 1, siz, idx, idx);
	
	if(gap == zip[idx - 1])
		return Y + x * LL;
	
	return gap + x * LL;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 19036 KB Output is correct
9 Correct 3 ms 19036 KB Output is correct
10 Correct 3 ms 18920 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 2648 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 14 ms 5976 KB Output is correct
10 Correct 11 ms 5976 KB Output is correct
11 Correct 11 ms 5976 KB Output is correct
12 Correct 11 ms 5976 KB Output is correct
13 Correct 11 ms 5780 KB Output is correct
14 Correct 11 ms 5976 KB Output is correct
15 Correct 12 ms 6176 KB Output is correct
16 Correct 11 ms 5972 KB Output is correct
17 Correct 11 ms 5976 KB Output is correct
18 Correct 11 ms 5976 KB Output is correct
19 Correct 14 ms 5976 KB Output is correct
20 Correct 13 ms 5972 KB Output is correct
21 Correct 6 ms 5212 KB Output is correct
22 Correct 6 ms 3164 KB Output is correct
23 Correct 4 ms 4956 KB Output is correct
24 Correct 9 ms 5356 KB Output is correct
25 Correct 9 ms 5212 KB Output is correct
26 Correct 9 ms 5212 KB Output is correct
27 Correct 9 ms 5320 KB Output is correct
28 Correct 7 ms 3164 KB Output is correct
29 Correct 7 ms 3164 KB Output is correct
30 Correct 7 ms 3164 KB Output is correct
31 Correct 7 ms 3164 KB Output is correct
32 Correct 8 ms 5460 KB Output is correct
33 Correct 10 ms 5916 KB Output is correct
34 Correct 11 ms 5916 KB Output is correct
35 Correct 12 ms 5916 KB Output is correct
36 Correct 11 ms 5720 KB Output is correct
37 Correct 11 ms 5720 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 7 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 19036 KB Output is correct
10 Correct 3 ms 19036 KB Output is correct
11 Correct 3 ms 18920 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 14 ms 5976 KB Output is correct
17 Correct 11 ms 5976 KB Output is correct
18 Correct 11 ms 5976 KB Output is correct
19 Correct 11 ms 5976 KB Output is correct
20 Correct 11 ms 5780 KB Output is correct
21 Correct 11 ms 5976 KB Output is correct
22 Correct 12 ms 6176 KB Output is correct
23 Correct 11 ms 5972 KB Output is correct
24 Correct 11 ms 5976 KB Output is correct
25 Correct 11 ms 5976 KB Output is correct
26 Correct 14 ms 5976 KB Output is correct
27 Correct 13 ms 5972 KB Output is correct
28 Correct 6 ms 5212 KB Output is correct
29 Correct 6 ms 3164 KB Output is correct
30 Correct 4 ms 4956 KB Output is correct
31 Correct 9 ms 5356 KB Output is correct
32 Correct 9 ms 5212 KB Output is correct
33 Correct 9 ms 5212 KB Output is correct
34 Correct 9 ms 5320 KB Output is correct
35 Correct 7 ms 3164 KB Output is correct
36 Correct 7 ms 3164 KB Output is correct
37 Correct 7 ms 3164 KB Output is correct
38 Correct 7 ms 3164 KB Output is correct
39 Correct 8 ms 5460 KB Output is correct
40 Correct 10 ms 5916 KB Output is correct
41 Correct 11 ms 5916 KB Output is correct
42 Correct 12 ms 5916 KB Output is correct
43 Correct 11 ms 5720 KB Output is correct
44 Correct 11 ms 5720 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 7 ms 5208 KB Output is correct
48 Correct 1832 ms 117664 KB Output is correct
49 Correct 1720 ms 117008 KB Output is correct
50 Correct 1749 ms 117488 KB Output is correct
51 Correct 1703 ms 117220 KB Output is correct
52 Correct 1860 ms 117188 KB Output is correct
53 Correct 1800 ms 116832 KB Output is correct
54 Correct 1724 ms 116868 KB Output is correct
55 Correct 1362 ms 116904 KB Output is correct
56 Correct 1568 ms 116908 KB Output is correct
57 Correct 1493 ms 116956 KB Output is correct
58 Correct 1560 ms 116976 KB Output is correct
59 Correct 1646 ms 116768 KB Output is correct
60 Correct 1667 ms 116988 KB Output is correct
61 Correct 1594 ms 116724 KB Output is correct
62 Correct 5 ms 19032 KB Output is correct
63 Correct 3 ms 2652 KB Output is correct
64 Correct 826 ms 68460 KB Output is correct
65 Correct 871 ms 60664 KB Output is correct
66 Correct 570 ms 59256 KB Output is correct
67 Correct 1913 ms 117148 KB Output is correct
68 Correct 1979 ms 116844 KB Output is correct
69 Correct 1090 ms 67836 KB Output is correct
70 Correct 1354 ms 100624 KB Output is correct
71 Correct 1483 ms 100768 KB Output is correct
72 Correct 1476 ms 109576 KB Output is correct
73 Correct 1449 ms 100792 KB Output is correct
74 Correct 1471 ms 100604 KB Output is correct
75 Correct 2 ms 2652 KB Output is correct
76 Correct 2 ms 2548 KB Output is correct
77 Correct 2 ms 2652 KB Output is correct
78 Correct 999 ms 63628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 19036 KB Output is correct
10 Correct 3 ms 19036 KB Output is correct
11 Correct 3 ms 18920 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2648 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 14 ms 5976 KB Output is correct
28 Correct 11 ms 5976 KB Output is correct
29 Correct 11 ms 5976 KB Output is correct
30 Correct 11 ms 5976 KB Output is correct
31 Correct 11 ms 5780 KB Output is correct
32 Correct 11 ms 5976 KB Output is correct
33 Correct 12 ms 6176 KB Output is correct
34 Correct 11 ms 5972 KB Output is correct
35 Correct 11 ms 5976 KB Output is correct
36 Correct 11 ms 5976 KB Output is correct
37 Correct 14 ms 5976 KB Output is correct
38 Correct 13 ms 5972 KB Output is correct
39 Correct 6 ms 5212 KB Output is correct
40 Correct 6 ms 3164 KB Output is correct
41 Correct 4 ms 4956 KB Output is correct
42 Correct 9 ms 5356 KB Output is correct
43 Correct 9 ms 5212 KB Output is correct
44 Correct 9 ms 5212 KB Output is correct
45 Correct 9 ms 5320 KB Output is correct
46 Correct 7 ms 3164 KB Output is correct
47 Correct 7 ms 3164 KB Output is correct
48 Correct 7 ms 3164 KB Output is correct
49 Correct 7 ms 3164 KB Output is correct
50 Correct 8 ms 5460 KB Output is correct
51 Correct 10 ms 5916 KB Output is correct
52 Correct 11 ms 5916 KB Output is correct
53 Correct 12 ms 5916 KB Output is correct
54 Correct 11 ms 5720 KB Output is correct
55 Correct 11 ms 5720 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 7 ms 5208 KB Output is correct
59 Correct 1832 ms 117664 KB Output is correct
60 Correct 1720 ms 117008 KB Output is correct
61 Correct 1749 ms 117488 KB Output is correct
62 Correct 1703 ms 117220 KB Output is correct
63 Correct 1860 ms 117188 KB Output is correct
64 Correct 1800 ms 116832 KB Output is correct
65 Correct 1724 ms 116868 KB Output is correct
66 Correct 1362 ms 116904 KB Output is correct
67 Correct 1568 ms 116908 KB Output is correct
68 Correct 1493 ms 116956 KB Output is correct
69 Correct 1560 ms 116976 KB Output is correct
70 Correct 1646 ms 116768 KB Output is correct
71 Correct 1667 ms 116988 KB Output is correct
72 Correct 1594 ms 116724 KB Output is correct
73 Correct 5 ms 19032 KB Output is correct
74 Correct 3 ms 2652 KB Output is correct
75 Correct 826 ms 68460 KB Output is correct
76 Correct 871 ms 60664 KB Output is correct
77 Correct 570 ms 59256 KB Output is correct
78 Correct 1913 ms 117148 KB Output is correct
79 Correct 1979 ms 116844 KB Output is correct
80 Correct 1090 ms 67836 KB Output is correct
81 Correct 1354 ms 100624 KB Output is correct
82 Correct 1483 ms 100768 KB Output is correct
83 Correct 1476 ms 109576 KB Output is correct
84 Correct 1449 ms 100792 KB Output is correct
85 Correct 1471 ms 100604 KB Output is correct
86 Correct 2 ms 2652 KB Output is correct
87 Correct 2 ms 2548 KB Output is correct
88 Correct 2 ms 2652 KB Output is correct
89 Correct 999 ms 63628 KB Output is correct
90 Correct 2012 ms 120060 KB Output is correct
91 Correct 2241 ms 146292 KB Output is correct
92 Correct 2416 ms 145656 KB Output is correct
93 Correct 2322 ms 146032 KB Output is correct
94 Correct 2329 ms 146176 KB Output is correct
95 Correct 2310 ms 146260 KB Output is correct
96 Correct 2272 ms 146284 KB Output is correct
97 Correct 1558 ms 119640 KB Output is correct
98 Correct 2193 ms 145712 KB Output is correct
99 Correct 2104 ms 147320 KB Output is correct
100 Correct 2115 ms 146216 KB Output is correct
101 Correct 2140 ms 146008 KB Output is correct
102 Correct 2070 ms 147192 KB Output is correct
103 Correct 2107 ms 147224 KB Output is correct
104 Correct 1312 ms 97376 KB Output is correct
105 Correct 1493 ms 91920 KB Output is correct
106 Correct 937 ms 86304 KB Output is correct
107 Correct 2393 ms 152572 KB Output is correct
108 Correct 2465 ms 152400 KB Output is correct
109 Correct 2485 ms 152092 KB Output is correct
110 Correct 2518 ms 153260 KB Output is correct
111 Correct 1497 ms 97560 KB Output is correct
112 Correct 1938 ms 131440 KB Output is correct
113 Correct 2051 ms 131368 KB Output is correct
114 Correct 2254 ms 145508 KB Output is correct
115 Correct 1971 ms 131044 KB Output is correct
116 Correct 1901 ms 131676 KB Output is correct
117 Correct 174 ms 35332 KB Output is correct
118 Correct 185 ms 35344 KB Output is correct
119 Correct 168 ms 33620 KB Output is correct
120 Correct 183 ms 35344 KB Output is correct
121 Correct 179 ms 36432 KB Output is correct
122 Correct 1383 ms 88024 KB Output is correct
123 Correct 2248 ms 141488 KB Output is correct
124 Correct 2325 ms 142556 KB Output is correct
125 Correct 2385 ms 142812 KB Output is correct