답안 #849235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849235 2023-09-14T09:44:41 Z faruk The Potion of Great Power (CEOI20_potion) C++17
17 / 100
3000 ms 48156 KB
#include <bits/stdc++.h>    	
#define all(a) a.begin(), a.end()

using namespace std;

typedef pair<int, int> pii;

const int C = 20;
const int MAXN = 1e5+1;
const int MAXU = 2e5+1;

int n, d, u;
vector<int> heights(MAXN);
vector<pii> changes(MAXU);

int min_dist(vector<int> first, vector<int> second) {
    if (first.empty() || second.empty())
        return 1e9;
    for (int i = 0; i < first.size(); i++)
        first[i] = heights[first[i]];
    for (int i = 0; i <second.size(); i++)
        second[i] = heights[second[i]];
    sort(all(first));
    sort(all(second));

    int pnt1 = 0, pnt2 = 0, out = 2e9;
    while (pnt1 < first.size() and pnt2 < second.size()) {
        out = min(out, abs(first[pnt1] - second[pnt2]));

        if (pnt1 + 1 == first.size())
            pnt2++;
        else if (pnt2 + 1 == second.size())
            pnt1++;
        else if (first[pnt1] < second[pnt2])
            pnt1++;
        else
            pnt2++;
    }
    return out;
}

vector<int> state_tim[MAXN];
vector<vector<int> > state_set[MAXN];
vector<pii> individ_updates[MAXN];
void init(int N, int D, int H[]) {
    n = N;
    for (int i = 0; i < n; i++)
    {
        heights[i] = H[i];
        state_tim[i].push_back(-1);
        state_set[i].push_back(vector<int>());
    }
    d = D;
}

void process(set<int> &set, int &val) {
    if (set.count(val))
        set.erase(val);
    else
        set.insert(val);
}

void curseChanges(int U, int A[], int B[]) {
    u = U;
    for (int i = 0; i < u; i++)
    {
        changes[i].first = A[i], changes[i].second = B[i];
        individ_updates[A[i]].push_back({i, B[i]});
        individ_updates[B[i]].push_back({i, A[i]});
    }
    
    vector<int> time_since_last(n, 0);
    vector<set<int> > guys(n);
    for (int i = 0; i < u; i++) {
        int a = changes[i].first, b = changes[i].second;
        process(guys[a], b);
        process(guys[b], a);
        if (time_since_last[a] == C) {
            state_tim[a].push_back(i);
            state_set[a].push_back(vector<int>(all(guys[a])));
            time_since_last[a] = 0;
        }
        if (time_since_last[b] == C) {
            state_tim[b].push_back(i);
            state_set[b].push_back(vector<int>(all(guys[b])));
            time_since_last[b] = 0;
        }
        time_since_last[a]++;
        time_since_last[b]++;
    }
}

// todo; finish get set
vector<int> get_set(int x, int v) {
    int check_tim_idx = upper_bound(all(state_tim[x]), v) - state_tim[x].begin() - 1;
    set<int> guys(all(state_set[x][check_tim_idx]));
    int idx = lower_bound(all(individ_updates[x]), 
        pii(state_tim[x][check_tim_idx], 1e9)) - individ_updates[x].begin();
    
    for (; idx < individ_updates[x].size() and individ_updates[x][idx].first < v; idx++)
        process(guys, individ_updates[x][idx].second);
    return vector<int>(all(guys));
}

int question(int x, int y, int v) {
    vector<int> x_set = get_set(x, v), y_set = get_set(y, v);
    return min_dist(x_set, y_set);
}

Compilation message

potion.cpp: In function 'int min_dist(std::vector<int>, std::vector<int>)':
potion.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i < first.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
potion.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i = 0; i <second.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
potion.cpp:27:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     while (pnt1 < first.size() and pnt2 < second.size()) {
      |            ~~~~~^~~~~~~~~~~~~~
potion.cpp:27:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     while (pnt1 < first.size() and pnt2 < second.size()) {
      |                                    ~~~~~^~~~~~~~~~~~~~~
potion.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         if (pnt1 + 1 == first.size())
      |             ~~~~~~~~~^~~~~~~~~~~~~~~
potion.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         else if (pnt2 + 1 == second.size())
      |                  ~~~~~~~~~^~~~~~~~~~~~~~~~
potion.cpp: In function 'std::vector<int> get_set(int, int)':
potion.cpp:100:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |     for (; idx < individ_updates[x].size() and individ_updates[x][idx].first < v; idx++)
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9728 KB Output is correct
2 Correct 4 ms 9728 KB Output is correct
3 Correct 4 ms 9560 KB Output is correct
4 Correct 22 ms 21788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 47916 KB Output is correct
2 Correct 286 ms 47572 KB Output is correct
3 Correct 228 ms 28464 KB Output is correct
4 Correct 2024 ms 35600 KB Output is correct
5 Correct 643 ms 38512 KB Output is correct
6 Execution timed out 3025 ms 47628 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 48156 KB Output is correct
2 Correct 2707 ms 43588 KB Output is correct
3 Correct 1274 ms 41372 KB Output is correct
4 Execution timed out 3028 ms 47696 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 11804 KB Output is correct
2 Incorrect 71 ms 11092 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9304 KB Output is correct
2 Correct 4 ms 9728 KB Output is correct
3 Correct 4 ms 9728 KB Output is correct
4 Correct 4 ms 9560 KB Output is correct
5 Correct 22 ms 21788 KB Output is correct
6 Correct 265 ms 47916 KB Output is correct
7 Correct 286 ms 47572 KB Output is correct
8 Correct 228 ms 28464 KB Output is correct
9 Correct 2024 ms 35600 KB Output is correct
10 Correct 643 ms 38512 KB Output is correct
11 Execution timed out 3025 ms 47628 KB Time limit exceeded
12 Halted 0 ms 0 KB -