Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- using namespace std;
- using ll = long long;
- using ld = long double;
- void cv(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <ll> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- ll inf = pow(2, 31);
- int main()
- {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- int n; cin>>n; vector<ll>a(n); for (ll &x: a) cin>>x;
- vector <ll> dp(n), optA(n+1, inf); optA[0] = -inf;
- for (int i=0;i<n;++i){ //cout<<"i = "<<i<<"\n";
- ll l = 0, r = n+1, m;
- cout<<"i = "<<i<<"\n";
- cout<<"dp\n";
- cv(dp);
- cout<<"optA\n";
- cv(optA);
- while (l + 1 < r){
- m = (l+r) / 2;
- //cout<<"m = "<<m<<"\n";
- if (optA[m] >= a[i]){
- l = m;
- }
- else r = m;
- }
- dp[i] = l;
- optA[dp[i]] = a[i];
- }
- cv(dp);
- cv(optA);
- //cout<<*max_element(dp.begin(), dp.end())<<"\n";
- }
- /*
- 5
- 5 8
- 10 4 1
- 10
- 10 9 8 7 6 5 4 100 2 1
- 7
- 7 6 5 4 10 2 1
- */
Add Comment
Please, Sign In to add comment