結果

問題 No.3617 Swap
コンテスト
ユーザー ルク
提出日時 2026-08-06 15:30:43
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,594 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,414 ms
コンパイル使用メモリ 391,280 KB
実行使用メモリ 372,776 KB
最終ジャッジ日時 2026-08-06 15:31:57
合計ジャッジ時間 73,873 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
サンプル 0 % AC * 4
小課題1 5 % AC * 3
小課題2 5 % AC * 3 WA * 2
小課題3 15 % AC * 14
小課題4 20 % AC * 15 WA * 6
小課題5 25 % AC * 5 WA * 3
小課題6 10 % AC * 8
小課題7 20 % AC * 35 WA * 21
合計 3 * 30% = 90 点
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:64:9: warning: '#pragma once' in main file [-Wpragma-once-outside-header]
   64 | #pragma once
      |         ^~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
constexpr ll dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr ll dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Init {
  Init() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(15);
  }
} init;
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  os << "[";
  rep(i, vec.size()) {
    os << vec[i];
    if (i != vec.size() - 1) os << ", ";
  }
  os << "]";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vec) {
  os << "[";
  rep(i, vec.size()) {
    os << vec[i];
    if (i != vec.size() - 1) os << ", ";
  }
  os << "]";
  return os;
}

#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;

vl f(vl& a1, vl& a2) {
  vl nex = {};
  rep(i, a1.size()) { nex.push_back(a2[a1[i] - 1]); }
  return nex;
}

const ll BLOCK_SIZE = 500;
vvl cache = {};
vector<pair<ll, ll>> items;
vl getArrM(ll x) {
  vl res = cache[x / BLOCK_SIZE];
  for (int i = x / BLOCK_SIZE * BLOCK_SIZE; i < x; i++) {
    swap(res[items[i].first - 1], res[items[i].second - 1]);
  }
  return res;
};
#pragma once

// @title Timer
struct Timer {
  Timer(int ms) : dur(ms), st(chrono::steady_clock::now()) {}
  bool isTimeOver() const {
    auto cur = chrono::steady_clock::now();
    auto e = chrono::duration_cast<chrono::milliseconds>(cur - st).count();
    return e >= dur;
  }
  int dur;
  chrono::steady_clock::time_point st;
};
int main() {
  Timer timer(1950);
  ll n, m, q;
  cin >> n >> m >> q;
  items.resize(m);
  rep(i, m) cin >> items[i].first >> items[i].second;
  vl last(n);
  rep(i, n) last[i] = i + 1;
  rep(i, m) {
    if (i % BLOCK_SIZE == 0) {
      cache.push_back(last);
    }
    swap(last[items[i].first - 1], last[items[i].second - 1]);
  }
  vvl db = {last};
  rep(i, 60) { db.push_back(f(db.back(), db.back())); }
  rep(i, q) {
    if (timer.isTimeOver()) {
      break;
    }
    ll t, x;
    cin >> t >> x;
    ll rest = t % m;
    ll now = (t - rest) / m;
    vl a(n);
    rep(i, n) a[i] = i + 1;
    rep(i, 60) {
      if (now % 2) {
        a = f(db[i], a);
      }
      now /= 2;
    }
    vl res = getArrM(rest);
    cout << f(res, a)[x - 1] << endl;
  }
  return 0;
}
0