Submission #410180

#TimeUsernameProblemLanguageResultExecution timeMemory
410180KoDThe Potion of Great Power (CEOI20_potion)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using i32 = std::int32_t; using u32 = std::uint32_t; using i64 = std::int64_t; using u64 = std::uint64_t; using i128 = __int128_t; using u128 = __uint128_t; using isize = std::ptrdiff_t; using usize = std::size_t; class rep { struct Iter { usize itr; constexpr Iter(const usize pos) noexcept : itr(pos) {} constexpr void operator++() noexcept { ++itr; } constexpr bool operator!=(const Iter& other) const noexcept { return itr != other.itr; } constexpr usize operator*() const noexcept { return itr; } }; const Iter first, last; public: explicit constexpr rep(const usize first, const usize last) noexcept : first(first), last(std::max(first, last)) {} constexpr Iter begin() const noexcept { return first; } constexpr Iter end() const noexcept { return last; } }; template <class T> using Vec = std::vector<T>; void main_() { usize N, D, U, Q; std::cin >> N >> D >> U >> Q; Vec<i32> H(N); for (auto& x : H) { std::cin >> x; } Vec<Vec<usize>> snapshot(N); Vec<Vec<std::multiset<i32>>> set(N); Vec<Vec<Vec<std::tuple<usize, i32, bool>>>> log(N); for (const auto i : rep(0, N)) { snapshot[i].push_back(0); set[i].emplace_back(); log[i].emplace_back(); } { Vec<std::multiset<i32>> cur(N); std::map<std::pair<usize, usize>, bool> exist; for (const auto i : rep(0, U)) { usize x, y; std::cin >> x >> y; if (x > y) std::swap(x, y); if (exist[{x, y}] ^= 1) { cur[x].insert(H[y]); log[x].back().emplace_back(i, H[y], true); cur[y].insert(H[x]); log[y].back().emplace_back(i, H[x], true); } else { cur[x].erase(cur[x].find(H[y])); log[x].back().emplace_back(i, H[y], false); cur[y].erase(cur[y].find(H[x])); log[y].back().emplace_back(i, H[x], false); } if (log[x].back().size() == 50) { snapshot[x].push_back(i + 1); set[x].push_back(cur[x]); log[x].push_back({}); } if (log[y].back().size() == 50) { snapshot[y].push_back(i + 1); set[y].push_back(cur[y]); log[y].push_back({}); } } } while (Q--) { usize x, y, u; std::cin >> x >> y >> u; const usize s_x = std::upper_bound(snapshot[x].begin(), snapshot[x].end(), u) - snapshot[x].begin() - 1; std::multiset<i32> set_x = set[x][s_x]; for (const auto [i, v, f] : log[x][s_x]) { if (u <= i) break; if (f) set_x.insert(v); else set_x.erase(set_x.find(v)); } const usize s_y = std::upper_bound(snapshot[y].begin(), snapshot[y].end(), u) - snapshot[y].begin() - 1; std::multiset<i32> set_y = set[y][s_y]; for (const auto [i, v, f] : log[y][s_y]) { if (u <= i) break; if (f) set_y.insert(v); else set_y.erase(set_y.find(v)); } i32 ans = 1000000000; auto itr_x = set_x.begin(); auto itr_y = set_y.begin(); while (itr_x != set_x.end() and itr_y != set_y.end()) { ans = std::min(ans, std::abs(*itr_x - *itr_y)); if (*itr_x <= *itr_y) { ++itr_x; } else { ++itr_y; } } std::cout << ans << std::endl; } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); main_(); return 0; }

Compilation message (stderr)

/usr/bin/ld: /tmp/cckhO30t.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccFa9S7r.o:potion.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cckhO30t.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