Created
March 9, 2017 01:49
-
-
Save takageymt/3f8f30f6a7b41a65df2bb9417523034f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define int long long | |
#define all(v) begin(v), end(v) | |
#define rep(i, n) for(int i = 0; i < (int)(n); i++) | |
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++) | |
#define min(...) min({__VA_ARGS__}) | |
#define max(...) max({__VA_ARGS__}) | |
template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;} | |
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;} | |
using pint = pair<int, int>; | |
using tint = tuple<int, int, int>; | |
using vint = vector<int>; | |
const int inf = 1LL << 55; | |
const int mod = 1e9 + 7; | |
// Binary Indexed Tree (1 indexed) | |
struct BIT | |
{ | |
vector<int> data; | |
BIT(int n):data(n+1, 0){} | |
int query(int k) | |
{ | |
int ret = 0; | |
while(k > 0) { | |
chmax(ret, data[k]); | |
k -= k & -k; | |
} | |
return ret; | |
} | |
void update(int k, int x) | |
{ | |
while(k < data.size()) { | |
chmax(data[k], x); | |
k += k & -k; | |
} | |
} | |
}; | |
signed main() | |
{ | |
cin.tie(0); | |
ios_base::sync_with_stdio(0); | |
cout << fixed << setprecision(12); | |
int N; | |
cin >> N; | |
vector< pair<int, int> > box; | |
rep(i, N) { | |
int w, h; | |
cin >> w >> h; | |
box.emplace_back(w, -h); | |
} | |
sort(all(box)); | |
int dp[100010] = {}; | |
BIT bit(100010); | |
rep(i, N) { | |
int h = -box[i].second; | |
dp[i] = bit.query(h-1) + 1; | |
bit.update(h, dp[i]); | |
} | |
cout << *max_element(dp, dp + N) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment