Submission #1128115

#TimeUsernameProblemLanguageResultExecution timeMemory
1128115VietnowMoney (IZhO17_money)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h> #define yes cout<<"YES\n" #define no cout<<"NO\n" #define int long long #define ff first #define ss second #define pb push_back #define y1 zildjian #define left radio #define right head using namespace std; const int N = 1e6+10; const int INF = 1e18; const int mod = 1e9+7; const int mod1 = 998244353; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int n; int a[N]; pair<int,int> b[N]; int cnt[N]; void solve(){ cin>>n; for(int i = 1;i<=n;i++){ cin>>a[i]; b[i] = {a[i],i}; } // 4 // 2 // 1 2 // 4 // 2 // 4 // 2 // 1 2 // 4 sort(b+1,b+1+n); int ans = 1; int lst = 1; for(int i = 2;i<=n;i++){ if(a[i]<a[i-1]){ lst = i; ans++; continue; } int l = 0; int r = n+1; while(r>l+1){ int m = (l+r)/2; if(b[m].ff >= a[lst]){ r = m; } else{ l = m; } } // cout<<a[i-1]<<' '<<b[r].ff<<' '<<b[r].ss<<' '<<a[i]<<'\n'; if(b[r].ss < lst){ lst = i; ans++; } } cout<<ans<<'\n'; } signed main(){ // freopen("bootfall.in","r",stdin); // freopen("bootfall.out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(nullptr); // cout.tie(nullptr); int t = 1; // cin>>t; for(int i = 1;i<=t;i++){ // cout<<"Case "<<i<<": "; solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...