結果
問題 | No.1024 Children in a Row |
ユーザー | noshi91 |
提出日時 | 2020-04-10 22:30:21 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 561 ms / 2,000 ms |
コード長 | 4,116 bytes |
コンパイル時間 | 961 ms |
コンパイル使用メモリ | 85,232 KB |
実行使用メモリ | 50,256 KB |
最終ジャッジ日時 | 2024-09-15 20:59:59 |
合計ジャッジ時間 | 15,310 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 503 ms
44,752 KB |
testcase_11 | AC | 499 ms
44,112 KB |
testcase_12 | AC | 504 ms
44,752 KB |
testcase_13 | AC | 507 ms
45,520 KB |
testcase_14 | AC | 494 ms
43,732 KB |
testcase_15 | AC | 502 ms
45,136 KB |
testcase_16 | AC | 512 ms
44,624 KB |
testcase_17 | AC | 427 ms
45,772 KB |
testcase_18 | AC | 427 ms
45,392 KB |
testcase_19 | AC | 554 ms
50,128 KB |
testcase_20 | AC | 548 ms
50,128 KB |
testcase_21 | AC | 550 ms
50,000 KB |
testcase_22 | AC | 561 ms
50,000 KB |
testcase_23 | AC | 542 ms
50,000 KB |
testcase_24 | AC | 541 ms
50,124 KB |
testcase_25 | AC | 545 ms
49,996 KB |
testcase_26 | AC | 448 ms
50,132 KB |
testcase_27 | AC | 459 ms
49,988 KB |
testcase_28 | AC | 426 ms
50,004 KB |
testcase_29 | AC | 270 ms
50,256 KB |
ソースコード
//#define NDEBUG #include <algorithm> #include <cstddef> #include <cstdint> #include <iostream> #include <utility> #include <vector> namespace n91 { using i8 = std::int_fast8_t; using i32 = std::int_fast32_t; using i64 = std::int_fast64_t; using u8 = std::uint_fast8_t; using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t; using isize = std::ptrdiff_t; using usize = std::size_t; struct rep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr rep(const usize f, const usize l) noexcept : f(std::min(f, l)), l(l) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; struct revrep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr revrep(const usize f, const usize l) noexcept : f(l - 1), l(std::min(f, l) - 1) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; template <class T> auto md_vec(const usize n, const T &value) { return std::vector<T>(n, value); } template <class... Args> auto md_vec(const usize n, Args... args) { return std::vector<decltype(md_vec(args...))>(n, md_vec(args...)); } template <class T> constexpr T difference(const T &a, const T &b) noexcept { return a < b ? b - a : a - b; } template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; } template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; } template <class F> class rec_lambda { F f; public: rec_lambda(F &&f) : f(std::move(f)) {} template <class... Args> auto operator()(Args &&... args) const { return f(*this, std::forward<Args>(args)...); } }; template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); } template <class T> T scan() { T ret; std::cin >> ret; return ret; } constexpr char eoln = '\n'; } // namespace n91 #include <cassert> #include <list> namespace n91 { void main_() { /* std::ios::sync_with_stdio(false); std::cin.tie(nullptr); //*/ const usize n = scan<usize>(); const usize m = scan<usize>(); struct node { usize id; int state; }; std::list<node> list; using itr = typename std::list<node>::iterator; std::vector<itr> pos; for (const usize i : rep(0, n)) { pos.push_back(list.insert(list.end(), {i, 0})); } std::vector<usize> k(m); for (const usize i : rep(0, m)) { const usize a = scan<usize>() - 1; const usize b = scan<usize>() - 1; k[i] = scan<usize>() - 1; list.insert(pos[a], {i, 1}); list.erase(pos[a]); list.insert(std::next(pos[b]), {i, 3}); pos[a] = list.insert(std::next(pos[b]), {a, 0}); list.insert(std::next(pos[b]), {i, 2}); } std::vector<usize> res(n), pre(m), left(m), right(m); { usize c = 0; for (const auto &e : list) { switch (e.state) { case 0: { res[c] = e.id; c += 1; } break; case 1: { pre[e.id] = c; } break; case 2: { left[e.id] = c; } break; case 3: { right[e.id] = c; } break; } } } for (const usize i : rep(0, m)) { usize ans; if (right[i] <= pre[i]) { const usize temp = pre[i]; pre[i] = left[i]; left[i] = right[i]; right[i] = temp; } if (k[i] < pre[i]) { ans = res[k[i]]; } else if (k[i] < pre[i] + (right[i] - left[i])) { ans = res[k[i] + (left[i] - pre[i])]; } else if (k[i] < right[i]) { ans = res[k[i] - (right[i] - left[i])]; } else { ans = res[k[i]]; } std::cout << ans + 1 << eoln; } } } // namespace n91 int main() { n91::main_(); return 0; }