답안 #762992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762992 2023-06-22T02:13:21 Z vjudge1 Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
174 ms 24132 KB
#include<bits/stdc++.h>
#define int long long
#define BUG(x) cerr << #x << " = " << x << endl
using namespace std;
const int N = 200005;
int t,n,a[N],b[N],st[2][4*N],diff[2][N];
vector < pair < int , int > > v;
vector < pair < int , int > > ans;
void build(int id, int l, int r, int idx) {
	if (l>r) return;
	if (l==r) {
		st[idx][id] = diff[idx][l];
		return;
	}
	int m = (l+r)/2;
	build(id*2,l,m,idx);
	build(id*2+1,m+1,r,idx);
	st[idx][id] = max(st[idx][id*2],st[idx][id*2+1]);
}
int get(int id, int l, int r, int u, int v, int idx) {
	if (l>v || r<u) return 0;
	if (l>=u && r<=v) return st[idx][id];
	int m = (l+r)/2;
	return max(get(id*2,l,m,u,v,idx),get(id*2+1,m+1,r,u,v,idx));
}
void solve() {
	cin >> n;
	for (int i = 0; i<=n; i++) {
		cin >> a[i];
		v.push_back({a[i],i});
	}
	for (int i = 0; i<n; i++) {
		cin >> b[i];
	}
	sort(v.begin(),v.end());
	sort(a,a+n+1);
	sort(b,b+n);
//	for (int i = 0; i<n+1; i++) {
//		cout << a[i] << " ";
//	}
//	cout << endl;
//	for (int i = 0; i<n; i++) {
//		cout << b[i] << " ";
//	}
//	cout << endl;
	for (int i = 1; i<=n; i++) {
		diff[0][i] = max(a[i-1]-b[i-1],0LL);
		diff[1][i] = max(a[i]-b[i-1],0LL);
//		BUG(diff[0][i]);
//		BUG(diff[1][i]);
	}
	build(1,1,n,0);
	build(1,1,n,1);
	for (int i = 0; i<=n; i++) {
//		BUG(v[i].second);
//		BUG(v[i].first);
		if (i==0) {
			ans.push_back({v[i].second,get(1,1,n,1,n,1)});
//			BUG(ans[i].second);
			continue;
		}
		if (i==n) {
			ans.push_back({v[i].second,get(1,1,n,1,n,0)});
//			BUG(ans[i].second);
			continue;
		}
		ans.push_back({v[i].second,max(get(1,1,n,1,i,0),get(1,1,n,i+1,n,1))});
//		BUG(ans[i].second);
	}
	sort(ans.begin(),ans.end());
	for (int i = 0; i<=n; i++) {
//		BUG(ans[i].first);
		cout << ans[i].second << " ";
	}
}
signed main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 145 ms 23544 KB Output is correct
34 Correct 153 ms 23976 KB Output is correct
35 Correct 145 ms 23620 KB Output is correct
36 Correct 174 ms 23736 KB Output is correct
37 Correct 151 ms 23996 KB Output is correct
38 Correct 160 ms 23948 KB Output is correct
39 Correct 146 ms 23760 KB Output is correct
40 Correct 148 ms 23752 KB Output is correct
41 Correct 147 ms 23860 KB Output is correct
42 Correct 149 ms 23808 KB Output is correct
43 Correct 145 ms 23748 KB Output is correct
44 Correct 143 ms 23580 KB Output is correct
45 Correct 151 ms 23796 KB Output is correct
46 Correct 145 ms 23560 KB Output is correct
47 Correct 135 ms 24004 KB Output is correct
48 Correct 133 ms 23988 KB Output is correct
49 Correct 152 ms 24004 KB Output is correct
50 Correct 151 ms 24000 KB Output is correct
51 Correct 151 ms 24000 KB Output is correct
52 Correct 162 ms 24132 KB Output is correct
53 Correct 151 ms 24072 KB Output is correct