Submission #709374

#TimeUsernameProblemLanguageResultExecution timeMemory
709374jiahngFinancial Report (JOI21_financial)C++14
0 / 100
46 ms4084 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]; 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; FOR(i,1,N) cin >> A[i]; vpi v; FOR(i,1,N) v.pb(pi(A[i], i)); sort(all(v), greater <pi> ()); FOR(i,1,N) p[i] = i,sz[i] = 1; set <int> st; aFOR(i, v){ auto it = st.lower_bound(i.s); if (it == st.end()) nxt[i.s] = N; else nxt[i.s] = *it - 1; inc[i.s] = 1; if (inc[i.s-1]) join(i.s,i.s-1); if (inc[i.s+1]) join(i.s+1,i.s); int x = fl(i.s); 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...