Submission #1303961

#TimeUsernameProblemLanguageResultExecution timeMemory
1303961duchieulcMoney (IZhO17_money)C++20
100 / 100
907 ms55228 KiB
#include <bits/stdc++.h> #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define F first #define S second #define pb push_back using namespace std; typedef long long ll; typedef pair<ll,ll> pll; const ll MAX = 1e6+7; const ll MOD = 1e9+7; ll n, a[MAX]; set <ll> s; bool check(ll a, ll b) { auto r = s.upper_bound(a); ll r1 = *r; return b<=r1; } void solve() { cin >> n; for(ll i=1; i<=n; ++i) cin >> a[i]; ll ans = 0; s.insert(0); s.insert(1e6+1); vector <ll> v; a[n+1] = -1; ll m = 1e6+1, M = 0; for(ll i=1; i<=n+1; ++i) { m = min(m, a[i]); M = max(M, a[i]); if(check(m,M) && a[i] >= a[i-1]) v.pb(a[i]); else { ++ ans; for(auto j:v) s.insert(j); v.clear(); m = a[i]; M = a[i]; v.pb(a[i]); } } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //if(fopen("TASK.INP","r")) { // freopen("TASK.INP","r",stdin); // freopen("TASK.OUT","w",stdout); //} solve(); // cerr << "\n" << "Time elapsed: " << TIME << "s\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...