結果
問題 | No.3072 Speedrun Query |
ユーザー |
![]() |
提出日時 | 2025-03-21 22:31:01 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 735 ms / 2,500 ms |
コード長 | 2,242 bytes |
コンパイル時間 | 6,504 ms |
コンパイル使用メモリ | 332,236 KB |
実行使用メモリ | 5,888 KB |
最終ジャッジ日時 | 2025-03-21 22:31:20 |
合計ジャッジ時間 | 18,011 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using namespace atcoder;//using mint = modint1000000007;//const int mod = 1000000007;using mint = modint998244353;const int mod = 998244353;const int INF = 1e9;const long long LINF = 1e18;#define rep(i, n) for (int i = 0; i < (n); ++i)#define rep2(i,l,r)for(int i=(l);i<(r);++i)#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)#define all(x) (x).begin(),(x).end()#define allR(x) (x).rbegin(),(x).rend()#define P pair<int,int>template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int n, ka, kb; cin >> n >> ka >> kb;vector<int>a(ka);rep(i, ka)cin >> a[i], a[i]--;vector<int>b(kb);rep(i, kb)cin >> b[i], b[i]--;int ab = INF;rep(i, ka) {//以下の数int count = upper_bound(all(b), a[i]) - b.begin();if (count) {int x = b[count - 1];chmin(ab, abs(a[i] - x));}if (count != kb) {int x = b[count];chmin(ab, abs(a[i] - x));}}auto fa = [&](const int p)->int {int l = -INF, r = INF;int count = upper_bound(all(a), p) - a.begin();if (count) {l = a[count - 1];}if (count != ka) {r = a[count];}if (abs(p - l) < abs(p - r))return l;else return r;};auto fb = [&](const int p)->int {int l = -INF, r = INF;int count = upper_bound(all(b), p) - b.begin();if (count) {l = b[count - 1];}if (count != kb) {r = b[count];}if (abs(p - l) < abs(p - r))return l;else return r;};//cout << ab << endl;int q; cin >> q;while (q--) {int s, t; cin >> s >> t;s--, t--;int ans = abs(t - s);int as, bs, at, bt;as = fa(s);bs = fb(s);at = fa(t);bt = fb(t);//cout << as << " " << bs << " " << at << " " << bt << endl;chmin(ans, abs(as - s) + abs(at - t));chmin(ans, abs(bs - s) + abs(bt - t));chmin(ans, abs(as - s) + abs(bt - t) + ab);chmin(ans, abs(bs - s) + abs(at - t) + ab);cout << ans << endl;}return 0;}