結果
| 問題 |
No.2796 Small Matryoshka
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-28 21:52:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 459 ms / 2,000 ms |
| コード長 | 826 bytes |
| コンパイル時間 | 2,369 ms |
| コンパイル使用メモリ | 210,476 KB |
| 最終ジャッジ日時 | 2025-02-22 01:03:14 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll INF = 1e18;
void solve() {
ll n;
cin >> n;
set<ll> st;
st.insert(INF);
map<ll, set<pair<ll, ll>>> mp;
rep(i, n) {
ll l, r;
cin >> l >> r;
st.insert(l);
mp[l].emplace(r, i);
}
ll ans = 0;
while (st.size() > 1) {
ans++;
ll now = 0;
for (;;) {
ll nex = *st.lower_bound(now);
if (nex == INF)
break;
auto iter = mp[nex].begin();
now = iter->first;
mp[nex].erase(iter);
if (mp[nex].size() == 0)
st.erase(nex);
}
}
ans--;
cout << ans << '\n';
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
int T = 1;
for (int t = 0; t < T; t++) {
solve();
}
return 0;
}