結果
問題 | No.1888 Odd Insertion |
ユーザー | Forested |
提出日時 | 2022-03-25 23:47:17 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 5,680 bytes |
コンパイル時間 | 1,331 ms |
コンパイル使用メモリ | 126,044 KB |
実行使用メモリ | 9,088 KB |
最終ジャッジ日時 | 2024-10-14 08:04:06 |
合計ジャッジ時間 | 7,761 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | AC | 28 ms
7,552 KB |
testcase_07 | AC | 28 ms
7,424 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 30 ms
7,296 KB |
testcase_17 | WA | - |
testcase_18 | AC | 30 ms
7,424 KB |
testcase_19 | AC | 29 ms
7,296 KB |
testcase_20 | AC | 30 ms
7,296 KB |
testcase_21 | AC | 30 ms
7,552 KB |
testcase_22 | AC | 31 ms
7,424 KB |
testcase_23 | AC | 30 ms
7,424 KB |
testcase_24 | AC | 31 ms
7,296 KB |
testcase_25 | AC | 31 ms
7,424 KB |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | AC | 28 ms
8,192 KB |
testcase_30 | AC | 26 ms
7,296 KB |
testcase_31 | AC | 27 ms
7,424 KB |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
ソースコード
// ===== template.hpp ===== #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define OVERRIDE(a, b, c, d, ...) d #define REP2(i, n) for (i32 i = 0; i < (i32) (n); ++i) #define REP3(i, m, n) for (i32 i = (i32) (m); i < (i32) (n); ++i) #define REP(...) OVERRIDE(__VA_ARGS__, REP3, REP2)(__VA_ARGS__) #define PER(i, n) for (i32 i = (i32) (n) - 1; i >= 0; --i) #define ALL(x) begin(x), end(x) using namespace std; using u32 = unsigned int; using u64 = unsigned long long; using u128 = __uint128_t; using i32 = signed int; using i64 = signed long long; using i128 = __int128_t; template <typename T> using Vec = vector<T>; template <typename T> bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } return false; } template <typename T> bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } return false; } [[maybe_unused]] constexpr i32 inf = 1000000100; [[maybe_unused]] constexpr i64 inf64 = 3000000000000000100; struct SetIO { SetIO() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); } } set_io; // ===== template.hpp ===== #ifdef DEBUGF #include "../new_library/other/debug.hpp" #else #define DBG(x) (void) 0 #endif // ===== fenwick_tree.hpp ===== #ifndef FENWICK_TREE_HPP #define FENWICK_TREE_HPP #include <cassert> #include <vector> // ===== operations.hpp ===== #ifndef OPERATIONS_HPP #define OPERATIONS_HPP #include <limits> #include <utility> template <typename T> struct Add { using Value = T; static Value id() { return T(0); } static Value op(const Value &lhs, const Value &rhs) { return lhs + rhs; } static Value inv(const Value &x) { return -x; } }; template <typename T> struct Mul { using Value = T; static Value id() { return Value(1); } static Value op(const Value &lhs, const Value &rhs) { return lhs * rhs; } static Value inv(const Value &x) { return Value(1) / x; } }; template <typename T> struct Min { using Value = T; static Value id() { return std::numeric_limits<T>::max(); } static Value op(const Value &lhs, const Value &rhs) { return std::min(lhs, rhs); } }; template <typename T> struct Max { using Value = T; static Value id() { return std::numeric_limits<Value>::min(); } static Value op(const Value &lhs, const Value &rhs) { return std::max(lhs, rhs); } }; template <typename T> struct Xor { using Value = T; static Value id() { return T(0); } static Value op(const Value &lhs, const Value &rhs) { return lhs ^ rhs; } static Value inv(const Value &x) { return x; } }; template <typename Monoid> struct Reversible { using Value = std::pair<typename Monoid::Value, typename Monoid::Value>; static Value id() { return Value(Monoid::id(), Monoid::id()); } static Value op(const Value &v1, const Value &v2) { return Value( Monoid::op(v1.first, v2.first), Monoid::op(v2.second, v1.second)); } }; #endif // ===== operations.hpp ===== template <typename CommutativeGroup> class FenwickTree { public: using Value = typename CommutativeGroup::Value; private: std::vector<Value> data; public: FenwickTree(std::size_t n) : data(n, CommutativeGroup::id()) {} void add(std::size_t idx, const Value &x) { assert(idx < data.size()); for (; idx < data.size(); idx |= idx + 1) { data[idx] = CommutativeGroup::op(data[idx], x); } } Value sum(std::size_t r) const { assert(r <= data.size()); Value ret = CommutativeGroup::id(); for (; r > 0; r &= r - 1) { ret = CommutativeGroup::op(ret, data[r - 1]); } return ret; } Value sum(std::size_t l, std::size_t r) const { assert(l <= r && r <= data.size()); return CommutativeGroup::op(sum(r), CommutativeGroup::inv(sum(l))); } }; #endif // ===== fenwick_tree.hpp ===== int main() { i32 n; cin >> n; Vec<i32> p(n); REP(i, n) { cin >> p[i]; --p[i]; } Vec<i32> pos(n); REP(i, n) { pos[p[i]] = i; } Vec<i32> ord; ord.reserve(n); i32 last = n; i32 trouble_min_pos = n; FenwickTree<Add<i32>> fw2(n); PER(i, n) { i32 po = pos[i] - fw2.sum(pos[i]); fw2.add(pos[i], 1); if (pos[i] < trouble_min_pos && po % 2 == 0) { ord.emplace_back(i); for (i32 j = last - 1; j > i; --j) { ord.emplace_back(j); } last = i; trouble_min_pos = n; continue; } chmin(trouble_min_pos, pos[i]); } if (last != 0) { cout << "No\n"; exit(0); } DBG(ord); FenwickTree<Add<i32>> fw3(n); Vec<pair<i32, i32>> ans; ans.reserve(n); for (i32 i : ord) { i32 po = pos[i] - fw3.sum(pos[i]); if (po % 2) { cout << "No\n"; exit(0); } fw3.add(pos[i], 1); ans.emplace_back(i, po); } /*reverse(ALL(ans)); cout << "Yes\n"; for (auto [i, po] : ans) { cout << i + 1 << ' ' << po + 1 << '\n'; }*/ exit(1); }