답안 #557276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557276 2022-05-05T05:17:05 Z hoanghq2004 The Potion of Great Power (CEOI20_potion) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e5 + 10;

int n, m, q, D, a[N], ord[N];
int p[N];
set <int> g[N];
vector <pair <int, set <int> > > H[N];
vector <pair <int, int> > dta[N];

int flip(set <int>& s, int x) {
    if (s.find(x) == s.end()) {
        s.insert(x);
        return 1;
    }
    s.erase(x);
    return 0;
}

int cur[N];
const int C = 100;

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    cin >> n >> D >> m >> q;
    vector <pair <int, int> > s = {{-1, -1}};
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) p[i] = i;
    sort(p, p + n, [&](int u, int v) {
        return a[u] < a[v];
    });
    sort(a, a + n);
    for (int i = 0; i < n; ++i) ord[p[i]] = i;
    for (int i = 1; i <= m; ++i) {
        int u, v;
        cin >> u >> v;
        u = ord[u], v = ord[v];
        s.push_back({u, v});
    }
    for (int i = 1; i <= m; ++i) {
        auto [u, v] = s[i];
        dta[u].push_back({i, v});
        dta[v].push_back({i, u});
        flip(g[u], v);
        flip(g[v], u);

        ++cur[u], ++cur[v];
        if (cur[u] == C) {
            H[u].push_back({i, g[u]});
            cur[u] = 0;
        }
        if (cur[v] == C) {
            H[v].push_back({i, g[v]});
            cur[u] = 0;
        }
    }
    while (q--) {
        int u, v, id;
        cin >> u >> v >> id;
        u = ord[u], v = ord[v];

        auto work = [&](int u, vector <int>& s) {
            set <int> cur;
            int last = 0;
            if (s.size() && id > H[u][0].first) {
                int L = 0, R = H[u].size() - 1;
                while (L < R) {
                    int mid = L + R >> 1;
                    if (H[u][mid].first > id) R = mid - 1;
                    else L = mid;
                }
                cur = H[u][L].second;
                last = H[u][L].first + 1;
            }
            int L = 0, R = dta[u].size() - 1;
            while (L < R) {
                int mid = L + R >> 1;
                if (dta[u][mid].first <= last) L = mid + 1;
                else R = mid;
            }
            for (int i = L; i < dta[u].size() && dta[u][i].first <= id; ++i) flip(cur, dta[u][i].second);
            for (auto x: cur) s.push_back(a[x]);
            return s;
        };
        vector <int> cur[2];
        work(u, cur[0]);
        work(v, cur[1]);
        int ans = 1e9;
        int i = 0, j = 0;
        while (i < cur[0].size() && j < cur[1].size()) {
            ans = min(ans, abs(cur[0][i] - cur[1][j]));
            if (cur[0][i] < cur[1][j]) ++i;
            else ++j;
        }
        cout << ans << endl;
    }
}

Compilation message

potion.cpp: In function 'int main()':
potion.cpp:51:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |         auto [u, v] = s[i];
      |              ^
potion.cpp: In lambda function:
potion.cpp:78:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   78 |                     int mid = L + R >> 1;
      |                               ~~^~~
potion.cpp:87:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   87 |                 int mid = L + R >> 1;
      |                           ~~^~~
potion.cpp:91:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |             for (int i = L; i < dta[u].size() && dta[u][i].first <= id; ++i) flip(cur, dta[u][i].second);
      |                             ~~^~~~~~~~~~~~~~~
potion.cpp: In function 'int main()':
potion.cpp:100:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |         while (i < cur[0].size() && j < cur[1].size()) {
      |                ~~^~~~~~~~~~~~~~~
potion.cpp:100:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |         while (i < cur[0].size() && j < cur[1].size()) {
      |                                     ~~^~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccYZ4vW6.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccXTaTT5.o:potion.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccYZ4vW6.o: in function `main':
grader.cpp:(.text.startup+0xec): undefined reference to `init(int, int, int*)'
/usr/bin/ld: grader.cpp:(.text.startup+0x184): undefined reference to `curseChanges(int, int*, int*)'
/usr/bin/ld: grader.cpp:(.text.startup+0x1d9): undefined reference to `question(int, int, int)'
collect2: error: ld returned 1 exit status