#include<bits/stdc++.h>
#include "koninc.h"
using namespace std;
const int MAXN = 300001, rad = 400;
int N, K, v[MAXN+5], done = 200000;
int buk[MAXN+5], L[1012], R[1012], ad[1012], nrbuk, aans[1012];
short ans[1002][100012];
void proc(int bk, int LL, int RR)
{
for(int j = L[bk]; j <= R[bk]; ++j)
{
if(v[j] >= K)
ans[bk][0] = 0;
else
if(K - v[j] <= 100000)
ans[bk][K - v[j]] = 0;
}
for(int j = LL; j <= RR; ++j)
v[j]++;
for(int j = L[bk]; j <= R[bk]; ++j)
{
v[j] += ad[bk];
if(v[j] >= K)
ans[bk][0]++;
else
if(K - v[j] <= 100000)
ans[bk][K - v[j]]++;
}
ad[bk] = 0;
aans[bk] = ans[bk][0];
}
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, 1, 0);
}
void podlej(int a, int b)
{
int fini = R[buk[a]];
int ax = buk[a];
proc(ax, a, min(b, fini));
a = min(b, fini) + 1;
while(a < N && R[buk[a]] <= b)
++ad[buk[a]], aans[buk[a]] = aans[buk[a]] + ans[buk[a]][ad[buk[a]]], a = R[buk[a]] + 1;
if(a <= b)
{
fini = R[buk[a]];
ax = buk[a];
proc(ax, a, b);
}
--done;
}
int dojrzale(int a, int b)
{
int fini = R[buk[a]];
int qans = 0;
proc(buk[a], 1, 0);
while(a <= b && a <= fini)
{
if(v[a] >= K)
++qans;
++a;
}
while(a < N && R[buk[a]] <= b)
qans += aans[buk[a]], a = R[buk[a]] + 1;
if(a <= b)
{
proc(buk[a], 1, 0);
fini = R[buk[a]];
while(a <= b && a <= fini)
{
if(v[a] >= K)
++qans;
++a;
}
}
--done;
return qans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
12 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
388 ms |
1360 KB |
Output is correct |
2 |
Correct |
283 ms |
1036 KB |
Output is correct |
3 |
Correct |
268 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
688 ms |
1672 KB |
Output is correct |
2 |
Correct |
231 ms |
1744 KB |
Output is correct |
3 |
Correct |
262 ms |
1660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
819 ms |
42872 KB |
Output is correct |
2 |
Correct |
921 ms |
32960 KB |
Output is correct |
3 |
Correct |
488 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1573 ms |
60932 KB |
Output is correct |
2 |
Correct |
1355 ms |
38944 KB |
Output is correct |
3 |
Correct |
715 ms |
3128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2027 ms |
39916 KB |
Output is correct |
2 |
Correct |
1452 ms |
49168 KB |
Output is correct |
3 |
Correct |
1205 ms |
5096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3132 ms |
77748 KB |
Output is correct |
2 |
Correct |
2815 ms |
100828 KB |
Output is correct |
3 |
Correct |
1506 ms |
16920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2414 ms |
11208 KB |
Output is correct |
2 |
Correct |
1755 ms |
10300 KB |
Output is correct |
3 |
Correct |
2270 ms |
13944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2319 ms |
10212 KB |
Output is correct |
2 |
Correct |
2813 ms |
10548 KB |
Output is correct |
3 |
Correct |
1728 ms |
8156 KB |
Output is correct |