Submission #710113

#TimeUsernameProblemLanguageResultExecution timeMemory
710113hpesojMoney (IZhO17_money)C++17
0 / 100
0 ms340 KiB
#include <bits/stdc++.h> #define int long long #define pi pair <int, int> #define ppi pair <pi, int> #define pb push_back #define fi first #define se second #define all(x) x.begin(), x.end() #define debug(x) cout << #x << ": " << x << '\n' using namespace std; const int inf = 1000000000; int n, a[1000005], prefmax[1000005], prefmin[1000005]; set <int> s; signed main(){ ios::sync_with_stdio(0), cin.tie(0); cin >> n; prefmin[0] = inf; for(int i = 1; i <= n; i++){ cin >> a[i]; prefmax[i] = max(prefmax[i-1], a[i]); prefmin[i] = min(prefmin[i-1], a[i]); } s.insert(a[1]); int ans = 1, l = 2; while(a[l] >= a[l-1]){ s.insert(a[l]); l++; } //for(int i = 1; i < l; i++) cout << a[i] << ' '; int i = l, sz = 1, tmpmin = inf, tmpmax = 0; while(i <= n){ //debug(i); tmpmin = min(tmpmin, a[i]), tmpmax = max(tmpmax, a[i]); if(sz != 1){ if(a[i] < a[i-1] or (s.upper_bound(tmpmin) != s.lower_bound(tmpmax))){ ans++, sz = 1; for(int j = l; j < i; j++) s.insert(a[j]); l = i; tmpmin = a[i], tmpmax = a[i]; } else sz++; } else sz++; i++; } ans++; cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...