Submission #748028

# Submission time Handle Problem Language Result Execution time Memory
748028 2023-05-25T10:15:42 Z Dan4Life Dancing Elephants (IOI11_elephants) C++17
26 / 100
377 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second

const int mxN = (int)1.5e5+10;
const int INF = (int)1e9+10;
const int B = 390;
const int nmB = INF/B;

set<int> S, pos[nmB];
int n, L, ok, p[mxN/B];
unordered_map<int,int> b;
set<array<int,3>> block[INF/B];

void reUpd(int ind){
    block[ind].clear();
    auto itr = end(pos[ind]);
    while(itr!=begin(pos[ind])){
        itr--;
        auto itr2 = block[ind].lower_bound({*itr+L+1,-1,-1});
        
        if(itr2!=block[ind].end()){
            auto obj = *itr2;
            block[ind].insert({*itr,1+obj[1],obj[2]});
        }
        else block[ind].insert({*itr,1,*itr+L+1});
    }
}

void ins(int x){
    b[x]++; if(b[x]!=1) return;
    if(ok) { S.insert(x); return; }
    int ind = x/B; pos[ind].insert(x); reUpd(ind);
}

void del(int x){
    b[x]--; if(b[x]) return;
    if(ok) { S.erase(x); return;}
    int ind = x/B; pos[ind].erase(x); reUpd(ind);
}

void init(int N, int l, int X[])
{
    n = N; L = l;
    if(N<B) ok=1;
    for(int i = 0; i < n; i++)
        p[i]=X[i], ins(p[i]);
}

int update(int i, int y)
{
    del(p[i]); p[i]=y; ins(y);
    int ans = 0;
    if(ok){
        auto itr = S.begin();
        while(itr!=S.end()) itr = S.upper_bound(*itr+L), ans++;
        return ans;
    }
    int cur = 0;
    for(int i = 0; i < nmB; i++){
        auto itr = block[i].lower_bound({cur,-1,-1});
        if(itr!=block[i].end()) ans+=(*itr)[1], cur = (*itr)[2];
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 109 ms 241236 KB Output is correct
2 Correct 108 ms 241244 KB Output is correct
3 Correct 114 ms 241168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 241236 KB Output is correct
2 Correct 108 ms 241244 KB Output is correct
3 Correct 114 ms 241168 KB Output is correct
4 Correct 121 ms 241156 KB Output is correct
5 Correct 107 ms 241116 KB Output is correct
6 Correct 109 ms 241116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 241236 KB Output is correct
2 Correct 108 ms 241244 KB Output is correct
3 Correct 114 ms 241168 KB Output is correct
4 Correct 121 ms 241156 KB Output is correct
5 Correct 107 ms 241116 KB Output is correct
6 Correct 109 ms 241116 KB Output is correct
7 Runtime error 377 ms 262144 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 109 ms 241236 KB Output is correct
2 Correct 108 ms 241244 KB Output is correct
3 Correct 114 ms 241168 KB Output is correct
4 Correct 121 ms 241156 KB Output is correct
5 Correct 107 ms 241116 KB Output is correct
6 Correct 109 ms 241116 KB Output is correct
7 Runtime error 377 ms 262144 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 109 ms 241236 KB Output is correct
2 Correct 108 ms 241244 KB Output is correct
3 Correct 114 ms 241168 KB Output is correct
4 Correct 121 ms 241156 KB Output is correct
5 Correct 107 ms 241116 KB Output is correct
6 Correct 109 ms 241116 KB Output is correct
7 Runtime error 377 ms 262144 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -