답안 #725045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725045 2023-04-16T14:14:10 Z sandry24 Just Long Neckties (JOI20_ho_t1) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second

void solve(){
    int n;
    cin >> n;
    vector<ll> a(n+1), b(n);
    for(int i = 0; i <= n; i++)
        cin >> a[i];
    for(int i = 0; i < n; i++)
        cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    vector<ll> diff_same(n), diff_next(n);
    for(int i = 0; i < n; i++){
        diff_same[i] = max(a[i] - b[i], 0LL);
        diff_next[i] = max(a[i+1] - b[i], 0LL);
    }
    vector<vector<ll>> sparse_same(n+1, vector<ll>(26)), sparse_next(n+1, vector<ll>(26));
    for(int i = 1; i <= n; i++){
        sparse_same[i][0] = diff_same[i-1];
        sparse_next[i][0] = diff_next[i-1];
    }
    for(int j = 1; j < 26; j++){
        for(int i = 1; i + (1 << j) - 1 <= n; i++){
            sparse_same[i][j] = max(sparse_same[i][j-1], sparse_same[i + (1 << (j-1))][j-1]);
            sparse_next[i][j] = max(sparse_next[i][j-1], sparse_next[i + (1 << (j-1))][j-1]);
        }
    }
    for(int i = 1; i <= n+1; i++){
        if(i == n+1){
            int l = 1, r = n;
            int w = (int)log2(r - l + 1);
            cout << max(sparse_same[l][w], sparse_same[r - (1 << w) + 1][w]) << ' ';
        } else if(i == 1){
            int l = 1, r = n;
            int w = (int)log2(r - l + 1);
            cout << max(sparse_next[l][w], sparse_next[r - (1 << w) + 1][w]) << ' ';
        } else {
            int l1 = 1, r1 = i-1, l2 = i, r2 = n;
            int w1 = (int)log2(r1 - l1 + 1), w2 = (int)log2(r2 - l2 + 1);
            int max1 = max(sparse_same[l1][w1], sparse_same[r1 - (1 << w1) + 1][w1]);
            int max2 = max(sparse_next[l2][w2], sparse_next[r2 - (1 << w2) + 1][w2]);
            cout << max(max1, max2) << ' ';
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("test.out", "w", stdout);
    //ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -