제출 #463706

#제출 시각아이디문제언어결과실행 시간메모리
463706MounirFinancial Report (JOI21_financial)C++14
5 / 100
547 ms33752 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);
int dateVal[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;

void update(int noeud, int val){
      dateVal[val] = temps++;
      arbre[noeud] = val;
      noeud /= 2;
      for (; noeud > 0; noeud /= 2)
            arbre[noeud] = max(arbre[noeud * 2], arbre[noeud * 2 + 1]);
}

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);
      }

      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];

      for (int iVal = 0; iVal < nVals; ++iVal){
            if (iVal > distMax && dateVal[vals[iVal - distMax - 1]] == iVal - distMax - 1)
                  update(N + vals[iVal - distMax - 1], -1);
            update(N + vals[iVal], getMax(N, N + vals[iVal] - 1) + 1);
      }
      cout << arbre[1] << 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...