제출 #483726

#제출 시각아이디문제언어결과실행 시간메모리
483726minhcoolFinancial Report (JOI21_financial)C++17
31 / 100
425 ms20348 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define mp make_pair #define foru(i, l, r) for(int i = l; i <= r; i++) #define ford(i, r, l) for(int i = r; i >= l; i--) #define eb emplace_back typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int N = 3e5 + 5, MAXN = 1e7 + 5; const long long oo = 1e9 + 7, mod = 1e9 + 7; int n, d; ii a[N]; int IT[N << 2], dp[N]; set<ii> se;// segments with length >= d void upd(int id, int l, int r, int pos, int vl){ if(l == r){ IT[id] = vl; return; } int mid = (l + r) >> 1; if(pos <= mid) upd(id << 1, l, mid, pos, vl); else upd(id << 1 | 1, mid + 1, r, pos, vl); IT[id] = max(IT[id << 1], IT[id << 1 | 1]); } int get(int id, int l, int r, int L, int R){ if(l > R || r < L || l > r) return 0; if(l >= L && r <= R) return IT[id]; int mid = (l + r) >> 1; return max(get(id << 1, l, mid, L, R), get(id << 1 | 1, mid + 1, r, L, R)); } bool cmp(ii a, ii b){ if(a.fi != b.fi) return a.fi < b.fi; else return a.se > b.se; } void er(int temp){ set<ii>::iterator it = se.lower_bound({temp, oo}); if(it != se.begin()){ it--; ii tmp1 = (*it), tmp2 = {tmp1.fi, temp - 1}, tmp3 = {temp + 1, tmp1.se}; se.erase(tmp1); //cout << tmp2.fi << " " << tmp2.se << " " << tmp3.fi << " " << tmp3.se << "\n"; if((tmp2.se - tmp2.fi + 1) >= d) se.insert(tmp2); if((tmp3.se - tmp3.fi + 1) >= d) se.insert(tmp3); } } void process(){ cin >> n >> d; for(int i = 1; i <= n; i++){ cin >> a[i].fi; a[i].se = i; } sort(a + 1, a + n + 1, cmp); se.insert({1, n}); int ans = -1, itr = 1; for(int i = 1; i <= n; i++){ int temp = a[i].se; while(itr <= n && a[itr].fi == a[i].fi){ er(a[itr].se); itr++; } //cout << i << " " << itr << "\n"; //cout << i << "\n"; //for(auto it : se) cout << it.fi << " " << it.se << "\n"; int lst = 1; set<ii>::iterator it = se.lower_bound({temp, oo}); if(it != se.begin()){ it--; lst = (*it).se + 1; } //cout << i << " " << temp << " " << lst << "\n"; dp[temp] = get(1, 1, n, lst, temp - 1) + 1; //cout << dp[temp] << "\n"; upd(1, 1, n, temp, dp[temp]); ans = max(ans, dp[temp]); } cout << ans; } signed main(){ ios_base::sync_with_stdio(0); #ifdef nqm freopen("input.inp", "r", stdin); freopen("output.out", "w", stdout); #endif #ifndef nqm #endif process(); }
#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...