提出 #66777575


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<typename T>
ostream& operator<<(ostream &o, vector<T> v) {
  for (int i = 0; i < v.size(); i++)
    o << v[i] << (i+1<v.size()?" ":"");
  return o;
}

const int iinf = 1e9+7;
const ll inf = 1e18+7;

using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
using ull = unsigned long long;
using i128 = __int128_t;

template <typename T>
struct SegTree {
  using F = function<T(T, T)>;
  int n;
  F f;
  T ti;
  vector<T> dat;
  SegTree() {}
  SegTree(F f, T ti,unsigned int num) : f(f), ti(ti) {
    n = max(int(__bit_ceil(num)), 1);
    dat.assign(n << 1, ti);
  }
  SegTree(F f,T ti,vector<T>&v):SegTree(f,ti,v.size()){
    for (int i = 0; i < v.size(); i++)
      dat[n + i] = v[i];
    for(int i=n-1;i;i--) dat[i]=f(dat[i*2], dat[i*2+1]);
  }
  void set_val(int k, T x) {
    k += n;
    dat[k] = f(dat[k], x);
    while(k >>= 1) dat[k] = f(dat[k*2], dat[k*2+1]);
  }
  T query(int a, int b) {
    if (a >= b) return ti;
    T vl = ti, vr = ti;
    for (int l=a+n, r=b+n; l<r; l>>=1, r>>=1) {
      if (l & 1) vl = f(vl, dat[l++]);
      if (r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};

int main() {
  cin.tie(0)->sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pll> ab(n);
  for (int i = 0; i < n; i++) {
    cin >> ab[i].first >> ab[i].second;
    ab[i].first--;
    ab[i].second--;
    if (ab[i].first > ab[i].second) swap(ab[i].first, ab[i].second);
  }
  for (int i = 0; i < n; i++) {
    ab.emplace_back(ab[i].first+2*n, ab[i].second+2*n);
    ab.emplace_back(ab[i].second, ab[i].first+2*n);
  }
  SegTree<ll> seg([&](ll a, ll b) { return max(a, b); }, 0LL, n*4);
  sort(ab.begin(), ab.end(), [&](auto a, auto b) {
    if (a.first == b.first) {
      return a.second < b.second;
    } else {
      return a.first > b.first;
    }
  });
  int ans = 0;
  for (int i = 0; i < n*3; i++) {
    int v = seg.query(0, ab[i].second + 1) + 1;
    // cout << i << " " << ab[i].first << " " << ab[i].second << " " << v << endl;
    seg.set_val(ab[i].second, v);
    ans = max(ans, v);
  }
  cout << ans << endl;
}

提出情報

提出日時
問題 G - Longest Chord Chain
ユーザ Yu_212
言語 C++ 23 (gcc 12.2)
得点 575
コード長 2249 Byte
結果 AC
実行時間 221 ms
メモリ 28872 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 575 / 575
結果
AC × 3
AC × 30
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 217 ms 28776 KiB
random_02.txt AC 210 ms 28472 KiB
random_03.txt AC 221 ms 28708 KiB
random_04.txt AC 30 ms 8812 KiB
random_05.txt AC 216 ms 28872 KiB
random_06.txt AC 83 ms 15564 KiB
random_07.txt AC 212 ms 28788 KiB
random_08.txt AC 118 ms 16980 KiB
random_09.txt AC 214 ms 28804 KiB
random_10.txt AC 65 ms 14820 KiB
random_11.txt AC 218 ms 28772 KiB
random_12.txt AC 190 ms 27904 KiB
random_13.txt AC 211 ms 28648 KiB
random_14.txt AC 139 ms 25868 KiB
random_15.txt AC 216 ms 28732 KiB
random_16.txt AC 174 ms 27424 KiB
random_17.txt AC 217 ms 28796 KiB
random_18.txt AC 39 ms 9432 KiB
random_19.txt AC 211 ms 28704 KiB
random_20.txt AC 202 ms 28428 KiB
random_21.txt AC 1 ms 3432 KiB
random_22.txt AC 162 ms 28700 KiB
random_23.txt AC 161 ms 28748 KiB
random_24.txt AC 159 ms 28792 KiB
random_25.txt AC 160 ms 28684 KiB
random_26.txt AC 157 ms 28692 KiB
random_27.txt AC 157 ms 28788 KiB
sample_01.txt AC 1 ms 3464 KiB
sample_02.txt AC 1 ms 3416 KiB
sample_03.txt AC 1 ms 3444 KiB