Submission #793091

# Submission time Handle Problem Language Result Execution time Memory
793091 2023-07-25T13:48:04 Z JakobZorz The Potion of Great Power (CEOI20_potion) C++14
35 / 100
3000 ms 170328 KB
#include<iostream>
#include<vector>
#include<unordered_set>
using namespace std;
typedef long long ll;
const int TREE_SIZE=1<<30;
const int NUM_NODES=1e8;

vector<int>elements;

int val[NUM_NODES];
int ch1[NUM_NODES];
int ch2[NUM_NODES];
int curr_node=1;

void collect_fn(int node,int l,int r){
    if(l==r-1){
        if(val[node]!=0)
            elements.push_back(l);
        return;
    }
    int m=(l+r)/2;
    if(ch1[node]!=0)
        collect_fn(ch1[node],l,m);
    if(ch2[node]!=0)
        collect_fn(ch2[node],m,r);
}

vector<int>collect(int node){
    elements.clear();
    collect_fn(node,0,TREE_SIZE);
    return elements;
}

int insert_fn(int old_node,int x,int q,int l,int r){
    if(x<l||r<=x)
        return old_node;
    
    int node=curr_node++;
    if(old_node){
        ch1[node]=ch1[old_node];
        ch2[node]=ch2[old_node];
        val[node]=val[old_node];
    }
    
    if(l==r-1){
        val[node]+=q;
        return node;
    }
    
    int m=(l+r)/2;
    ch1[node]=insert_fn(ch1[node],x,q,l,m);
    ch2[node]=insert_fn(ch2[node],x,q,m,r);
    
    return node;
}

int insert(int old_node,int x,int q){
    return insert_fn(old_node,x,q,0,TREE_SIZE);
}

// time travelling multiset
class TTMS{
    vector<int>days;
    vector<int>sets;
public:
    TTMS(){
        days={-1};
        sets={curr_node++};
    }
    
    void add_new_day(int day){
        days.push_back(day);
        sets.push_back(sets.back());
    }
    
    void insert(int el){
        sets.back()=::insert(sets.back(),el,1);
    }
    
    void remove(int el){
        sets.back()=::insert(sets.back(),el,-1);
    }
    
    vector<int> get(int day){
        int l=0,r=(int)days.size();
        while(l!=r-1){
            int m=(l+r)/2;
            if(day<days[m])
                r=m;
            else
                l=m;
        }
        return collect(sets[l]);
    }
};


int get_closest(vector<int>a,vector<int>b){
    int res=1e9;
    for(int i:a)
        for(int j:b){
            res=min(res,abs(i-j));
        }
    return res;
}


int n;
int heights[100000];
TTMS ttms[100000];

void init(int N, int D, int H[]) {
    n=N;
    for(int i=0;i<n;i++)
        heights[i]=H[i];
}

ll to(int a,int b){
    if(a<b)
        swap(a,b);
    return a+((ll)b<<32);
}

void curseChanges(int U, int A[], int B[]) {
    unordered_set<ll>conns;
    for(int day=0;day<U;day++){
        int a=A[day],b=B[day];
        ll conn=to(a,b);
        ttms[a].add_new_day(day+1);
        ttms[b].add_new_day(day+1);
        if(conns.find(conn)==conns.end()){
            conns.insert(conn);
            ttms[a].insert(heights[b]);
            ttms[b].insert(heights[a]);
        }else{
            conns.erase(conn);
            ttms[a].remove(heights[b]);
            ttms[b].remove(heights[a]);
        }
    }
}

int question(int x, int y, int v) {
    vector<int>a=ttms[x].get(v);
    vector<int>b=ttms[y].get(v);
    
    return get_closest(a,b);
    return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12056 KB Output is correct
2 Correct 11 ms 12112 KB Output is correct
3 Correct 11 ms 12112 KB Output is correct
4 Correct 20 ms 12856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 758 ms 170328 KB Output is correct
2 Correct 755 ms 170324 KB Output is correct
3 Correct 503 ms 162992 KB Output is correct
4 Execution timed out 3082 ms 166960 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 560 ms 170312 KB Output is correct
2 Correct 386 ms 163536 KB Output is correct
3 Correct 520 ms 164308 KB Output is correct
4 Correct 440 ms 164244 KB Output is correct
5 Correct 583 ms 170208 KB Output is correct
6 Correct 445 ms 164232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 19136 KB Output is correct
2 Correct 393 ms 18940 KB Output is correct
3 Correct 687 ms 18956 KB Output is correct
4 Execution timed out 3088 ms 19100 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11216 KB Output is correct
2 Correct 11 ms 12056 KB Output is correct
3 Correct 11 ms 12112 KB Output is correct
4 Correct 11 ms 12112 KB Output is correct
5 Correct 20 ms 12856 KB Output is correct
6 Correct 758 ms 170328 KB Output is correct
7 Correct 755 ms 170324 KB Output is correct
8 Correct 503 ms 162992 KB Output is correct
9 Execution timed out 3082 ms 166960 KB Time limit exceeded
10 Halted 0 ms 0 KB -