Submission #863185

# Submission time Handle Problem Language Result Execution time Memory
863185 2023-10-19T18:02:57 Z denniskim Overtaking (IOI23_overtaking) C++17
100 / 100
1744 ms 163460 KB
#pragma GCC optimize ("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#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, NN;
vector<ll> zip;
ll won[8000010];

struct lazysegtree
{
	ll lazy[8000010];
	ll seg[8000010];
	
	void init(ll no, ll s, ll e)
	{
		if(s == e)
		{
			seg[no] = zip[s - 1];
			return;
		}
		
		init(no << 1, s, (s + e) >> 1);
		init(no << 1 | 1, ((s + e) >> 1) + 1, e);
		
		seg[no] = max(seg[no << 1], seg[no << 1 | 1]);
	}
	
	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);
	
	for(auto &i : qry)
		NN.push_back({num(i.fi + 1), num(i.se)});
	
	siz = (ll)zip.size();
	
	segt.init(1, 1, siz);
	
	for(ll i = (ll)qry.size() - 1 ; i >= 0 ; i--)
	{
		ll gap = segt.query(1, 1, siz, NN[i].se, NN[i].se);
		segt.update(1, 1, siz, NN[i].fi, NN[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 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 3 ms 16732 KB Output is correct
8 Correct 3 ms 20828 KB Output is correct
9 Correct 3 ms 21080 KB Output is correct
10 Correct 3 ms 21084 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 7 ms 7640 KB Output is correct
10 Correct 7 ms 7640 KB Output is correct
11 Correct 7 ms 7640 KB Output is correct
12 Correct 7 ms 7728 KB Output is correct
13 Correct 7 ms 7636 KB Output is correct
14 Correct 8 ms 7648 KB Output is correct
15 Correct 7 ms 7640 KB Output is correct
16 Correct 7 ms 7724 KB Output is correct
17 Correct 7 ms 7640 KB Output is correct
18 Correct 7 ms 7636 KB Output is correct
19 Correct 7 ms 7636 KB Output is correct
20 Correct 7 ms 7640 KB Output is correct
21 Correct 4 ms 7232 KB Output is correct
22 Correct 4 ms 4956 KB Output is correct
23 Correct 4 ms 7004 KB Output is correct
24 Correct 8 ms 7260 KB Output is correct
25 Correct 6 ms 7260 KB Output is correct
26 Correct 6 ms 7260 KB Output is correct
27 Correct 6 ms 7376 KB Output is correct
28 Correct 5 ms 5212 KB Output is correct
29 Correct 5 ms 5212 KB Output is correct
30 Correct 5 ms 5240 KB Output is correct
31 Correct 5 ms 5048 KB Output is correct
32 Correct 6 ms 7128 KB Output is correct
33 Correct 7 ms 7384 KB Output is correct
34 Correct 6 ms 7452 KB Output is correct
35 Correct 7 ms 7384 KB Output is correct
36 Correct 7 ms 7384 KB Output is correct
37 Correct 7 ms 7384 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 6 ms 7128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 3 ms 20828 KB Output is correct
10 Correct 3 ms 21080 KB Output is correct
11 Correct 3 ms 21084 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 7 ms 7640 KB Output is correct
17 Correct 7 ms 7640 KB Output is correct
18 Correct 7 ms 7640 KB Output is correct
19 Correct 7 ms 7728 KB Output is correct
20 Correct 7 ms 7636 KB Output is correct
21 Correct 8 ms 7648 KB Output is correct
22 Correct 7 ms 7640 KB Output is correct
23 Correct 7 ms 7724 KB Output is correct
24 Correct 7 ms 7640 KB Output is correct
25 Correct 7 ms 7636 KB Output is correct
26 Correct 7 ms 7636 KB Output is correct
27 Correct 7 ms 7640 KB Output is correct
28 Correct 4 ms 7232 KB Output is correct
29 Correct 4 ms 4956 KB Output is correct
30 Correct 4 ms 7004 KB Output is correct
31 Correct 8 ms 7260 KB Output is correct
32 Correct 6 ms 7260 KB Output is correct
33 Correct 6 ms 7260 KB Output is correct
34 Correct 6 ms 7376 KB Output is correct
35 Correct 5 ms 5212 KB Output is correct
36 Correct 5 ms 5212 KB Output is correct
37 Correct 5 ms 5240 KB Output is correct
38 Correct 5 ms 5048 KB Output is correct
39 Correct 6 ms 7128 KB Output is correct
40 Correct 7 ms 7384 KB Output is correct
41 Correct 6 ms 7452 KB Output is correct
42 Correct 7 ms 7384 KB Output is correct
43 Correct 7 ms 7384 KB Output is correct
44 Correct 7 ms 7384 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 6 ms 7128 KB Output is correct
48 Correct 1128 ms 133744 KB Output is correct
49 Correct 1057 ms 133764 KB Output is correct
50 Correct 1047 ms 133656 KB Output is correct
51 Correct 1038 ms 133884 KB Output is correct
52 Correct 1053 ms 134800 KB Output is correct
53 Correct 1034 ms 133792 KB Output is correct
54 Correct 1042 ms 135240 KB Output is correct
55 Correct 945 ms 135068 KB Output is correct
56 Correct 939 ms 133712 KB Output is correct
57 Correct 929 ms 135848 KB Output is correct
58 Correct 947 ms 133992 KB Output is correct
59 Correct 971 ms 133708 KB Output is correct
60 Correct 936 ms 135736 KB Output is correct
61 Correct 947 ms 135540 KB Output is correct
62 Correct 5 ms 21084 KB Output is correct
63 Correct 3 ms 4700 KB Output is correct
64 Correct 539 ms 77472 KB Output is correct
65 Correct 538 ms 69588 KB Output is correct
66 Correct 523 ms 78292 KB Output is correct
67 Correct 1139 ms 135820 KB Output is correct
68 Correct 1131 ms 134024 KB Output is correct
69 Correct 756 ms 84528 KB Output is correct
70 Correct 830 ms 118996 KB Output is correct
71 Correct 852 ms 117400 KB Output is correct
72 Correct 858 ms 127620 KB Output is correct
73 Correct 859 ms 117368 KB Output is correct
74 Correct 848 ms 117244 KB Output is correct
75 Correct 2 ms 4696 KB Output is correct
76 Correct 2 ms 4700 KB Output is correct
77 Correct 2 ms 4700 KB Output is correct
78 Correct 747 ms 80232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 3 ms 20828 KB Output is correct
10 Correct 3 ms 21080 KB Output is correct
11 Correct 3 ms 21084 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 2 ms 4440 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4528 KB Output is correct
27 Correct 7 ms 7640 KB Output is correct
28 Correct 7 ms 7640 KB Output is correct
29 Correct 7 ms 7640 KB Output is correct
30 Correct 7 ms 7728 KB Output is correct
31 Correct 7 ms 7636 KB Output is correct
32 Correct 8 ms 7648 KB Output is correct
33 Correct 7 ms 7640 KB Output is correct
34 Correct 7 ms 7724 KB Output is correct
35 Correct 7 ms 7640 KB Output is correct
36 Correct 7 ms 7636 KB Output is correct
37 Correct 7 ms 7636 KB Output is correct
38 Correct 7 ms 7640 KB Output is correct
39 Correct 4 ms 7232 KB Output is correct
40 Correct 4 ms 4956 KB Output is correct
41 Correct 4 ms 7004 KB Output is correct
42 Correct 8 ms 7260 KB Output is correct
43 Correct 6 ms 7260 KB Output is correct
44 Correct 6 ms 7260 KB Output is correct
45 Correct 6 ms 7376 KB Output is correct
46 Correct 5 ms 5212 KB Output is correct
47 Correct 5 ms 5212 KB Output is correct
48 Correct 5 ms 5240 KB Output is correct
49 Correct 5 ms 5048 KB Output is correct
50 Correct 6 ms 7128 KB Output is correct
51 Correct 7 ms 7384 KB Output is correct
52 Correct 6 ms 7452 KB Output is correct
53 Correct 7 ms 7384 KB Output is correct
54 Correct 7 ms 7384 KB Output is correct
55 Correct 7 ms 7384 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 6 ms 7128 KB Output is correct
59 Correct 1128 ms 133744 KB Output is correct
60 Correct 1057 ms 133764 KB Output is correct
61 Correct 1047 ms 133656 KB Output is correct
62 Correct 1038 ms 133884 KB Output is correct
63 Correct 1053 ms 134800 KB Output is correct
64 Correct 1034 ms 133792 KB Output is correct
65 Correct 1042 ms 135240 KB Output is correct
66 Correct 945 ms 135068 KB Output is correct
67 Correct 939 ms 133712 KB Output is correct
68 Correct 929 ms 135848 KB Output is correct
69 Correct 947 ms 133992 KB Output is correct
70 Correct 971 ms 133708 KB Output is correct
71 Correct 936 ms 135736 KB Output is correct
72 Correct 947 ms 135540 KB Output is correct
73 Correct 5 ms 21084 KB Output is correct
74 Correct 3 ms 4700 KB Output is correct
75 Correct 539 ms 77472 KB Output is correct
76 Correct 538 ms 69588 KB Output is correct
77 Correct 523 ms 78292 KB Output is correct
78 Correct 1139 ms 135820 KB Output is correct
79 Correct 1131 ms 134024 KB Output is correct
80 Correct 756 ms 84528 KB Output is correct
81 Correct 830 ms 118996 KB Output is correct
82 Correct 852 ms 117400 KB Output is correct
83 Correct 858 ms 127620 KB Output is correct
84 Correct 859 ms 117368 KB Output is correct
85 Correct 848 ms 117244 KB Output is correct
86 Correct 2 ms 4696 KB Output is correct
87 Correct 2 ms 4700 KB Output is correct
88 Correct 2 ms 4700 KB Output is correct
89 Correct 747 ms 80232 KB Output is correct
90 Correct 1202 ms 136012 KB Output is correct
91 Correct 1477 ms 160740 KB Output is correct
92 Correct 1506 ms 158760 KB Output is correct
93 Correct 1471 ms 159104 KB Output is correct
94 Correct 1498 ms 158856 KB Output is correct
95 Correct 1518 ms 160060 KB Output is correct
96 Correct 1462 ms 158860 KB Output is correct
97 Correct 1030 ms 138088 KB Output is correct
98 Correct 1418 ms 158664 KB Output is correct
99 Correct 1407 ms 160144 KB Output is correct
100 Correct 1431 ms 159004 KB Output is correct
101 Correct 1442 ms 158604 KB Output is correct
102 Correct 1417 ms 158868 KB Output is correct
103 Correct 1429 ms 160488 KB Output is correct
104 Correct 994 ms 102024 KB Output is correct
105 Correct 1096 ms 95896 KB Output is correct
106 Correct 888 ms 99208 KB Output is correct
107 Correct 1661 ms 163112 KB Output is correct
108 Correct 1740 ms 163264 KB Output is correct
109 Correct 1726 ms 163460 KB Output is correct
110 Correct 1744 ms 163224 KB Output is correct
111 Correct 1171 ms 109840 KB Output is correct
112 Correct 1330 ms 143132 KB Output is correct
113 Correct 1409 ms 145812 KB Output is correct
114 Correct 1564 ms 157828 KB Output is correct
115 Correct 1380 ms 143800 KB Output is correct
116 Correct 1296 ms 143652 KB Output is correct
117 Correct 183 ms 32084 KB Output is correct
118 Correct 174 ms 32084 KB Output is correct
119 Correct 170 ms 31060 KB Output is correct
120 Correct 174 ms 32080 KB Output is correct
121 Correct 175 ms 33108 KB Output is correct
122 Correct 1145 ms 102984 KB Output is correct
123 Correct 1609 ms 157832 KB Output is correct
124 Correct 1639 ms 161128 KB Output is correct
125 Correct 1650 ms 159004 KB Output is correct