Submission #570257

#TimeUsernameProblemLanguageResultExecution timeMemory
570257gg123_peMoney (IZhO17_money)C++14
100 / 100
1485 ms61936 KiB
#include <bits/stdc++.h> using namespace std; #define f(i,a,b) for(int i = a; i < b; i++) const int N = 1e6 + 6; int n, a[N], dp[N]; set <int> s; int main(){ cin >> n; f(i,1,n+1) cin >> a[i]; a[n+1] = N; int id = 0; s.insert(0); f(i,1,n+1){ dp[i] = 1; if(a[i] > a[i+1]) break; } while(id <= n){ while(id <= n and a[id] <= a[id+1]) s.insert(a[id]), id++; s.insert(a[id++]); f(i,id,n+1){ s.insert(N); auto it = s.lower_bound(a[i]); it = prev(it); s.erase(N); int x = *it, j; j = lower_bound(a+id,a+i+1,x) - a; dp[i] = dp[j-1] + 1; if(a[i] > a[i+1]) break; } } cout << dp[n] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...