답안 #887364

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887364 2023-12-14T10:05:04 Z abcvuitunggio 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
100 / 100
3336 ms 14456 KB
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
const int sz=387,sz2=300,maxN=150000;
int n,l,x[maxN+1],idx[maxN+1],q,pos[maxN+1];
pair <int, int> nxt[maxN/sz+1][sz+sz2+1];
vector <int> v[maxN/sz+1];
void calc(int k){
    if (v[k].empty())
        return;
    int j=v[k].size()-1;
    for (int i=j;i>=0;i--){
        while (x[v[k][i]]+l<x[v[k][j]])
            j--;
        if (j==v[k].size()-1)
            nxt[k][i]={i,0};
        else{
            j++;
            nxt[k][i]={nxt[k][j].first,nxt[k][j].second+1};
        }
    }
}
void init(int N, int L, int X[]){
    n=N,l=L;
    for (int i=0;i<n;i++){
        x[i]=X[i];
        idx[i]=i;
    }
    sort(idx,idx+n,[](int i, int j){return x[i]<x[j];});
    for (int i=0;i*sz<n;i++){
        v[i].clear();
        for (int j=i*sz;j<min(i*sz+sz,n);j++){
            v[i].push_back(idx[j]);
            pos[idx[j]]=i;
        }
        calc(i);
    }
}
void reinit(){
    int j=0;
    for (int i=0;i*sz<n;i++){
        for (int k:v[i]){
            idx[j]=k;
            j++;
        }
    }
    for (int i=0;i*sz<n;i++){
        v[i].clear();
        for (int j=i*sz;j<min(i*sz+sz,n);j++){
            v[i].push_back(idx[j]);
            pos[idx[j]]=i;
        }
        calc(i);
    }
}
int update(int i, int y){
    q++;
    if (q%sz2==0)
        reinit();
    vector <int> tmp;
    int c=0;
    for (int j:v[pos[i]]){
        if (j!=i||c)
            tmp.push_back(j);
        else
            c=1;
    }
    swap(tmp,v[pos[i]]);
    calc(pos[i]);
    tmp.clear();
    x[i]=y;
    int newpos=-1;
    for (int j=0;j*sz<n;j++){
        int l=(j?x[v[j-1].back()]:-1),r=(j*sz+sz<n&&!v[j+1].empty()?x[v[j+1][0]]:1000000001);
        if (l<=y&&y<=r){
            newpos=j;
            break;
        }
    }
    pos[i]=newpos;
    c=0;
    for (int j:v[newpos]){
        if (x[j]>=y&&!c){
            tmp.push_back(i);
            c=1;
        }
        tmp.push_back(j);
    }
    if (!c)
        tmp.push_back(i);
    swap(v[newpos],tmp);
    calc(newpos);
    int j=0,cur=0,res=0,block=0;
    while (true){
        res+=nxt[block][cur].second;
        cur=nxt[block][cur].first;
        res++;
        j=max(j,block+1);
        while (j<=(n-1)/sz){
            if (v[j].empty()||x[v[j].back()]<=x[v[block][cur]]+l){
                j++;
                continue;
            }
            break;
        }
        if (j>(n-1)/sz)
            break;
        int lo=0,hi=v[j].size()-1,kq=-1;
        while (lo<=hi){
            int mid=(lo+hi)>>1;
            if (x[v[j][mid]]>x[v[block][cur]]+l){
                kq=mid;
                hi=mid-1;
            }
            else
                lo=mid+1;
        }
        cur=kq;
        block=j;
    }
    return res;
}

Compilation message

elephants.cpp: In function 'void calc(int)':
elephants.cpp:15:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         if (j==v[k].size()-1)
      |             ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10840 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10840 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10840 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 238 ms 10920 KB Output is correct
8 Correct 246 ms 10960 KB Output is correct
9 Correct 309 ms 11352 KB Output is correct
10 Correct 253 ms 11116 KB Output is correct
11 Correct 235 ms 11116 KB Output is correct
12 Correct 510 ms 11124 KB Output is correct
13 Correct 266 ms 11120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10840 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 238 ms 10920 KB Output is correct
8 Correct 246 ms 10960 KB Output is correct
9 Correct 309 ms 11352 KB Output is correct
10 Correct 253 ms 11116 KB Output is correct
11 Correct 235 ms 11116 KB Output is correct
12 Correct 510 ms 11124 KB Output is correct
13 Correct 266 ms 11120 KB Output is correct
14 Correct 282 ms 10844 KB Output is correct
15 Correct 379 ms 11092 KB Output is correct
16 Correct 855 ms 11348 KB Output is correct
17 Correct 900 ms 11228 KB Output is correct
18 Correct 987 ms 11352 KB Output is correct
19 Correct 525 ms 11228 KB Output is correct
20 Correct 881 ms 11092 KB Output is correct
21 Correct 853 ms 11236 KB Output is correct
22 Correct 523 ms 11228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10840 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 238 ms 10920 KB Output is correct
8 Correct 246 ms 10960 KB Output is correct
9 Correct 309 ms 11352 KB Output is correct
10 Correct 253 ms 11116 KB Output is correct
11 Correct 235 ms 11116 KB Output is correct
12 Correct 510 ms 11124 KB Output is correct
13 Correct 266 ms 11120 KB Output is correct
14 Correct 282 ms 10844 KB Output is correct
15 Correct 379 ms 11092 KB Output is correct
16 Correct 855 ms 11348 KB Output is correct
17 Correct 900 ms 11228 KB Output is correct
18 Correct 987 ms 11352 KB Output is correct
19 Correct 525 ms 11228 KB Output is correct
20 Correct 881 ms 11092 KB Output is correct
21 Correct 853 ms 11236 KB Output is correct
22 Correct 523 ms 11228 KB Output is correct
23 Correct 2532 ms 13908 KB Output is correct
24 Correct 2572 ms 13516 KB Output is correct
25 Correct 2061 ms 13692 KB Output is correct
26 Correct 2339 ms 13704 KB Output is correct
27 Correct 2195 ms 13700 KB Output is correct
28 Correct 1004 ms 12880 KB Output is correct
29 Correct 972 ms 12828 KB Output is correct
30 Correct 1004 ms 12884 KB Output is correct
31 Correct 965 ms 12884 KB Output is correct
32 Correct 1636 ms 13700 KB Output is correct
33 Correct 1345 ms 13764 KB Output is correct
34 Correct 2117 ms 13696 KB Output is correct
35 Correct 1481 ms 14456 KB Output is correct
36 Correct 887 ms 13776 KB Output is correct
37 Correct 2638 ms 13960 KB Output is correct
38 Correct 2279 ms 13908 KB Output is correct
39 Correct 1953 ms 13692 KB Output is correct
40 Correct 2085 ms 13652 KB Output is correct
41 Correct 3318 ms 13916 KB Output is correct
42 Correct 3336 ms 13696 KB Output is correct