This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 3e5+2;
int n,d,a[NMAX],aib[NMAX],dp[NMAX];
map<int, int> mp;
void update(int pos, int val){
for(int i = pos; i < NMAX; i += (i&-i)){
aib[i] = max(aib[i], val);
}
}
int query(int pos){
int ans = 0;
for(int i = pos; i > 0; i -= (i&-i)){
ans = max(ans, aib[i]);
}
return ans;
}
int main()
{
cin >> n >> d;
for(int i = 1; i <= n; i++){
cin >> a[i];
mp[a[i]] = i;
}
int cnt = 0;
for(auto &it: mp){
it.second = ++cnt;
}
for(int i = 1; i <= n; i++){
a[i] = mp[a[i]];
}
for(int i = 1; i <= n; i++){
dp[i] = max(dp[i], 1+query(a[i]-1));
update(a[i], dp[i]);
}
cout << dp[n];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |