답안 #1116629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116629 2024-11-22T02:50:36 Z Bzslayed Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
185 ms 49992 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define coutpair(p) cout << p.first << " " << p.second << "|"

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct node{
	int s, e, m;
	int val;
	node *l, *r;

	node(int S, int E){
		s = S, e = E, m = (s+e)/2;
		val = 0;
		if (s != e) {
			l = new node(s, m);
			r = new node(m+1, e);
		}
	}

	void update(int x, int v){
		if (s == e) {val = v;}
		else {
			if (x <= m) {l->update(x, v);}
			else {r->update(x, v);}
			val = max(l->val,r->val);
		}
	}

	int query(int S, int E){
		if (s == S && e == E) {return val;}
		else if (E <= m) {return l->query(S, E);}
		else if (S >= m+1) {return r->query(S, E);}
		else {return max(l->query(S, m),r->query(m+1, E));}
	}
} *curdiff, *nextdiff;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n; cin >> n;
    pll a[n+1]; ll b[n];
    ll ans[n+1];

    for (int i=0; i<n+1; i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    for (int i=0; i<n; i++) cin >> b[i];
    sort(a, a+n+1);
    sort(b, b+n);

    curdiff = new node(0, n+5);
    nextdiff = new node(0, n+5);
    for (int i=0; i<n; i++){ 
        ll cdiff = max(a[i].first-b[i], (ll)0);
        ll ndiff = max(a[i+1].first-b[i], (ll)0);
        curdiff->update(i, cdiff);
        nextdiff->update(i, ndiff);
    }

    for (int i=0; i<n+1; i++){
        if (i == 0) ans[a[i].second] = nextdiff->query(0, n-1);
        else if (i == n) ans[a[i].second] = curdiff->query(0, n-1);
        else ans[a[i].second] = max(curdiff->query(0, i-1), nextdiff->query(i, n-1));
    }

    for (int i=0; i<n+1; i++) cout << ans[i] << " ";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 2 ms 848 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 2 ms 848 KB Output is correct
20 Correct 3 ms 780 KB Output is correct
21 Correct 2 ms 848 KB Output is correct
22 Correct 2 ms 848 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 1016 KB Output is correct
25 Correct 2 ms 848 KB Output is correct
26 Correct 2 ms 848 KB Output is correct
27 Correct 2 ms 848 KB Output is correct
28 Correct 2 ms 848 KB Output is correct
29 Correct 2 ms 840 KB Output is correct
30 Correct 2 ms 848 KB Output is correct
31 Correct 2 ms 848 KB Output is correct
32 Correct 2 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 2 ms 848 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 2 ms 848 KB Output is correct
20 Correct 3 ms 780 KB Output is correct
21 Correct 2 ms 848 KB Output is correct
22 Correct 2 ms 848 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 1016 KB Output is correct
25 Correct 2 ms 848 KB Output is correct
26 Correct 2 ms 848 KB Output is correct
27 Correct 2 ms 848 KB Output is correct
28 Correct 2 ms 848 KB Output is correct
29 Correct 2 ms 840 KB Output is correct
30 Correct 2 ms 848 KB Output is correct
31 Correct 2 ms 848 KB Output is correct
32 Correct 2 ms 848 KB Output is correct
33 Correct 167 ms 47176 KB Output is correct
34 Correct 167 ms 49224 KB Output is correct
35 Correct 170 ms 47716 KB Output is correct
36 Correct 166 ms 48200 KB Output is correct
37 Correct 166 ms 49992 KB Output is correct
38 Correct 173 ms 49276 KB Output is correct
39 Correct 175 ms 47688 KB Output is correct
40 Correct 168 ms 47576 KB Output is correct
41 Correct 170 ms 48200 KB Output is correct
42 Correct 169 ms 47960 KB Output is correct
43 Correct 177 ms 47688 KB Output is correct
44 Correct 173 ms 46716 KB Output is correct
45 Correct 160 ms 47012 KB Output is correct
46 Correct 162 ms 46664 KB Output is correct
47 Correct 160 ms 48712 KB Output is correct
48 Correct 160 ms 48672 KB Output is correct
49 Correct 166 ms 49224 KB Output is correct
50 Correct 184 ms 49224 KB Output is correct
51 Correct 185 ms 49232 KB Output is correct
52 Correct 167 ms 49224 KB Output is correct
53 Correct 170 ms 49224 KB Output is correct