Submission #769137

# Submission time Handle Problem Language Result Execution time Memory
769137 2023-06-29T08:36:04 Z Dan4Life Dancing Elephants (IOI11_elephants) C++17
26 / 100
9000 ms 3364 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mxN = (int)5e4+10;
const int B = 500;
int n, L, x[mxN];
using ar = array<int,3>;

struct Block{
    set<int> S;
    set<ar>S2;
    Block(){}
    void recalc(){
        S2.clear();
        auto itr = end(S);
        while(1){
            itr--;
            auto it2 = S2.lower_bound({*itr+L+1,-1,-1});
            if(it2==end(S2)) S2.insert({*itr,1,*itr+L+1});
            else S2.insert({*itr,(*it2)[1]+1, (*it2)[2]});
            if(itr==begin(S)) break;
        }
    }

    void add(int x){
        if(S.count(x)) return;
        S.insert(x); recalc();
    }

    void rem(int x){
        if(!S.count(x)) return;
        S.erase(x); recalc();
    }
};
vector<Block> bl;

void combine(int i, int j){

} 

void divide(int i){

}

void init(int N, int l, int X[]){
    bl.pb({}); L = l; n = N;
    for(int i = 0; i < n; i++){
        x[i] = X[i]; bl[sz(bl)-1].add(x[i]);
        if(sz(bl[sz(bl)-1].S)>B) divide(sz(bl)-1);
    }
}

int update(int p, int y){
    for(int i = 0; i < sz(bl); i++){
        if(bl[i].S.count(x[p])){ bl[i].rem(x[p]); 
            while(i and sz(bl[i].S)+sz(bl[i-1].S) <= B) combine(i-1,i),i--;
            while(i<sz(bl)-1 and sz(bl[i].S)+sz(bl[i+1].S) <= B) combine(i,i+1),i++;
            break;
        }
    }
    x[p] = y;
    for(int i = 0; i < sz(bl); i++){
        if(i==sz(bl)-1 or *(--end(bl[i].S)) >= x[p]){
            bl[i].add(x[p]); if(sz(bl[i].S)>B) divide(i); break;
        }
    }
    int ans = 0, pos = 0;
    for(Block cur : bl){
        auto S = cur.S; auto S2 = cur.S2;
        if(*(--end(S))<pos) continue;
        auto itr = *S2.lower_bound({pos,-1,-1});
        ans+=itr[1], pos = itr[2];
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Execution timed out 9031 ms 3364 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Execution timed out 9031 ms 3364 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Execution timed out 9031 ms 3364 KB Time limit exceeded
8 Halted 0 ms 0 KB -