Submission #763012

# Submission time Handle Problem Language Result Execution time Memory
763012 2023-06-22T02:24:46 Z tpd2k Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
221 ms 12580 KB
// teddybear's code
// the one who loves NBP
// noe the second
// goal: 0 / 8
// get medal in APIO (like TKN)
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

// prob: 
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#define FOR(i,n) for (int i = 0; i<n; i++)
using ll = long long;
using ull = unsigned long long;
ll n,m,t;
ll cnt = 0;
const int maxn = 1e5;
const ll mod = 1e6;
#define Y "YES"
#define N "NO"

bool visited[1005][1005];
int dist[1005][1005];
int w,h;
int fx[4] = {-1, 1, 0, 0};
int fy[4] = {0, 0, -1, 1};
queue <pair<int,int>> q;

ll b[mod];
pair<ll,ll> a[mod];

ll st[4 * mod + 5];
ll ans[4 * mod + 5];

void build (int id, int l, int r)
{
	if (l == r)
	{
		st[id] = max(0LL, a[l+1].first - b[l]);
		return;
	}
	
	int m = (l + r) / 2;
	build(id*2,l,m);
	build(id*2+1, m+1, r);
	
	st[id] = max(st[id*2], st[id*2+1]);
} 

void update(int id, int l, int r, int lq, int rq, int val)
{
	if (l > rq || r < lq)
	{
		return;
	}
	
	if (l >= lq && r <= rq)
	{
		//cout << "!!" << ' ' << l << ' ' << r << ' ' << val << ' ' << b[l] << '\n';
		st[id] = max(0LL, val - b[l]);
		return;
	}
	
	int m = (l + r) / 2;
	update(id*2,l,m,lq,rq,val);
	update(id*2+1,m+1,r,lq,rq,val);
	
	st[id] = max(st[id*2], st[id*2+1]);
	
}

void solve()
{
	cin >> n;
	for (int i = 1; i<=n+1; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	for (int i = 1; i<=n; i++)
	{
		cin >> b[i];
	}
	
	sort(a+1,a+n+2);
	sort(b+1,b+n+1);
	
	/*for (int i = 1; i<=n+1; i++)
	{
		cout << a[i].first << ' ' << a[i].second << '\n';
	}*/
	
	build(1,1,n);
	
	ans[a[1].second] = st[1];
	
 	/*for (int i = 1; i<=2*n; i++)
	{
		cout << "! " << i << ' ' << st[i] << '\n';
	}
	
	return;*/
	
	for (int i = 2; i<=n+1; i++)
	{
		//cout << a[i].first << '\n';
		update(1,1,n,i-1,i-1,a[i-1].first);
		//cout << st[1] << '\n';
		/*for (int j = 1; j<=2*n; j++)
		{
			cout << "! " << j << ' ' << st[j] << '\n';
		}*/
		ans[a[i].second] = st[1];
	}
	
	for (int i = 1; i<=n+1; i++)
	{
		cout << ans[i] << ' ';
	}
	
	
	
}

/*
3
4 3 7 6
2 6 4

*/

void init()
{
 	int te = 1; 
 	while (te--)
 	{
 	 	  solve();
 	}
}

void preprocess()
{

}


int main()
{
 	//ios_base::sync_with_stdio(false);
 	//cin.tie(NULL);
    //cin.tie(0); cout.tie(0);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
 	init();
 	preprocess();
 	//solve();
 	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 194 ms 11828 KB Output is correct
34 Correct 221 ms 12108 KB Output is correct
35 Correct 163 ms 11848 KB Output is correct
36 Correct 193 ms 12380 KB Output is correct
37 Correct 185 ms 12580 KB Output is correct
38 Correct 184 ms 12536 KB Output is correct
39 Correct 164 ms 11612 KB Output is correct
40 Correct 168 ms 11596 KB Output is correct
41 Correct 202 ms 11656 KB Output is correct
42 Correct 182 ms 11688 KB Output is correct
43 Correct 177 ms 11516 KB Output is correct
44 Correct 159 ms 11196 KB Output is correct
45 Correct 162 ms 11340 KB Output is correct
46 Correct 170 ms 11224 KB Output is correct
47 Correct 162 ms 11164 KB Output is correct
48 Correct 161 ms 11196 KB Output is correct
49 Correct 167 ms 11792 KB Output is correct
50 Correct 167 ms 11764 KB Output is correct
51 Correct 168 ms 11812 KB Output is correct
52 Correct 171 ms 11824 KB Output is correct
53 Correct 176 ms 12000 KB Output is correct