This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 500000
lli n,t,d,act,a,res,op;
lli arr[MAX+2],grupo[MAX+2],bit[MAX+2];
stack<lli> pila;
void actualiza(lli pos) {
while (pos <= n) {
bit[pos]++;
pos += pos&(-pos);
}
}
lli query(lli pos) {
lli total = 0;
while (pos > 0) {
total += bit[pos];
pos -= pos & (-pos);
}
return total;
}
lli busca() {
lli sum,mayor=0;
lli pos = -1;
sum = 0;
repa(i,n,1) {
if (grupo[i] == 0) continue;
if (grupo[i] == i) {
sum = query(i);
if (sum > mayor) {
mayor = sum;
pos = i;
}
}
actualiza(grupo[i]);
}
return pos;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> d >> t;
rep(i,1,n) cin >> arr[i];
res = n;
rep(i,1,n) {
if (arr[i] <= t) {
pila.push(i);
grupo[i] = i;
}
else {
while (!pila.empty()) {
act = pila.top();
a = arr[act] + (i-act);
if (a <= t) {grupo[i] = act;break;}
else pila.pop();
}
if (grupo[i] == 0) res--;
}
}
rep(q,1,d) {
rep(i,1,n) bit[i] = 0;
op = busca();
if (op == -1) break;
rep(i,op+1,n) {
if (grupo[i] <= op && grupo[i] > 0) {
grupo[i] = 0;
res--;
}
}
grupo[op] = 0;
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |