답안 #793052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793052 2023-07-25T13:02:40 Z JakobZorz The Potion of Great Power (CEOI20_potion) C++14
0 / 100
3000 ms 40604 KB
#include<iostream>
#include<set>
#include<vector>
#include<unordered_set>
using namespace std;
typedef long long ll;
const int TREE_SIZE=1<<20;

vector<int>elements;

struct Node;

Node* insert_fn(Node* old_node,int x,int q);

struct Node{
    int val=0;
    Node*ch1=nullptr,*ch2=nullptr;
    
    void collect_fn(int l,int r){
        if(l==r-1){
            if(val!=0)
                elements.push_back(l);
            return;
        }
        int m=(l+r)/2;
        if(ch1)
            ch1->collect_fn(l,m);
        if(ch2)
            ch2->collect_fn(m,r);
    }
    
    vector<int>collect(){
        elements.clear();
        collect_fn(0,TREE_SIZE);
        return elements;
    }
    
    ~Node(){
        delete ch1;
        delete ch2;
    }
};

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

Node* insert(Node* 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<Node*>sets;
    Node* set;
    multiset<int>mset;
public:
    TTMS(){
        //days={-1};
        //sets={new Node};
        //set=new 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);
        //set=::insert(set,el,1);
        mset.insert(el);
    }
    
    void remove(int el){
        //sets.back()=::insert(sets.back(),el,-1);
        //set=::insert(set,el,-1);
        mset.erase(mset.find(el));
    }
    
    vector<int> get(int day){
        /*int i=0;
        while(i<(int)days.size()-1&&days[i+1]<=day)
            i++;
        return sets[i]->collect();*/
        //return set->collect();
        return {mset.begin(),mset.end()};
    }
};


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);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 10448 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 10656 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 321 ms 40544 KB Output is correct
2 Correct 391 ms 40564 KB Output is correct
3 Correct 135 ms 12876 KB Output is correct
4 Execution timed out 3045 ms 25788 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 260 ms 40604 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 11984 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 10448 KB Incorrect
2 Halted 0 ms 0 KB -