Submission #793957

# Submission time Handle Problem Language Result Execution time Memory
793957 2023-07-26T08:19:23 Z JakobZorz The Potion of Great Power (CEOI20_potion) C++14
17 / 100
3000 ms 26472 KB
#include<iostream>
#include<set>
#include<vector>
#include<unordered_set>
using namespace std;
typedef long long ll;

// time travelling multiset
class TTMS{
    vector<int>days;
    //vector<multiset<int>>sets;
    vector<pair<int,int>>changes;
    int curr_day=0;
public:
    TTMS(){
        days={};
        //sets={{}};
    }
    
    void add_new_day(int day){
        //days.push_back(day);
        //sets.push_back(sets.back());
        curr_day=day;
    }
    
    void insert(int el){
        //sets.back().insert(el);
        changes.push_back({el,1});
        days.push_back(curr_day);
    }
    
    void remove(int el){
        //sets.back().erase(sets.back().find(el));
        changes.push_back({el,-1});
        days.push_back(curr_day);
    }
    
    vector<int> get(int day){
        /*int i=0;
        while(i<(int)days.size()-1&&days[i+1]<=day)
            i++;
        return {sets[i].begin(),sets[i].end()};*/
        multiset<int>s;
        for(int i=0;i<(int)changes.size();i++){
            if(days[i]>day)
                break;
            if(changes[i].second==1)
                s.insert(changes[i].first);
            else if(changes[i].second==-1)
                s.erase(s.find(changes[i].first));
        }
        return{s.begin(),s.end()};
    }
};

int get_closest(vector<int>a,vector<int>b){
    int res=1e9;
    int i=0,j=0;
    while(i<(int)a.size()&&j<(int)b.size()){
        res=min(res,abs(a[i]-b[j]));
        if(i<(int)a.size()&&a[i]<=b[j])
            i++;
        else if(j<(int)b.size()&&b[j]<=a[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);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5840 KB Output is correct
2 Correct 3 ms 5840 KB Output is correct
3 Correct 4 ms 6016 KB Output is correct
4 Correct 12 ms 6680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 221 ms 26432 KB Output is correct
2 Correct 285 ms 26472 KB Output is correct
3 Execution timed out 3071 ms 13520 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 221 ms 26384 KB Output is correct
2 Execution timed out 3081 ms 15380 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 6948 KB Output is correct
2 Correct 157 ms 6340 KB Output is correct
3 Correct 1484 ms 6180 KB Output is correct
4 Correct 1617 ms 6756 KB Output is correct
5 Correct 1733 ms 6916 KB Output is correct
6 Correct 115 ms 6608 KB Output is correct
7 Execution timed out 3029 ms 6408 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5840 KB Output is correct
3 Correct 3 ms 5840 KB Output is correct
4 Correct 4 ms 6016 KB Output is correct
5 Correct 12 ms 6680 KB Output is correct
6 Correct 221 ms 26432 KB Output is correct
7 Correct 285 ms 26472 KB Output is correct
8 Execution timed out 3071 ms 13520 KB Time limit exceeded
9 Halted 0 ms 0 KB -