답안 #547663

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547663 2022-04-11T08:55:28 Z tengiz05 The Potion of Great Power (CEOI20_potion) C++17
38 / 100
773 ms 262144 KB
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif

using namespace std;

/*


6 5 11 4
2 42 1000 54 68 234
0 1
2 0
3 4
3 5
3 5
1 3
5 3
0 5
3 0
1 3
3 5
0 3 4 26
3 0 8 0
0 5 5 1000000000
3 0 11 14


*/

namespace sOlUTiON {
    constexpr int N = 1E5, M = 2E5;
    int n, D;
    int h[N];
    vector<int> f[N];
    vector<vector<int>> a[N];
};
using namespace sOlUTiON;

void init(int _N, int _D, int H[]) {
    n = _N;
    D = _D;
    for (int i = 0; i < n; i++) {
        a[i].push_back({});
        f[i].push_back(0);
        h[i] = H[i];
    }
}

void curseChanges(int U, int A[], int B[]) {
    for (int i = 0; i < U; i++) {
        int u = A[i];
        int v = B[i];
        
        {
            vector<int> &b = a[u].back(), w;
            int j = 0;
            while (j < int(b.size()) && (b[j] != v && h[b[j]] <= h[v]))
                w.push_back(b[j++]);
            
            if (j < int(b.size()) && b[j] == v) {
                j++;
            } else {
                w.push_back(v);
            }
            
            while (j < int(b.size()))
                w.push_back(b[j++]);
            
            a[u].push_back(w);
        }
        {
            vector<int> &b = a[v].back(), w;
            int j = 0;
            while (j < int(b.size()) && (b[j] != u && h[b[j]] <= h[u]))
                w.push_back(b[j++]);
            
            if (j < int(b.size()) && b[j] == u) {
                j++;
            } else {
                w.push_back(u);
            }
            
            while (j < int(b.size()))
                w.push_back(b[j++]);
            
            a[v].push_back(w);
        }
        
        f[u].push_back(i + 1);
        f[v].push_back(i + 1);
    }
}

int question(int x, int y, int v) {
    int p1 = upper_bound(f[x].begin(), f[x].end(), v) - f[x].begin() - 1;
    int p2 = upper_bound(f[y].begin(), f[y].end(), v) - f[y].begin() - 1;
    
    int ans = 1E9;
    
    if (a[x][p1].empty() || a[y][p2].empty())
        return ans;
    
    int j = 0;
    for (int i = 0; i < int(a[x][p1].size()); i++) {
        int t = h[a[x][p1][i]];
        while (j + 1 < int(a[y][p2].size()) && h[a[y][p2][j]] < t)
            j++;
        ans = min(ans, abs(h[a[x][p1][i]] - h[a[y][p2][j]]));
    }
    j = 0;
    for (int i = 0; i < int(a[y][p2].size()); i++) {
        int t = h[a[y][p2][i]];
        while (j + 1 < int(a[x][p1].size()) && h[a[x][p1][j]] < t)
            j++;
        ans = min(ans, abs(h[a[y][p2][i]] - h[a[x][p1][j]]));
    }
    
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5200 KB Output is correct
2 Correct 4 ms 5200 KB Output is correct
3 Correct 4 ms 5200 KB Output is correct
4 Correct 26 ms 12120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 456 ms 41340 KB Output is correct
2 Correct 440 ms 41456 KB Output is correct
3 Correct 254 ms 45508 KB Output is correct
4 Correct 773 ms 223712 KB Output is correct
5 Correct 373 ms 62552 KB Output is correct
6 Runtime error 517 ms 262144 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 438 ms 41312 KB Output is correct
2 Runtime error 488 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 7120 KB Output is correct
2 Correct 49 ms 7540 KB Output is correct
3 Correct 57 ms 7504 KB Output is correct
4 Correct 199 ms 11984 KB Output is correct
5 Correct 161 ms 10824 KB Output is correct
6 Correct 55 ms 6992 KB Output is correct
7 Correct 164 ms 11316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 4 ms 5200 KB Output is correct
3 Correct 4 ms 5200 KB Output is correct
4 Correct 4 ms 5200 KB Output is correct
5 Correct 26 ms 12120 KB Output is correct
6 Correct 456 ms 41340 KB Output is correct
7 Correct 440 ms 41456 KB Output is correct
8 Correct 254 ms 45508 KB Output is correct
9 Correct 773 ms 223712 KB Output is correct
10 Correct 373 ms 62552 KB Output is correct
11 Runtime error 517 ms 262144 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -