Submission #805443

# Submission time Handle Problem Language Result Execution time Memory
805443 2023-08-03T16:41:47 Z QwertyPi Dancing Elephants (IOI11_elephants) C++14
26 / 100
9000 ms 2260 KB
#include "elephants.h"
#include <bits/stdc++.h>

const int MAXN = 1.5e5 + 11;
const int SQ = 50011;
int n, l;
int x[MAXN];

struct naive{
    int n, y[SQ * 2], dp[SQ * 2], fin[SQ * 2];
    void build(int n, int x[]){
        naive::n = n;
        for(int i = 0; i < n; i++){
            y[i] = x[i];
        }
    }
    void rem(int x){
        int i; for(i = 0; i < n; i++) if(y[i] == x) break;
        for(int j = i; j < n - 1; j++) y[j] = y[j + 1];
        n--; precalc();
    }
    void add(int x){
        int i; for(i = 0; i < n; i++) if(y[i] > x) break;
        for(int j = n - 1; j >= i; j--) y[j + 1] = y[j];
        y[i] = x;
        n++; precalc();
    }
    void precalc(){
        dp[n] = 0; fin[n] = n; int r = n - 1;
        for(int j = n - 1; j >= 0; j--){
            while(y[r] - y[j] > l) r--;
            dp[j] = dp[r + 1] + 1;
            fin[j] = r + 1 != n ? fin[r + 1] : j;
        }
    }
    int qry(){
        return dp[0];
    }
} cal[MAXN / SQ + 10];


void rebuild(){
    std::sort(x, x + n);
    cal[0].build(n, x);
}

void rem(int x){
    cal[0].rem(x);
}

void add(int x){
    cal[0].add(x);
}

int qry(){
    return cal[0].qry();
}

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

int update(int i, int y){
    rem(x[i]);
    x[i] = y;
    add(x[i]);
    return qry();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 6979 ms 1172 KB Output is correct
8 Execution timed out 9016 ms 2260 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 6979 ms 1172 KB Output is correct
8 Execution timed out 9016 ms 2260 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 6979 ms 1172 KB Output is correct
8 Execution timed out 9016 ms 2260 KB Time limit exceeded
9 Halted 0 ms 0 KB -