Submission #51137

# Submission time Handle Problem Language Result Execution time Memory
51137 2018-06-16T09:25:48 Z 강태규(#1289, imeimi2000) Dancing Elephants (IOI11_elephants) C++11
Compilation error
0 ms 0 KB
#include "elephants.h"
#include <algorithm>
#include <map>

using namespace std;

const int t = 2000;
const int MAXN = 2e5;
int n, l, a[MAXN];
int x[MAXN];
int bs;
map<int, int> mp;

struct _dp {
    int cnt, mx;
    _dp operator+(int x) const {
        return { cnt + x, mx };
    }
} dp[t][t << 1 | 1];

int buc[t][t << 1 | 1];
int s[t];

const int inf = 1e9 + 7;
void recalc(int s) {
    int j = buc[s][0];
    for (int i = j++; i > 0; --i) {
        while (j > 1 && buc[s][i] + l < buc[s][j - 1]) --j;
        if (j <= buc[s][0]) dp[s][i] = dp[s][j] + 1;
        else dp[s][i] = { 1, buc[s][i] };
    }
}

void reset() {
    for (int i = 0; i < bs; ++i) {
        buc[i][0] = 0;
        for (int j = 0; j < t && t * i + j < n; ++j) {
            buc[i][++buc[i][0]] = x[t * i + j];
        }
        recalc(i);
        s[i] = buc[i][1];
    }
}

void getX() {
    int p = 0;
    for (int i = 0; i < bs; ++i) {
        for (int j = 1; j <= buc[i][0]; ++j) {
            x[p++] = buc[i][j];
        }
    }
}

void init(int N, int L, int X[]) {
    n = N;
    l = L;
    bs = (n + t - 1) / t;
    for (int i = 0; i < n; ++i) ++mp[a[i] = x[i] = X[i]];
    n = unique(x, x + n) - x;
    reset();
}

int getBuc(int i) {
    return lower_bound(s + 1, s + bs, i + 1) - s - 1;
}

int update(int p, int y) {
    
    if (mp[a[p]] == 1) {
            --mp[a[p]];
    int s = getBuc(a[p]);
    int si = lower_bound(buc[s] + 1, buc[s] + (buc[s][0] + 1), a[p]) - buc[s];
    for (int i = si; i < buc[s][0]; ++i) {
        buc[s][i] = buc[s][i + 1];
    }
    --buc[s][0];
    --n;
    recalc(s);
    }
    if (mp[y] == 0){
            ++mp[y];
            s = getBuc(y);
    if (buc[s][0] == (t << 1)) getX(), reset(), s = getBuc(y);
    si = lower_bound(buc[s] + 1, buc[s] + (buc[s][0] + 1), y) - buc[s];
    for (int i = ++buc[s][0]; i > si; --i) {
        buc[s][i] = buc[s][i - 1];
    }
    buc[s][si] = y;
    ++n;
    recalc(s);
    a[p] = y;
    }
    int ret = 0;
    p = -inf;
    for (int i = 0; i < bs; ++i) {
        int j = lower_bound(buc[i] + 1, buc[i] + (buc[i][0] + 1), p + l + 1) - buc[i];
        if (j <= buc[i][0]) {
            ret += dp[i][j].cnt;
            p = dp[i][j].mx;
        }
    }
    return ret;
}

Compilation message

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:82:25: error: incompatible types in assignment of 'int' to 'int [2000]'
             s = getBuc(y);
                         ^
elephants.cpp:83:14: error: invalid types 'int [2000][4001][int [2000]]' for array subscript
     if (buc[s][0] == (t << 1)) getX(), reset(), s = getBuc(y);
              ^
elephants.cpp:83:61: error: incompatible types in assignment of 'int' to 'int [2000]'
     if (buc[s][0] == (t << 1)) getX(), reset(), s = getBuc(y);
                                                             ^
elephants.cpp:84:5: error: 'si' was not declared in this scope
     si = lower_bound(buc[s] + 1, buc[s] + (buc[s][0] + 1), y) - buc[s];
     ^~
elephants.cpp:84:5: note: suggested alternative: 's'
     si = lower_bound(buc[s] + 1, buc[s] + (buc[s][0] + 1), y) - buc[s];
     ^~
     s
elephants.cpp:84:27: error: invalid types 'int [2000][4001][int [2000]]' for array subscript
     si = lower_bound(buc[s] + 1, buc[s] + (buc[s][0] + 1), y) - buc[s];
                           ^
elephants.cpp:84:39: error: invalid types 'int [2000][4001][int [2000]]' for array subscript
     si = lower_bound(buc[s] + 1, buc[s] + (buc[s][0] + 1), y) - buc[s];
                                       ^
elephants.cpp:84:49: error: invalid types 'int [2000][4001][int [2000]]' for array subscript
     si = lower_bound(buc[s] + 1, buc[s] + (buc[s][0] + 1), y) - buc[s];
                                                 ^
elephants.cpp:84:70: error: invalid types 'int [2000][4001][int [2000]]' for array subscript
     si = lower_bound(buc[s] + 1, buc[s] + (buc[s][0] + 1), y) - buc[s];
                                                                      ^
elephants.cpp:85:25: error: invalid types 'int [2000][4001][int [2000]]' for array subscript
     for (int i = ++buc[s][0]; i > si; --i) {
                         ^
elephants.cpp:86:14: error: invalid types 'int [2000][4001][int [2000]]' for array subscript
         buc[s][i] = buc[s][i - 1];
              ^
elephants.cpp:86:26: error: invalid types 'int [2000][4001][int [2000]]' for array subscript
         buc[s][i] = buc[s][i - 1];
                          ^
elephants.cpp:88:10: error: invalid types 'int [2000][4001][int [2000]]' for array subscript
     buc[s][si] = y;
          ^
elephants.cpp:90:13: error: invalid conversion from 'int*' to 'int' [-fpermissive]
     recalc(s);
             ^
elephants.cpp:25:6: note:   initializing argument 1 of 'void recalc(int)'
 void recalc(int s) {
      ^~~~~~