結果
| 問題 |
No.2002 Range Swap Query
|
| コンテスト | |
| ユーザー |
Ricky_pon
|
| 提出日時 | 2022-07-08 22:28:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,069 ms / 2,000 ms |
| コード長 | 2,757 bytes |
| コンパイル時間 | 2,446 ms |
| コンパイル使用メモリ | 199,688 KB |
| 最終ジャッジ日時 | 2025-01-30 05:26:14 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:75:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
75 | scanf("%d%d%d", &n, &K, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:78:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
78 | scanf("%d%d", &a[i], &b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:85:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
85 | scanf("%d%d%d", &l, &r, &x);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <vector>
namespace rklib {
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin_non_negative(T &a, const T &b) {
if (a < 0 || a > b) {
a = b;
return true;
}
return false;
}
template <class T>
T div_floor(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a > 0 ? (a - 1) / b + 1 : a / b;
}
} // namespace rklib
#define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second
using namespace std;
using namespace rklib;
using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
struct query {
int l, r, x, idx;
query() {}
query(int l, int r, int x, int i) : l(l), r(r), x(x), idx(i) {}
};
int main() {
int n, K, q;
scanf("%d%d%d", &n, &K, &q);
int a[K], b[K];
rep(i, K) {
scanf("%d%d", &a[i], &b[i]);
--a[i];
--b[i];
}
vector<query> qs(q);
rep(i, q) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
--l;
--x;
qs[i] = {l, r, x, i};
}
constexpr int B = 500;
sort(qs.begin(), qs.end(), [](const query &q1, const query &q2) {
int b1 = q1.l / B, b2 = q2.l / B;
if (b1 == b2) {
return b1 % 2 == 0 ? q1.r < q2.r : q1.r > q2.r;
}
return b1 < b2;
});
int v[n], pos[n];
iota(v, v + n, 0);
iota(pos, pos + n, 0);
int ans[q];
int tl = 0, tr = 0;
for (auto [l, r, x, idx] : qs) {
while (tr < r) {
swap(v[a[tr]], v[b[tr]]);
pos[v[a[tr]]] = a[tr];
pos[v[b[tr]]] = b[tr];
++tr;
}
while (tl > l) {
--tl;
swap(pos[a[tl]], pos[b[tl]]);
v[pos[a[tl]]] = a[tl];
v[pos[b[tl]]] = b[tl];
}
while (tr > r) {
--tr;
swap(v[a[tr]], v[b[tr]]);
pos[v[a[tr]]] = a[tr];
pos[v[b[tr]]] = b[tr];
}
while (tl < l) {
swap(pos[a[tl]], pos[b[tl]]);
v[pos[a[tl]]] = a[tl];
v[pos[b[tl]]] = b[tl];
++tl;
}
ans[idx] = v[x] + 1;
}
rep(i, q) printf("%d\n", ans[i]);
}
Ricky_pon