Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <map>
- #include <vector>
- #include <algorithm>
- using namespace std;
- #define M 1048576
- #define treeSize 2097152
- int maxTree[treeSize];
- int dyn[M];
- int tab[M];
- int n;
- void insertion(int where, int val)
- {
- where += M;
- maxTree[where] = val;
- where /=2;
- while (where)
- {
- maxTree[where] = max(maxTree[2*where], maxTree[2*where+1]);
- where /=2;
- }
- }
- int getMax (int a, int b)
- {
- a += M;
- b += M;
- int ans = max(maxTree[a], maxTree[b]);
- while (a/2 != b/2)
- {
- if (a%2 == 0) ans = max(ans,maxTree[a+1]);
- if (b%2 == 1) ans = max(ans,maxTree[b-1]);
- a /= 2;
- b /= 2;
- }
- return ans;
- }
- int main()
- {
- for (int i=0; i!=treeSize; ++i) maxTree[i] = 0;
- cin >> n;
- set <int> St;
- map <int,int> Mp;
- vector <int> V;
- for (int i=0; i!=n; ++i)
- {
- cin >> tab[i];
- St.insert(tab[i]);
- }
- int val = 0;
- for (auto i:St) V.push_back(i);
- sort(V.begin(), V.end());
- for (int i=0; i<V.size(); ++i) Mp[V[i]] = ++val;
- for (int i=0; i!=n; ++i) tab[i] = Mp[tab[i]];
- for (int i=0; i!=n; ++i)
- {
- dyn[i] = getMax(0,tab[i]-1)+1;
- insertion(tab[i], dyn[i]);
- }
- int odp = 0;
- for (int i=0; i!=n; ++i) odp = max(odp,dyn[i]);
- cout << odp;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement