답안 #1032506

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032506 2024-07-23T21:55:14 Z SiliconSquared 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
100 / 100
4454 ms 11876 KB
using namespace std;
#include "elephants.h"
#include <vector>
#include <algorithm>
#define B 400
int n,m,e;
struct bucket{
    vector<int> v;
    vector<int> z;
    vector<int> zz;
    bucket(){}
    void f(){
        z.resize(v.size());
        zz.resize(v.size());
        int j=v.size()-1;//last in frame
        for (int i=v.size()-1;i>=0;i--){
            while (v[i]+m<=v[j]){
                j--;
            }
            if (j==(int)v.size()-1){
                z[i]=1;
                zz[i]=v[i]+m;
            }else{
                z[i]=z[j+1]+1;
                zz[i]=zz[j+1];
            }
        }
    }
    int find(int x){
        int a,b,y;
        a=0;b=v.size();
        if (b==0){return 0;}
        if (b==1){
            if (v[0]>=x){
                return 0;
            }
            return 1;
        }
        while (a+1!=b){
            y=(a+b)/2;
            if (v[y]<x){a=y;}
            else if (v[y]>x){b=y;}
            else{break;}
        }
        if (v[y]!=x){
            if(v[a]<x){y=b;}else{y=a;}
        }
        return y;
    }
};
vector<bucket> v;
int bigfind(int x){
    int a,b,y;
    a=0;b=v.size();
    while (a+1!=b){
        y=(a+b)/2;
        while (y<b && v[y].v.size()==0){y++;}
        while (y>=a && v[y].v.size()==0){y--;}
        if ((v[a].v[0]<=x) && (v[y-1].v[v[y-1].v.size()-1]>=x)){b=y;}
        else if (v[a].v[0]>=x){b=y;}
        else {a=y;}
    }
    return a;
}
vector<int> w;

void bucketer(){
    vector<int> t=w;
    sort(t.begin(),t.end());
    v.clear();
    int i=0;
    int k=0;
    while (i<n){
        v.push_back(bucket());
        for (int j=0;j<B;j++){
            if (i+j>=n){break;}
            v[k].v.push_back(t[i+j]);
        }
        i+=B;
        k++;
    }
    for (int i=0;i<(int)v.size();i++){
        v[i].f();
    }
}

void init(int N, int L, int X[]){
    n=N;
    m=L+1;
    e=0;
    w.resize(n);
    for (int i=0;i<n;i++){w[i]=X[i];}
    bucketer();
}

int update(int i, int y){
    int x=bigfind(y);
    v[x].v.insert(v[x].v.begin()+v[x].find(y),y);
    v[x].f();
    x=bigfind(w[i]);
    v[x].v.erase(v[x].v.begin()+v[x].find(w[i]));
    v[x].f();
    w[i]=y;
    e++;
    if (e==B){
        bucketer();
        e=0;
    }
    // if (y==0){for (auto vv:v){for(auto vvv:vv.v){print(vvv);}print(-1);}}
    int z=0;
    x=0;
    for (int j=0;j<(int)v.size();j++){
        if (v[j].find(x)==v[j].v.size()){continue;}
        x=v[j].find(x);//print(v[j].v[x]);
        z+=v[j].z[x];//print(z);
        x=v[j].zz[x];//print(x);
    }
    return z;
}

Compilation message

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:113:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |         if (v[j].find(x)==v[j].v.size()){continue;}
      |             ~~~~~~~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 114 ms 2292 KB Output is correct
8 Correct 152 ms 2396 KB Output is correct
9 Correct 229 ms 4164 KB Output is correct
10 Correct 315 ms 3484 KB Output is correct
11 Correct 292 ms 3480 KB Output is correct
12 Correct 545 ms 3960 KB Output is correct
13 Correct 315 ms 3428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 114 ms 2292 KB Output is correct
8 Correct 152 ms 2396 KB Output is correct
9 Correct 229 ms 4164 KB Output is correct
10 Correct 315 ms 3484 KB Output is correct
11 Correct 292 ms 3480 KB Output is correct
12 Correct 545 ms 3960 KB Output is correct
13 Correct 315 ms 3428 KB Output is correct
14 Correct 213 ms 3312 KB Output is correct
15 Correct 226 ms 3168 KB Output is correct
16 Correct 821 ms 4608 KB Output is correct
17 Correct 998 ms 5408 KB Output is correct
18 Correct 1044 ms 5336 KB Output is correct
19 Correct 560 ms 5192 KB Output is correct
20 Correct 969 ms 5412 KB Output is correct
21 Correct 970 ms 5428 KB Output is correct
22 Correct 568 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 114 ms 2292 KB Output is correct
8 Correct 152 ms 2396 KB Output is correct
9 Correct 229 ms 4164 KB Output is correct
10 Correct 315 ms 3484 KB Output is correct
11 Correct 292 ms 3480 KB Output is correct
12 Correct 545 ms 3960 KB Output is correct
13 Correct 315 ms 3428 KB Output is correct
14 Correct 213 ms 3312 KB Output is correct
15 Correct 226 ms 3168 KB Output is correct
16 Correct 821 ms 4608 KB Output is correct
17 Correct 998 ms 5408 KB Output is correct
18 Correct 1044 ms 5336 KB Output is correct
19 Correct 560 ms 5192 KB Output is correct
20 Correct 969 ms 5412 KB Output is correct
21 Correct 970 ms 5428 KB Output is correct
22 Correct 568 ms 4444 KB Output is correct
23 Correct 1950 ms 11876 KB Output is correct
24 Correct 2223 ms 11792 KB Output is correct
25 Correct 1600 ms 11500 KB Output is correct
26 Correct 2508 ms 10832 KB Output is correct
27 Correct 2839 ms 10768 KB Output is correct
28 Correct 417 ms 5196 KB Output is correct
29 Correct 391 ms 5288 KB Output is correct
30 Correct 400 ms 5220 KB Output is correct
31 Correct 416 ms 5028 KB Output is correct
32 Correct 2554 ms 10320 KB Output is correct
33 Correct 2759 ms 9732 KB Output is correct
34 Correct 2464 ms 10576 KB Output is correct
35 Correct 2176 ms 10828 KB Output is correct
36 Correct 1533 ms 10320 KB Output is correct
37 Correct 4024 ms 11280 KB Output is correct
38 Correct 2647 ms 9484 KB Output is correct
39 Correct 2577 ms 10580 KB Output is correct
40 Correct 2576 ms 9592 KB Output is correct
41 Correct 4320 ms 10996 KB Output is correct
42 Correct 4454 ms 11504 KB Output is correct