답안 #404033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404033 2021-05-13T17:08:25 Z SamAnd 식물 비교 (IOI20_plants) C++17
0 / 100
1 ms 280 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define m_p make_pair
#define fi first
#define se second
const int N = 200005;

int n, k;
vector<int> r;

pair<int, int> t[N * 4];
int laz[N * 4];
void shi(int pos)
{
    t[pos * 2].fi += laz[pos];
    laz[pos * 2] += laz[pos];
    t[pos * 2 + 1].fi += laz[pos];
    laz[pos * 2 + 1] += laz[pos];
    laz[pos] = 0;
}

void bil(int tl, int tr, int pos)
{
    if (tl == tr)
    {
        t[pos] = m_p(r[tl], tl);
        return;
    }
    int m = (tl + tr) / 2;
    bil(tl, m, pos * 2);
    bil(m + 1, tr, pos * 2 + 1);
    t[pos] = min(t[pos * 2], t[pos * 2 + 1]);
}

void ubd(int tl, int tr, int l, int r, int y, int pos)
{
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        t[pos].fi += y;
        laz[pos] += y;
        return;
    }
    shi(pos);
    int m = (tl + tr) / 2;
    ubd(tl, m, l, min(m, r), y, pos * 2);
    ubd(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1);
    t[pos] = min(t[pos * 2], t[pos * 2 + 1]);
}

pair<int, int> qry(int tl, int tr, int l, int r, int pos)
{
    if (l > r)
        return m_p(N, 0);
    if (tl == l && tr == r)
        return t[pos];
    shi(pos);
    int m = (tl + tr) / 2;
    return min(qry(tl, m, l, min(m, r), pos * 2),
               qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1));
}

vector<int> ans;
void rec(int i)
{
    while (1)
    {
        pair<int, int> u = m_p(N, 0);
        if (i - k + 1 >= 0)
        {
            u = min(u, qry(0, n - 1, i - k + 1, i - 1, 1));
        }
        else
        {
            u = min(u, qry(0, n - 1, 0, i - 1, 1));
            u = min(u, qry(0, n - 1, n + (i - k + 1), n - 1, 1));
        }
        if (u.fi)
            break;
        rec(u.se);
    }
    ans.push_back(i);
    ubd(0, n - 1, i, i, N, 1);
}

void init(int k, vector<int> r)
{
    n = sz(r);
    ::k = k;
    ::r = r;

    bil(0, n - 1, 1);

    while (sz(ans) != n)
    {
        rec(t[1].se);
    }
}

int compare_plants(int x, int y)
{
    if (lower_bound(all(ans), x) - ans.begin() < lower_bound(all(ans), y) - ans.begin())
        return 1;
    return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 280 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -