답안 #628858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628858 2022-08-13T18:36:25 Z qwerasdfzxcl 송신탑 (IOI22_towers) C++17
17 / 100
927 ms 12816 KB
#include "towers.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int n, a[100100], mn[100100];
priority_queue<int> pq[100100];
vector<int> G;

struct Seg{
    pair<int, int> tree[200200];
    int sz;
    void init(int n){
        sz = n;
        for (int i=sz;i<sz*2;i++) tree[i] = {a[i-sz], i-sz};
        for (int i=sz-1;i;i--) tree[i] = max(tree[i<<1], tree[i<<1|1]);
    }
    pair<int, int> query(int l, int r){
        ++r;
        pair<int, int> ret = {-1, 0};
        for (l+=sz, r+=sz;l<r;l>>=1, r>>=1){
            if (l&1) ret = max(ret, tree[l++]);
            if (r&1) ret = max(ret, tree[--r]);
        }
        return ret;
    }
}tree;

void merge(int x, int l, int r, int d){
    if (pq[l].size() < pq[r].size()) swap(l, r);
    pq[l].push(d);
    while(!pq[r].empty()){
        pq[l].push(pq[r].top());
        pq[r].pop();
    }

    swap(pq[x], pq[l]);
}

int dnc(int l, int r){
    if (l>r) return -1;
    if (l==r) {mn[l] = a[l]; return l;}
    auto [mx, mid] = tree.query(l, r);

    int L = dnc(l, mid-1), R = dnc(mid+1, r);

    if (L==-1){
        swap(pq[mid], pq[R]);
        mn[mid] = mn[R];
    }
    else if (R==-1){
        swap(pq[mid], pq[L]);
        mn[mid] = mn[L];
    }
    else{
        mn[mid] = min(mn[L], mn[R]);
        merge(mid, L, R, mx-max(mn[L], mn[R]));
    }

    //printf("%d %d -> %d / %d\n", l, r, mid, mn[mid]);

    return mid;
}

void init(int N, std::vector<int> H) {
    n = N;
    for (int i=1;i<=n;i++) a[i] = H[i-1];
    tree.init(n+1);

    int tmp = dnc(1, n);
    while(!pq[tmp].empty()){
        G.push_back(pq[tmp].top()); pq[tmp].pop();
    }
    reverse(G.begin(), G.end());

    //for (auto &x:G) printf("%d ", x);
    //printf("\n");
}

int max_towers(int l, int r, int D) {
    ++l, ++r;
    int sz = G.size();
    return sz - (lower_bound(G.begin(), G.end(), D) - G.begin()) + 1;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 397 ms 8952 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 721 ms 8080 KB 1st lines differ - on the 1st token, expected: '11903', found: '33010'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 245 ms 5584 KB Output is correct
2 Correct 803 ms 7996 KB Output is correct
3 Correct 877 ms 8008 KB Output is correct
4 Correct 790 ms 8596 KB Output is correct
5 Correct 739 ms 8772 KB Output is correct
6 Correct 927 ms 8636 KB Output is correct
7 Correct 851 ms 8644 KB Output is correct
8 Correct 854 ms 12812 KB Output is correct
9 Correct 738 ms 12752 KB Output is correct
10 Correct 842 ms 10312 KB Output is correct
11 Correct 879 ms 10704 KB Output is correct
12 Correct 31 ms 7960 KB Output is correct
13 Correct 36 ms 8528 KB Output is correct
14 Correct 37 ms 8648 KB Output is correct
15 Correct 25 ms 12800 KB Output is correct
16 Correct 25 ms 12164 KB Output is correct
17 Correct 31 ms 7816 KB Output is correct
18 Correct 31 ms 8068 KB Output is correct
19 Correct 31 ms 7952 KB Output is correct
20 Correct 37 ms 8632 KB Output is correct
21 Correct 45 ms 8708 KB Output is correct
22 Correct 36 ms 8592 KB Output is correct
23 Correct 37 ms 8620 KB Output is correct
24 Correct 27 ms 12816 KB Output is correct
25 Correct 24 ms 12796 KB Output is correct
26 Correct 24 ms 10260 KB Output is correct
27 Correct 25 ms 12424 KB Output is correct
28 Correct 3 ms 5024 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 4 ms 5072 KB Output is correct
31 Correct 3 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 4944 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 3 ms 4944 KB Output is correct
36 Correct 3 ms 4944 KB Output is correct
37 Correct 3 ms 5072 KB Output is correct
38 Correct 3 ms 5072 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
43 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 397 ms 8952 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -