結果
| 問題 |
No.2796 Small Matryoshka
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-28 21:29:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,930 bytes |
| コンパイル時間 | 2,311 ms |
| コンパイル使用メモリ | 207,736 KB |
| 最終ジャッジ日時 | 2025-02-22 00:56:20 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 11 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << " " << p.second; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#define ASSERT(...) 42
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int oo = 1e9;
template<typename T> struct fenwick {
int n;
vector<T> fen;
fenwick(){}
fenwick(int nn) {
fen.resize(nn+1);
n = nn;
}
auto sum(int i) {
T ans = 0;
while(i) {
ans=max(ans,fen[i]);
i&=i-1;
}
return ans;
}
auto query(int r) {
return sum(r+1);
}
void update(int i, T val) {
++i;
while(i<=n) {
fen[i]=max(fen[i],val);
i+= i&(-i);
}
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
vector<array<int,2>> rs(n);
using V = int;
vector<V> c;
for(auto& [r,R] : rs) {
cin >> r >> R;
c.push_back(r);
c.push_back(R);
}
sort(all(c));
c.erase(unique(all(c)),c.end());
auto real = [&](V x) -> int {
auto it = lower_bound(all(c),x);
if(it==c.end() or *it!=x) return -1;
return it-c.begin();
};
fenwick<int> fen(c.size());
sort(all(rs));
int res=0;
for(auto [r,R] : rs) {
r = real(r),R = real(R);
int ans = fen.query(r);
res=max(res,ans+1);
fen.update(R,ans+1);
}
cout << n-res << '\n';
}