답안 #413023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413023 2021-05-28T05:00:31 Z ja_kingy 코끼리 (Dancing Elephants) (IOI11_elephants) C++14
26 / 100
19 ms 2068 KB
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;

const int SQRT = 500, mxN = 150000;
int n, x[mxN+1], l, req[mxN], nx[mxN], blk[mxN], ucnt;
vector<int> blocks[SQRT];

void build_block(int b) {
    int ne = blocks[b].size();
    for (int i = blocks[b].size(); i--;) {
        while (x[blocks[b][ne-1]] > x[blocks[b][i]] + l) ne--;
        req[blocks[b][i]] = ne == blocks[b].size() ? 1 : req[blocks[b][ne]] + 1;
        nx[blocks[b][i]] = ne == blocks[b].size() ? x[blocks[b][i]] + l + 1 : nx[blocks[b][ne]];
    }
}

void rebuild() {
    for (int i = 0; i < (n+SQRT-1)/SQRT; ++i) {
        blocks[i].clear();
    }
    vector<int> order(n);
    iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&](int a, int b){return x[a] < x[b];});
    int b = 0;
    for (int i = 0; i < n; ++i) {
        blocks[b].push_back(order[i]);
        blk[order[i]] = b;
        if (blocks[b].size() == SQRT || i == n-1) {
            build_block(b);
            b++;
        }
    }
}

void init(int N, int L, int X[]) {
    n = N;
    l = L;
    copy(X, X+n, x);
    rebuild();
}

int update(int i, int y) {
    ucnt++;
    if (ucnt == SQRT) {
        ucnt = 0;
        rebuild();
    }
    blocks[blk[i]].erase(find(blocks[blk[i]].begin(), blocks[blk[i]].end(), i));
    build_block(blk[i]);
    x[i] = y;
    for (int b = 0; b < n/SQRT+1; ++b) {
        if (b == n/SQRT || blocks[b].size() && x[blocks[b].back()] >= y) {
            blk[i] = b;
            blocks[b].insert(lower_bound(blocks[b].begin(), blocks[b].end(), i, [&](int a, int b){return x[a] < x[b];}), i);
            build_block(b);
            break;                        
        }
    }
    int ans = 0;
    x[n+1] = 0;
    for (int b = 0; b < (n+SQRT-1)/SQRT; ++b) {
        if (blocks[b].size()) {
            auto it = lower_bound(blocks[b].begin(), blocks[b].end(), n+1, [&](int a, int b){return x[a] < x[b];});
            if (it != blocks[b].end()) {
                ans += req[*it];
                x[n+1] = nx[*it];
            }
        }
    }
    return ans;
}

Compilation message

elephants.cpp: In function 'void build_block(int)':
elephants.cpp:13:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |         req[blocks[b][i]] = ne == blocks[b].size() ? 1 : req[blocks[b][ne]] + 1;
      |                             ~~~^~~~~~~~~~~~~~~~~~~
elephants.cpp:14:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         nx[blocks[b][i]] = ne == blocks[b].size() ? x[blocks[b][i]] + l + 1 : nx[blocks[b][ne]];
      |                            ~~~^~~~~~~~~~~~~~~~~~~
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:53:45: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   53 |         if (b == n/SQRT || blocks[b].size() && x[blocks[b].back()] >= y) {
      |                            ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 19 ms 2068 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 19 ms 2068 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 19 ms 2068 KB Output isn't correct
8 Halted 0 ms 0 KB -