Submission #709395

#TimeUsernameProblemLanguageResultExecution timeMemory
709395jiahngFinancial Report (JOI21_financial)C++14
48 / 100
132 ms16600 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef pair<int,int> pi; typedef vector <int> vi; typedef vector <pi> vpi; typedef pair<pi, ll> pii; typedef set <ll> si; typedef long double ld; #define f first #define s second #define mp make_pair #define FOR(i,s,e) for(int i=s;i<=int(e);++i) #define DEC(i,s,e) for(int i=s;i>=int(e);--i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i,x) for (auto i: x) #define mem(x,i) memset(x,i,sizeof x) #define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define maxn 200010 #define INF (ll)1e18 typedef pair <vi, int> pvi; typedef pair <int,pi> ipi; typedef vector <pii> vpii; #define DEBUG 0 #define MOD 1000003233 int TC; int N,M,D; int A[maxn],nxt[maxn],sz[maxn]; vi B[maxn]; bool inc[maxn]; int p[maxn],dp[maxn]; int fl(int x){ if (p[x] == x) return x; return p[x] = fl(p[x]); } void join(int a,int b){ a = fl(a); b = fl(b); if (a == b) return; p[a] = b; sz[b] += sz[a]; } void solve(){ cin >> N >> D; vi tmp; FOR(i,1,N){ cin >> A[i]; tmp.pb(A[i]); } sort(all(tmp)); FOR(i,1,N) A[i] = lower_bound(all(tmp), A[i]) - tmp.begin() + 1; FOR(i,1,N) B[A[i]].pb(i); FOR(i,1,N) p[i] = i,sz[i] = 1; set <int> st; DEC(i,N,1){ aFOR(j, B[i]){ auto it = st.upper_bound(j); if (it == st.end()) nxt[j] = N; else nxt[j] = *it - 1; } aFOR(j, B[i]){ inc[j] = 1; if (inc[j-1]) join(j,j-1); if (inc[j+1]) join(j+1,j); int x = fl(j); //assert(fl(x-1) != x); if (sz[x] >= D) st.insert(x); } } dp[N] = 0; DEC(i,N-1,1){ dp[i] = 0; FOR(j,i+1,nxt[i]+D) if (A[j] > A[i]) dp[i] = max(dp[i], dp[j] + 1); } //FOR(i,1,N) cout << dp[i] << ' '; //cout << '\n'; cout << *max_element(dp+1,dp+N+1)+1; } int32_t main(){ fast; solve(); //cin >> TC; //while (TC--) 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...