結果

問題 No.2242 Cities and Teleporters
ユーザー 👑 emthrmemthrm
提出日時 2023-03-10 23:02:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,465 bytes
コンパイル時間 4,531 ms
コンパイル使用メモリ 273,712 KB
実行使用メモリ 18,480 KB
最終ジャッジ日時 2023-10-18 08:44:18
合計ジャッジ時間 12,536 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 250 ms
17,512 KB
testcase_07 WA -
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 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 246 ms
16,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> h(n), t(n);
  REP(i, n) cin >> h[i];
  REP(i, n) cin >> t[i];
  int q; cin >> q;
  vector<int> a(q), b(q); REP(i, q) cin >> a[i] >> b[i], --a[i], --b[i];
  vector<int> v(n * 2);
  ranges::copy(h, v.begin());
  ranges::copy(t, next(v.begin(), n));
  ranges::sort(v);
  v.erase(unique(ALL(v)), v.end());
  REP(i, n) h[i] = distance(v.begin(), ranges::lower_bound(v, h[i]));
  REP(i, n) t[i] = distance(v.begin(), ranges::lower_bound(v, t[i]));
  // REP(i, n) cout << h[i] << " \n"[i + 1 == n];
  // REP(i, n) cout << t[i] << " \n"[i + 1 == n];
  vector<int> ans(q, -1);
  vector<vector<int>> queries(n);
  REP(i, q) {
    if (h[b[i]] <= t[a[i]]) {
      ans[i] = 1;
    } else {
      queries[a[i]].emplace_back(i);
    }
  }
  vector<int> ord(n);
  iota(ALL(ord), 0);
  ranges::sort(ord, {}, [&](const int i) -> pair<int, int> { return {-t[i], h[i]}; });
  vector<int> seq;
  for (const int i : ord) {
    const int p = ssize(seq) - distance(seq.rbegin(), upper_bound(seq.rbegin(), seq.rend(), t[i]));
    if (p < seq.size()) {
      for (const int id : queries[i]) {
        if (t[seq.front()] < h[b[id]]) continue;
        int lb = 0, ub = p + 1;
        while (ub - lb > 1) {
          const int mid = midpoint(lb, ub);
          (h[b[id]] <= t[seq[mid]] ? lb : ub) = mid;
        }
        ans[id] = p - lb + 2;
      }
    } else {
      seq.clear();
    }
    if (h[i] < t[i]) {
      while (seq.size() >= 2 && h[seq.end()[-2]] <= t[i]) seq.pop_back();
      seq.emplace_back(i);
    }
  }
  REP(i, q) cout << ans[i] << '\n';
  return 0;
}
0