Submission #793081

# Submission time Handle Problem Language Result Execution time Memory
793081 2023-07-25T13:40:15 Z JakobZorz The Potion of Great Power (CEOI20_potion) C++17
17 / 100
3000 ms 50108 KB
#include<iostream>
#include<vector>
#include<unordered_set>
using namespace std;
typedef long long ll;
const int TREE_SIZE=1<<30;

vector<int>elements;

struct Node{
    int val;
    int ch1,ch2;
};

Node nodes[1000000];
int curr_node=1;

void collect_fn(int node,int l,int r){
    if(l==r-1){
        if(nodes[node].val!=0)
            elements.push_back(l);
        return;
    }
    int m=(l+r)/2;
    if(nodes[node].ch1!=0)
        collect_fn(nodes[node].ch1,l,m);
    if(nodes[node].ch2!=0)
        collect_fn(nodes[node].ch2,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){
        nodes[node].ch1=nodes[old_node].ch1;
        nodes[node].ch2=nodes[old_node].ch2;
        nodes[node].val=nodes[old_node].val;
    }
    
    if(l==r-1){
        nodes[node].val+=q;
        return node;
    }
    
    int m=(l+r)/2;
    nodes[node].ch1=insert_fn(nodes[node].ch1,x,q,l,m);
    nodes[node].ch2=insert_fn(nodes[node].ch2,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 i=0;
        while(i<(int)days.size()-1&&days[i+1]<=day)
            i++;
        return collect(sets[i]);
    }
};


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 12 ms 11216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12080 KB Output is correct
2 Correct 17 ms 12028 KB Output is correct
3 Correct 12 ms 11984 KB Output is correct
4 Correct 21 ms 12820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 84 ms 50108 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 86 ms 50088 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 82 ms 19108 KB Output is correct
2 Correct 393 ms 18904 KB Output is correct
3 Correct 721 ms 18964 KB Output is correct
4 Execution timed out 3083 ms 19060 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 11216 KB Output is correct
2 Correct 11 ms 12080 KB Output is correct
3 Correct 17 ms 12028 KB Output is correct
4 Correct 12 ms 11984 KB Output is correct
5 Correct 21 ms 12820 KB Output is correct
6 Runtime error 84 ms 50108 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -