답안 #792999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792999 2023-07-25T12:17:22 Z JakobZorz The Potion of Great Power (CEOI20_potion) C++14
38 / 100
1527 ms 262144 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;
public:
    TTMS(){
        days={-1};
        sets={{}};
    }
    
    void add_new_day(int day){
        days.push_back(day);
        sets.push_back(sets.back());
    }
    
    void insert(int el){
        sets.back().insert(el);
    }
    
    void remove(int el){
        sets.back().erase(sets.back().find(el));
    }
    
    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()};
    }
};


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 Correct 10 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14800 KB Output is correct
2 Correct 13 ms 14792 KB Output is correct
3 Correct 11 ms 14800 KB Output is correct
4 Correct 24 ms 15432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 617 ms 110680 KB Output is correct
2 Correct 608 ms 110816 KB Output is correct
3 Correct 925 ms 216148 KB Output is correct
4 Runtime error 264 ms 262144 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 560 ms 110920 KB Output is correct
2 Runtime error 217 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 18160 KB Output is correct
2 Correct 72 ms 24136 KB Output is correct
3 Correct 117 ms 24800 KB Output is correct
4 Correct 1438 ms 79468 KB Output is correct
5 Correct 1527 ms 63100 KB Output is correct
6 Correct 103 ms 26424 KB Output is correct
7 Correct 1020 ms 69732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14416 KB Output is correct
2 Correct 11 ms 14800 KB Output is correct
3 Correct 13 ms 14792 KB Output is correct
4 Correct 11 ms 14800 KB Output is correct
5 Correct 24 ms 15432 KB Output is correct
6 Correct 617 ms 110680 KB Output is correct
7 Correct 608 ms 110816 KB Output is correct
8 Correct 925 ms 216148 KB Output is correct
9 Runtime error 264 ms 262144 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -