답안 #748071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748071 2023-05-25T11:23:32 Z Dan4Life 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
0 / 100
1 ms 340 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)5e4+10;
const int B = 300;


set<int> pos[B+10];
int n, L, tim=B, p[mxN];
unordered_map<int,int> b;
set<array<int,3>> block[B+10];
 
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 ins(int x, bool now=1, int ind=-1){
    b[x]++; if(b[x]!=1 or !now) return;
    if(ind!=-1){ pos[ind].insert(x),reUpd(ind); return; }
    for(int i = 0; i < B; i++){
        if(i==B-1 or (!pos[i+1].empty() and *pos[i+1].begin()>x)){
            pos[i].insert(x),reUpd(i);  return;
        }
    }
}
 
void del(int x, bool now=1, int ind=-1){
    b[x]--; if(b[x] or !now) return;
    if(ind!=-1){ pos[ind].insert(x),reUpd(ind); return;}
    for(int i = 0; i < B; i++){
        if(i==B-1 or (!pos[i+1].empty() and *pos[i+1].begin()>x)){
            pos[i].insert(x),reUpd(i); return;
        }
    }
}

void build(){
    for(int i = 0; i < B; i++) 
        pos[i].clear(), block[i].clear();
    vector<int> v; v.clear();
    set<int> S; S.clear();
    for(int i = 0; i < n; i++) v.push_back(p[i]);
    sort(all(v)); v.erase(unique(all(v)),end(v));
    for(int i = 0; i < n; i++){
        ins(v[i],1,i/B);
    }
}
 
void init(int N, int l, int X[])
{
    n = N; L = l;
    for(int i = 0; i < n; i++) p[i]=X[i];
    build();
}
 
int update(int i, int y)
{
    del(p[i]); p[i]=y; ins(y);
    if(!tim) build(),tim=B; tim--;
    int ans = 0, cur = 0;
    for(int i = 0; i < B; i++){
        auto itr = block[i].lower_bound({cur,-1,-1});
        if(itr!=block[i].end()) ans+=(*itr)[1], cur = (*itr)[2];
    }
    return ans;
}

Compilation message

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:69:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   69 |     if(!tim) build(),tim=B; tim--;
      |     ^~
elephants.cpp:69:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   69 |     if(!tim) build(),tim=B; tim--;
      |                             ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -