#include<bits/stdc++.h>
#include "koninc.h"
using namespace std;
const int MAXN = 300001, rad = 550;
int N, K, v[MAXN+5];
int buk[MAXN+5], L[1002], R[1002], ad[1002], nrbuk;
int srt[1002][1002];
void proc(int bk)
{
for(int j = L[bk]; j <= R[bk]; ++j)
{
v[j] += ad[bk];
srt[bk][j - L[bk]] = v[j];
}
ad[bk] = 0;
sort(srt[bk], srt[bk] + R[bk] - L[bk] + 1);
}
int solve(int bk)
{
if(srt[bk][R[bk] - L[bk]] + ad[bk] < K)
return 0;
int st = 0;
int dr = R[bk] - L[bk];
int ans = dr;
while(st <= dr)
{
int mid = (st + dr) / 2;
if(srt[bk][mid] + ad[bk] >= K)
ans = mid, dr = mid - 1;
else
st = mid + 1;
}
return (R[bk] - L[bk]) - ans + 1;
}
void inicjuj(int n, int k, int *D)
{
N = n, K = k;
for(int i = 0; i < n; ++i)
v[i] = D[i];
for(int i = 0; i < n; ++i)
{
if(i % rad == 0)
++nrbuk, L[nrbuk] = i;
R[nrbuk] = i;
buk[i] = nrbuk;
}
for(int i = 0; i <= nrbuk; ++i)
proc(i);
}
void podlej(int a, int b)
{
int fini = R[buk[a]];
while(a <= b && a <= fini)
{
++v[a];
++a;
}
proc(buk[a]);
while(a < N && R[buk[a]] <= b)
++ad[buk[a]], a = R[buk[a]] + 1;
if(a <= b)
{
fini = R[buk[a]];
while(a <= b && a <= fini)
{
++v[a];
++a;
}
proc(buk[a]);
}
}
int dojrzale(int a, int b)
{
int fini = R[buk[a]];
int ans = 0;
// cout << a << " " << fini << '\n';
proc(buk[a]);
while(a <= b && a <= fini)
{
if(v[a] >= K)
++ans;
++a;
}
// cout << "RC " << a << " " << ans << '\n';
while(a < N && R[buk[a]] <= b)
ans += solve(buk[a]), a = R[buk[a]] + 1;
// cout << "RC " << a << " " << ans << '\n';
if(a <= b)
{
proc(buk[a]);
fini = R[buk[a]];
while(a <= b && a <= fini)
{
if(v[a] >= K)
++ans;
++a;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
476 KB |
Output is correct |
2 |
Correct |
62 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2273 ms |
2900 KB |
Output is correct |
2 |
Correct |
2145 ms |
2580 KB |
Output is correct |
3 |
Correct |
558 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3120 ms |
3692 KB |
Output is correct |
2 |
Correct |
3450 ms |
3992 KB |
Output is correct |
3 |
Correct |
752 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4014 ms |
5556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4010 ms |
6168 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4101 ms |
6840 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4021 ms |
9004 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4022 ms |
11316 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4030 ms |
11312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |