Submission #463721

#TimeUsernameProblemLanguageResultExecution timeMemory
463721MounirFinancial Report (JOI21_financial)C++14
5 / 100
1103 ms616872 KiB
#include <bits/stdc++.h> #define sz(x) (int)x.size() #define chmin(x, v) x = min(x, v) #define chmax(x, v) x = max(x, v) #define all(x) x.begin(), x.end() #define pb push_back #define pii pair<int, int> #define deb first #define fin second #define int long long using namespace std; const int N = (1 << 19); deque<int> enAttente[N]; int arbre[N * 2]; int getMax(int gauche, int droite){ if (droite < gauche) return 0; if (gauche%2 == 1) return max(arbre[gauche], getMax(gauche + 1, droite)); if (droite%2 == 0) return max(arbre[droite], getMax(gauche, droite - 1)); return getMax(gauche/2, droite/2); } int temps = 0; int dp[N]; void update(int val, int newVal){ int noeud = N + val; arbre[noeud] = newVal; // cout << "upd " << val << " " << arbre[noeud] << endl; noeud /= 2; for (; noeud > 0; noeud /= 2) arbre[noeud] = max(arbre[noeud * 2], arbre[noeud * 2 + 1]); } int mini[N][19]; int getMin(int deb, int fin){ int ex = floor(log2(fin- deb + 1)); return max(mini[deb][ex], mini[fin - (1 << ex) + 1][ex]); } signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int nVals, distMax; cin >> nVals >> distMax; vector<int> vals(nVals), triees; for (int& val : vals){ cin >> val; triees.pb(val); } for (int deb = 0; deb < N; ++deb) for (int i = 0; i < 19; ++i) mini[deb][i] = 1e9; for (int deb = 0; deb < nVals; ++deb) mini[deb][0] = vals[deb]; for (int i = 0; (1 << i) < nVals; ++i){ for (int deb = 0; deb + (1 << (i + 1)) <= nVals; ++deb) mini[deb][i + 1] = min(mini[deb][i], mini[deb + (1 << i)][i]); } sort(all(triees)); map<int, int> conv; for (int i = 0; i < nVals; ++i) conv[triees[i]] = i; for (int& val : vals) val = conv[val]; int maxi = 0; for (int iVal = 0; iVal < nVals; ++iVal){ if (iVal > distMax){ int val = vals[iVal - distMax - 1]; while (!enAttente[val].empty() && enAttente[val].back() < iVal - distMax && getMin(enAttente[val].back() + 1, iVal - 1) > val) enAttente[val].pop_back(); if (!enAttente[val].empty()) update(val, dp[enAttente[val].back()]); else update(val, -1); } int res = getMax(N, N + vals[iVal] - 1) + 1; dp[iVal] = res; while (!enAttente[vals[iVal]].empty() && dp[enAttente[vals[iVal]].front()] <= res) enAttente[vals[iVal]].pop_front(); enAttente[vals[iVal]].push_front(iVal); update(vals[iVal], dp[enAttente[vals[iVal]].back()]); chmax(maxi, dp[iVal]); // cout << "res " << iVal << ": "<< dp[iVal] << endl; } // cout << endl; cout << maxi << endl; 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...