Submission #115853

# Submission time Handle Problem Language Result Execution time Memory
115853 2019-06-09T10:44:21 Z songc Dancing Elephants (IOI11_elephants) C++14
26 / 100
382 ms 5244 KB
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;

int N, K, M, Q;
int Sq;
int B[400][800], sz[400];
int D[400][800], C[400][800];
int A[150505], T[150505];

void calc(int t){
    if (!sz[t]) return;
    int k=sz[t]-1;
    for (int i=sz[t]-1; i>=0; i--){
        while (B[t][i] + K < B[t][k]) k--;
        if (k == sz[t]-1) D[t][i] = 1, C[t][i] = B[t][i] + K;
        else D[t][i] = D[t][k+1] + 1, C[t][i] = C[t][k+1];
    }
}

void init(int n, int l, int X[])
{
    N=n, K=l;
    Sq = sqrt(N);
    M = (N+Sq-1)/Sq;
    for (int i=0; i<N; i++){
        B[i/Sq][sz[i/Sq]++] = X[i];
        A[i] = X[i];
    }
    for (int i=0; i<M; i++) calc(i);
}

void del(int x){
    int t, k;
    for (t=0; t<M; t++){
        if (!sz[t]) continue;
        k = lower_bound(B[t], B[t]+sz[t], x) - B[t];
        if (k < sz[t] && B[t][k] == x) break;
    }
    sz[t]--;
    for (; k<sz[t]; k++) B[t][k] = B[t][k+1];
    calc(t);
}

void add(int x){
    int t;
    for (t=0; t<M-1; t++) if (sz[t] && x <= B[t][sz[t]-1]) break;
    B[t][sz[t]++] = x;
    for (int i=sz[t]-1; i>0 && B[t][i-1] > B[t][i]; i--) swap(B[t][i-1], B[t][i]);
    calc(t);
}

int update(int x, int y)
{
    del(A[x]);
    A[x] = y;
    add(y);

    Q++;
    if (Q % 400 == 0){
        int cnt=0;
        for (int i=0; i<M; i++){
            for (int j=0; j<sz[i]; j++) T[cnt++] = B[i][j];
            sz[i] = 0;
        }
        init(N, K, T);
    }

    int p=-1, ans=0;
    for (int i=0; i<M; i++){
        if (!sz[i]) continue;
        int k = upper_bound(B[i], B[i]+sz[i], p) - B[i];
        if (k == sz[i]) continue;
        ans += D[i][k], p = C[i][k];
    }
    return ans;
}

Compilation message

elephants.cpp: In function 'void del(int)':
elephants.cpp:34:12: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int t, k;
            ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 203 ms 2220 KB Output is correct
8 Correct 251 ms 3444 KB Output is correct
9 Correct 382 ms 5244 KB Output is correct
10 Incorrect 176 ms 5084 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 203 ms 2220 KB Output is correct
8 Correct 251 ms 3444 KB Output is correct
9 Correct 382 ms 5244 KB Output is correct
10 Incorrect 176 ms 5084 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 203 ms 2220 KB Output is correct
8 Correct 251 ms 3444 KB Output is correct
9 Correct 382 ms 5244 KB Output is correct
10 Incorrect 176 ms 5084 KB Output isn't correct
11 Halted 0 ms 0 KB -