답안 #388265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388265 2021-04-10T17:31:26 Z alexxela12345 식물 비교 (IOI20_plants) C++17
44 / 100
752 ms 18960 KB
#include <bits/stdc++.h>
#include "plants.h"

using namespace std;

int n;
int k;
vector<int> arr;

void genSome();

void init(int k_, std::vector<int> r_) {
	k = k_;
	arr = r_;
	n = arr.size();
    genSome();
}

vector<int> h;
int cur;

vector<pair<int, int>> tree;
vector<int> mod;

void build(int v, int l, int r) {
    if (l + 1 == r) {
        tree[v] = {arr[l], l};
    } else {
        int m = (l + r) / 2;
        build(2 * v + 1, l, m);
        build(2 * v + 2, m, r);
        tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]);
    }
}

void build() {
    tree.resize(4 * n);
    mod.resize(4 * n);
    build(0, 0, n);
}

void push(int v, int l, int r) {
    tree[v].first += mod[v];
    if (l + 1 != r) {
        mod[2 * v + 1] += mod[v];
        mod[2 * v + 2] += mod[v];
    }
    mod[v] = 0;
}

pair<int, int> GetMin(int v, int l, int r, int ql, int qr) {
    if (ql >= r || qr <= l) {
        return {n, -1};
    }
    push(v, l, r);
    if (ql <= l && r <= qr) {
        return tree[v];
    }
    int m = (l + r) / 2;
    return min(GetMin(2 * v + 1, l, m, ql, qr),
               GetMin(2 * v + 2, m, r, ql, qr));
}

pair<int, int> GetMin(int l, int r) {
    // l might be negative
    if (l >= 0) {
        return GetMin(0, 0, n, l, r);
    }
    return min(GetMin(0, 0, n, 0, r), GetMin(0, 0, n, n + l, n));
}

void Set(int v, int l, int r, int ind, int x) {
    push(v, l, r);
    if (ind < l || ind >= r)
        return;
    if (l + 1 == r) {
        tree[v] = {x, ind};
    } else {
        int m = (l + r) / 2;
        Set(2 * v + 1, l, m, ind, x);
        Set(2 * v + 2, m, r, ind, x);
        tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]);
    }
}

void Set(int ind, int x) {
    Set(0, 0, n, ind, x);
}

void Add(int v, int l, int r, int ql, int qr, int x) {
    push(v, l, r);
    if (ql >= r || qr <= l)
        return;
    if (ql <= l && r <= qr) {
        mod[v] = x;
        push(v, l, r);
        return;
    }
    int m = (l + r) / 2;
    Add(2 * v + 1, l, m, ql, qr, x);
    Add(2 * v + 2, m, r, ql, qr, x);
    tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]);
}

void Add(int l, int r, int x) {
    if (l >= 0) {
        return Add(0, 0, n, l, r, x);
    }
    Add(0, 0, n, 0, r, x);
    Add(0, 0, n, n + l, n, x);
}

void rec(int ind) {
    while (true) {
        auto pp = GetMin(ind - k + 1, ind);
        if (pp.first == 0) {
            rec(pp.second);
        } else {
            break;
        }
    }
    h[ind] = cur--;
    Set(ind, n);
    Add(ind - k + 1, ind, -1);
}

void genSome() {
    h.resize(n, -1);
    build();
    cur = n;
    while (true) {
        auto pp = GetMin(0, n);
        if (pp.first == 0) {
            rec(pp.second);
        } else {
            break;
        }
    }
}

int compare_plants(int x, int y) {
    if (h[x] > h[y]) {
        return 1;
    } else {
        return -1;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 3 ms 332 KB Output is correct
7 Correct 72 ms 3392 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 72 ms 3396 KB Output is correct
11 Correct 69 ms 3312 KB Output is correct
12 Correct 70 ms 3524 KB Output is correct
13 Correct 71 ms 3440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 3 ms 332 KB Output is correct
7 Correct 72 ms 3392 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 72 ms 3396 KB Output is correct
11 Correct 69 ms 3312 KB Output is correct
12 Correct 70 ms 3524 KB Output is correct
13 Correct 71 ms 3440 KB Output is correct
14 Correct 111 ms 4332 KB Output is correct
15 Correct 734 ms 15184 KB Output is correct
16 Correct 117 ms 6544 KB Output is correct
17 Correct 739 ms 18880 KB Output is correct
18 Correct 507 ms 18476 KB Output is correct
19 Correct 508 ms 18960 KB Output is correct
20 Correct 688 ms 18884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 64 ms 3172 KB Output is correct
4 Correct 394 ms 15432 KB Output is correct
5 Correct 455 ms 18296 KB Output is correct
6 Correct 639 ms 18500 KB Output is correct
7 Correct 722 ms 18756 KB Output is correct
8 Correct 752 ms 18756 KB Output is correct
9 Correct 429 ms 18116 KB Output is correct
10 Correct 402 ms 18148 KB Output is correct
11 Correct 338 ms 18116 KB Output is correct
12 Correct 410 ms 18296 KB Output is correct
13 Correct 511 ms 18264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -