結果

問題 No.2796 Small Matryoshka
ユーザー maeshunmaeshun
提出日時 2024-06-29 12:22:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,338 bytes
コンパイル時間 4,857 ms
コンパイル使用メモリ 271,252 KB
実行使用メモリ 18,308 KB
最終ジャッジ日時 2024-06-29 12:22:15
合計ジャッジ時間 8,061 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 36 ms
5,376 KB
testcase_06 AC 215 ms
17,656 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 170 ms
16,796 KB
testcase_09 AC 218 ms
18,180 KB
testcase_10 AC 241 ms
18,308 KB
testcase_11 AC 216 ms
18,184 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

P op(P a, P b) {
    return max(a, b);
}

P e() {
    return  {-1e18,-1};
}

int main()
{
    int n;
    cin >> n;
    vector<P> vs(n);
    rep(i,n) {
        cin >> vs[i].second >> vs[i].first;
    }
    sort(vs.begin(),vs.end());
    segtree<P, op, e> seg(n);
    rep(i,n) seg.set(i, {vs[i].second,i});
    ll ans = 0;
    vector<ll> y;
    rep(i,n) y.push_back(vs[i].first);
    vector<ll> used(n);
    dbg(y);
    for(int i=n-1;i>=0;i--) {
        if(used[i]) continue;
        ans++;
        int now = i;
        while(true) {
            if(now==-1 || used[now]) break;
            used[now] = 1;
            dbg(vs[now].second);
            int it = upper_bound(y.begin(),y.end(),vs[now].second) - y.begin();
            ll val = seg.prod(0, it).second;
            now = val;
            dbg(val);
        }
    }
    cout << ans-1 << endl;
    return 0;
}
0