답안 #748097

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748097 2023-05-25T11:53:29 Z Dan4Life 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
0 / 100
3 ms 5332 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(),a.end()
const int mxN = (int)1.5e5+10;
const int INF = (int)1e9;
const int B = 3;
const int mxB = mxN/B+1;

set<int> pos[mxB+2];
int n, L, tim, *p;
int le[mxN], ri[mxN];
unordered_map<int,int> b;
set<array<int,3>> block[mxB+2];
 
void reUpd(int ind){
    block[ind].clear();
    auto itr = end(pos[ind]);
    auto stop = begin(pos[ind]);
    while(itr!=stop){ itr--;
        auto itr2 = block[ind].lower_bound({*itr+L+1,-1,-1});
        if(itr2!=block[ind].end())
            block[ind].insert({*itr,1+(*itr2)[1],(*itr2)[2]});
        else block[ind].insert({*itr,1,*itr+L+1});
    }
}

void findPos(int x, bool ok){
    for(int i = 0; i < mxB; i++){
        if(le[i]<=x and x<=ri[i]){
            if(ok) pos[i].insert(x);
            else pos[i].erase(x);
            reUpd(i); return;
        }
    }
}

void ins(int x, int ind=-1){
    b[x]++; if(b[x]!=1) return;
    if(ind==-1) {findPos(x,1); return; }
    pos[ind].insert(x), reUpd(ind);
}
 
void del(int x, int ind=-1){
    b[x]--; if(b[x]) return;
    if(ind==-1) {findPos(x,0); return; }
    pos[ind].erase(x), reUpd(ind);
}

void build(){
    for(int i = 0; i < mxB; i++) 
        pos[i].clear(), block[i].clear(), le[i]=-1, ri[i]=INF;
    vector<int> v; v.clear();
    for(int i = 0; i < n; i++) v.push_back(p[i]);
    sort(all(v));
    for(int i = 0; i < n; i++) 
    for(int i = 0; i < n; i++){
        int j = i/B; ins(v[i],j);
        if(le[j]!=-1) le[j]=v[i];
        ri[j]=v[i];
    }
}
 
void init(int N, int l, int X[]){
    n = N; L = l; p=X; build();
}
 
int update(int i, int y)
{
    del(p[i]); p[i]=y; ins(y);
    //if(++tim%B==0) build(); 
    int ans = 0, cur = 0;
    for(int i = 0; i < mxB; i++){
        auto itr = block[i].lower_bound({cur,-1,-1});
        if(itr!=block[i].end()) ans+=(*itr)[1], cur = (*itr)[2];
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5332 KB Output isn't correct
2 Halted 0 ms 0 KB -