Submission #916177

# Submission time Handle Problem Language Result Execution time Memory
916177 2024-01-25T12:28:40 Z JakobZorz Dancing Elephants (IOI11_elephants) C++17
26 / 100
9000 ms 12568 KB
#include"elephants.h"
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

const int BUCKET_SIZE=256;
int n,l;
int pos[150000];

struct Bucket{
    vector<int>arr;
    vector<int>num;
    vector<int>pos;
    
    void regen(){
        num.resize(arr.size());
        pos.resize(arr.size());
        for(int i=0;i<(int)arr.size();i++){
            num[i]=0;
            pos[i]=-1;
            for(int i=0;i<(int)arr.size();i++){
                if(arr[i]>pos[i]){
                    num[i]++;
                    pos[i]=arr[i]+l;
                }
            }
        }
    }
    
    void erase(int el){
        auto it=lower_bound(arr.begin(),arr.end(),el);
        arr.erase(it);
        
        regen();
    }
    
    void add(int el){
        auto it=upper_bound(arr.begin(),arr.end(),el);
        arr.insert(it,el);
        
        regen();
    }
    
    pair<int,int>get(int pos){
        int res=0;
        
        for(int i=0;i<(int)arr.size();i++){
            if(arr[i]>pos){
                res++;
                pos=arr[i]+l;
            }
        }
        
        return{res,pos};
    }
};

vector<Bucket>buckets;

void init(int N,int L,int X[]){
    n=N;
    l=L;
    vector<int>vec;
    for(int i=0;i<n;i++){
        pos[i]=X[i];
        vec.push_back(X[i]);
    }
    sort(vec.begin(),vec.end());
    buckets.emplace_back();
    for(int i:vec){
        buckets.back().arr.push_back(i);
        if((int)buckets.back().arr.size()==BUCKET_SIZE){
            buckets.emplace_back();
        }
    }
    
    for(auto&i:buckets)
        i.regen();
}

int update(int i,int y){
    for(auto&b:buckets){
        if(b.arr[0]<=pos[i]&&pos[i]<=b.arr.back()){
            b.erase(pos[i]);
            break;
        }
    }
    pos[i]=y;
    
    int cb=0;
    while(cb<(int)buckets.size()){
        if(!buckets[cb].arr.empty()&&buckets[cb].arr[0]>=y)
            break;
        cb++;
    }
    if(cb)
        cb--;
    
    //cout<<"cb: "<<cb<<"\n";
    buckets[cb].add(y);
    
    int pos=-1,res=0;
    
    for(auto&b:buckets){
        auto r=b.get(pos);
        res+=r.first;
        pos=r.second;
    }
    
    /*cout<<"buckets:\n";
    for(auto&b:buckets){
        for(int i:b.arr)
            cout<<i<<" ";
        cout<<endl;
    }*/
    
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 4 ms 8536 KB Output is correct
5 Correct 4 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 4 ms 8536 KB Output is correct
5 Correct 4 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 5720 ms 9916 KB Output is correct
8 Correct 6606 ms 10056 KB Output is correct
9 Correct 6146 ms 12568 KB Output is correct
10 Execution timed out 9019 ms 12556 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 4 ms 8536 KB Output is correct
5 Correct 4 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 5720 ms 9916 KB Output is correct
8 Correct 6606 ms 10056 KB Output is correct
9 Correct 6146 ms 12568 KB Output is correct
10 Execution timed out 9019 ms 12556 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 4 ms 8536 KB Output is correct
5 Correct 4 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 5720 ms 9916 KB Output is correct
8 Correct 6606 ms 10056 KB Output is correct
9 Correct 6146 ms 12568 KB Output is correct
10 Execution timed out 9019 ms 12556 KB Time limit exceeded
11 Halted 0 ms 0 KB -