Submission #35766

#TimeUsernameProblemLanguageResultExecution timeMemory
35766funcsrMoney (IZhO17_money)C++14
45 / 100
1500 ms56852 KiB
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> #include <cassert> #include <bitset> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 int N; int A[1000000]; int L[1000000]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N; rep(i, N) cin >> A[i]; L[N-1] = N-1; for (int i=N-2; i>=0; i--) { if (A[i] <= A[i+1]) L[i] = L[i+1]; else L[i] = i; } set<int> vs; vs.insert(1000001); rep(i, N) { int lim = *vs.upper_bound(A[i]); L[i] = upper_bound(A+i, A+L[i]+1, lim) - A - 1; vs.insert(A[i]); } //rep(i, N) cout << L[i] << ",";cout<<"\n"; assert(is_sorted(L, L+N)); int lo = 0, ctr = 0; while (lo < N) { lo = L[lo]+1; ctr++; } cout << ctr << "\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...