제출 #536399

#제출 시각아이디문제언어결과실행 시간메모리
536399ArnchFinancial Report (JOI21_financial)C++17
100 / 100
563 ms25924 KiB
// oooo /* har chi delet mikhad bebar ~ gitar o ba khodet nabar! ~ ;Amoo_Hasan; */ #include<bits/stdc++.h> #pragma GCC optimize("O3,no-stack-protector,unroll-loops") #pragma GCC target("avx2,fma") using namespace std; typedef long long ll; typedef long double ld; #define Sz(x) int((x).size()) #define All(x) (x).begin(), (x).end() #define wtf(x) cout<<#x <<" : " <<x constexpr ll inf = 1e18, N = 1e6 + 10, mod = 1e9 + 7, pr = 1000696969; int n, d, a[N], l[N], r[N], dp[N]; set<int> bad, to; vector<pair<int, int> > vc; bool cmp(pair<int, int> p1, pair<int, int> p2) { if(p1.first != p2.first) return p1.first < p2.first; return p1.second > p2.second; } struct node { int val; } x[N << 2]; void change(int l, int r, int ind, int val, int v) { if(r - l < 2) { x[v].val = val; return; } int mid = (l + r) >> 1; if(ind < mid) change(l, mid, ind, val, 2 * v); else change(mid, r, ind, val, 2 * v + 1); x[v].val = max(x[2 * v].val, x[2 * v + 1].val); } int get(int l, int r, int s, int e, int v) { if(r <= s || l >= e) return 0; if(l >= s && r <= e) return x[v].val; int mid = (l + r) >> 1; return max(get(l, mid, s, e, 2 * v), get(mid, r, s, e, 2 * v + 1)); } int main() { ios :: sync_with_stdio(0), cin.tie(0); cin >>n >>d; for(int i = 0; i < n; i++) cin >>a[i], vc.push_back({a[i], i}); sort(All(vc), cmp); for(int i = 0; i < n; i++) l[i] = -1, r[i] = n; for(auto i : vc) { int ind = i.second; auto it = to.lower_bound(ind); if(it != to.end()) { l[*it] = ind, r[ind] = *it; if(*it - ind <= d) { bad.erase(*it); } } if(it != to.begin()) { it--; l[ind] = *it, r[*it] = ind; } to.insert(ind); if(ind - l[ind] > d) bad.insert(ind); dp[ind] = 1; if(ind != 0) { auto pos = bad.upper_bound(ind); if(pos == bad.begin()) { // cout<<"^&" <<ind <<" " <<0 <<" " <<ind <<endl; dp[ind] += get(0, n, 0, ind, 1); } else { pos--; int j = *pos; j = max(0, j); // cout<<"^&" <<ind <<" " <<*pos <<" " <<ind <<endl; if(j != ind) dp[ind] += get(0, n, j, ind, 1); } } change(0, n, ind, dp[ind], 1); } int ans = 0; for(int i = 0; i < n; i++) ans = max(ans, dp[i]); cout<<ans; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...