답안 #256169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256169 2020-08-02T10:47:12 Z SamAnd 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
100 / 100
8102 ms 12768 KB
#include "elephants.h"
//#include "grader.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int N = 150005;
const int S = 400;

int n, d;
int x[N];

vector<int> v[S];
vector<int> q[S];
vector<int> u[S];

void clc(int i)
{
    q[i].resize(sz(v[i]));
    u[i].resize(sz(v[i]));
    int k = sz(v[i]);
    for (int j = sz(v[i]) - 1; j >= 0; --j)
    {
        int x = v[i][j];
        //auto it = upper_bound(all(v[i]), x + d);

        while (v[i][k - 1] > x + d)
            --k;

        if (k == sz(v[i]))
        {
            q[i][j] = 1;
            u[i][j] = x + d;
        }
        else
        {
            q[i][j] = 1 + q[i][k];
            u[i][j] = u[i][k];
        }
    }
}

int ans()
{
    int qq = 0;
    int uu = -1;
    for (int i = 0; i < S; ++i)
    {
        auto it = upper_bound(all(v[i]), uu);
        if (it == v[i].end())
            continue;
        qq += q[i][it - v[i].begin()];
        uu = u[i][it - v[i].begin()];
    }
    return qq;
}

void init(int N, int L, int X[])
{
    n = N;
    d = L;
    for (int i = 0; i < n; ++i)
        x[i] = X[i];

    for (int i = 0; i < n; ++i)
    {
        v[(i / S)].push_back(x[i]);
    }

    for (int i = 0; i < S; ++i)
    {
        clc(i);
    }
}

int qq;
int sx[N];

int update(int i, int y)
{
    ++qq;
    int xx = x[i];

    for (int i = 0; i < S; ++i)
    {
        if (binary_search(all(v[i]), xx))
        {
            vector<int> vv;
            for (int j = 0; j < sz(v[i]); ++j)
            {
                if (v[i][j] == xx)
                {
                    for (int k = 0; k < j; ++k)
                        vv.push_back(v[i][k]);
                    for (int k = j + 1; k < sz(v[i]); ++k)
                        vv.push_back(v[i][k]);
                    break;
                }
            }
            v[i] = vv;
            clc(i);
            break;
        }
    }

    x[i] = y;

    bool z = false;
    for (int i = 0; i < S; ++i)
    {
        if (v[i].empty())
            continue;
        if (y < v[i][0])
        {
            reverse(all(v[i]));
            v[i].push_back(y);
            reverse(all(v[i]));
            clc(i);
            z = true;
            break;
        }
        if (y <= v[i].back())
        {
            vector<int> vv;
            for (int j = 0; j < sz(v[i]); ++j)
            {
                if (y <= v[i][j])
                {
                    for (int k = 0; k < j; ++k)
                        vv.push_back(v[i][k]);
                    vv.push_back(y);
                    for (int k = j; k < sz(v[i]); ++k)
                        vv.push_back(v[i][k]);
                    break;
                }
            }
            v[i] = vv;
            clc(i);
            z = true;
            break;
        }
    }

    if (!z)
    {
        v[S - 1].push_back(y);
        clc(S - 1);
    }

    if (qq % S == 0)
    {
        for (int i = 0; i < n; ++i)
            sx[i] = x[i];
        sort(sx, sx + n);
        for (int i = 0; i < S; ++i)
            v[i].clear();
        for (int i = 0; i < n; ++i)
            v[(i / S)].push_back(sx[i]);
        for (int i = 0; i < S; ++i)
            clc(i);
    }

    return ans();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 451 ms 2336 KB Output is correct
8 Correct 511 ms 2604 KB Output is correct
9 Correct 615 ms 3212 KB Output is correct
10 Correct 557 ms 3072 KB Output is correct
11 Correct 573 ms 3064 KB Output is correct
12 Correct 1173 ms 3484 KB Output is correct
13 Correct 575 ms 3072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 451 ms 2336 KB Output is correct
8 Correct 511 ms 2604 KB Output is correct
9 Correct 615 ms 3212 KB Output is correct
10 Correct 557 ms 3072 KB Output is correct
11 Correct 573 ms 3064 KB Output is correct
12 Correct 1173 ms 3484 KB Output is correct
13 Correct 575 ms 3072 KB Output is correct
14 Correct 692 ms 2864 KB Output is correct
15 Correct 806 ms 2936 KB Output is correct
16 Correct 1825 ms 3704 KB Output is correct
17 Correct 2043 ms 4600 KB Output is correct
18 Correct 2183 ms 4472 KB Output is correct
19 Correct 1167 ms 3832 KB Output is correct
20 Correct 2041 ms 4472 KB Output is correct
21 Correct 2032 ms 4364 KB Output is correct
22 Correct 1016 ms 3800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 451 ms 2336 KB Output is correct
8 Correct 511 ms 2604 KB Output is correct
9 Correct 615 ms 3212 KB Output is correct
10 Correct 557 ms 3072 KB Output is correct
11 Correct 573 ms 3064 KB Output is correct
12 Correct 1173 ms 3484 KB Output is correct
13 Correct 575 ms 3072 KB Output is correct
14 Correct 692 ms 2864 KB Output is correct
15 Correct 806 ms 2936 KB Output is correct
16 Correct 1825 ms 3704 KB Output is correct
17 Correct 2043 ms 4600 KB Output is correct
18 Correct 2183 ms 4472 KB Output is correct
19 Correct 1167 ms 3832 KB Output is correct
20 Correct 2041 ms 4472 KB Output is correct
21 Correct 2032 ms 4364 KB Output is correct
22 Correct 1016 ms 3800 KB Output is correct
23 Correct 4163 ms 7520 KB Output is correct
24 Correct 4753 ms 9404 KB Output is correct
25 Correct 3500 ms 11440 KB Output is correct
26 Correct 4199 ms 10920 KB Output is correct
27 Correct 5998 ms 10872 KB Output is correct
28 Correct 1978 ms 5368 KB Output is correct
29 Correct 1928 ms 5496 KB Output is correct
30 Correct 1963 ms 5344 KB Output is correct
31 Correct 1948 ms 5404 KB Output is correct
32 Correct 4276 ms 10368 KB Output is correct
33 Correct 4381 ms 9672 KB Output is correct
34 Correct 4118 ms 10552 KB Output is correct
35 Correct 4070 ms 12768 KB Output is correct
36 Correct 2844 ms 10324 KB Output is correct
37 Correct 7766 ms 12532 KB Output is correct
38 Correct 4395 ms 9556 KB Output is correct
39 Correct 4833 ms 10588 KB Output is correct
40 Correct 4375 ms 9592 KB Output is correct
41 Correct 7737 ms 11524 KB Output is correct
42 Correct 8102 ms 11756 KB Output is correct