#include <bits/stdc++.h>
#include "koninc.h"
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
const int N = 3e5 + 50;
vector<int> sum(4*N), maks(4*N);
vector<int> a(N);
int d;
vector<int> lazy(4*N);
int n;
int buildsum(int node, int l, int r)
{
if(l==r)
{
return sum[node] = (a[l]>=d)?1:0;
}
int mid = (l+r)/2;
return sum[node] = buildsum(node*2+1, l, mid) + buildsum(node*2+2, mid+1, r);
}
int buildmaks(int node, int l, int r)
{
if(l==r)
{
if(a[l]>=d) maks[node] = -N;
else maks[node] = a[l];
return maks[node];
}
int mid = (l+r)/2;
return maks[node] = max(buildmaks(node*2+1, l, mid), buildmaks(node*2+2, mid+1, r));
}
void updatemaks(int node, int l, int r, int i, int j)
{
if(i>j) return;
int mid = (i+j)/2;
if(lazy[node])
{
if(i!=j)
{
lazy[node*2+1] += lazy[node];
lazy[node*2+2] += lazy[node];
}
maks[node] += lazy[node];
lazy[node] = 0;
}
if(i>r||j<l) return;
if(i>=l&&j<=r)
{
maks[node]++;
if(i!=j)
{
lazy[node*2+1]++;
lazy[node*2+2]++;
}
return;
}
updatemaks(node*2+1, l, r, i, mid);
updatemaks(node*2+2, l, r, mid+1, j);
maks[node] = max(maks[node*2+1], maks[node*2+2]);
}
void updatesum(int node, int l, int r, int x)
{
if(l>r) return;
if(l==r)
{
sum[node] = 1;
return;
}
int mid = (l+r)/2;
if(x>mid) updatesum(node*2+2, mid+1, r, x);
else updatesum(node*2+1, l, mid, x);
sum[node] = sum[node*2+1] + sum[node*2+2];
}
int get_sum(int node, int l, int r, int i, int j)
{
if(i>j) return 0;
if(i>r||j<l) return 0;
if(i>=l&&j<=r) return sum[node];
int mid = (i+j)/2;
return get_sum(node*2+1, l, r, i, mid) + get_sum(node*2+2, l, r, mid+1, j);
}
void trazi(int node, int l, int r)
{
if(l>r) return;
int mid = (l+r)/2;
if(lazy[node])
{
if(l!=r)
{
lazy[node*2+1] += lazy[node];
lazy[node*2+2] += lazy[node];
}
maks[node] += lazy[node];
lazy[node] = 0;
}
if(maks[node]<d) return;
if(l==r)
{
updatesum(0, 0, n-1, l);
maks[node] = -N;
return;
}
//int mid = (l+r)/2;
trazi(node*2+1, l, mid);
trazi(node*2+2, mid+1, r);
maks[node] = max(maks[node*2+1], maks[node*2+2]);
}
void inicjuj(int w, int k, int *D)
{
n = w;
d = k;
for(int i = 0;i<n;i++) a[i] = D[i];
buildmaks(0, 0, n-1);
buildsum(0, 0, n-1);
}
void podlej(int a, int b)
{
updatemaks(0, a, b, 0, n-1);
}
int dojrzale(int a, int b)
{
trazi(0, 0, n-1);
return get_sum(0, a, b, 0, n-1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
15596 KB |
Output is correct |
2 |
Correct |
12 ms |
15596 KB |
Output is correct |
3 |
Correct |
13 ms |
15596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
15596 KB |
Output is correct |
2 |
Correct |
13 ms |
15724 KB |
Output is correct |
3 |
Correct |
10 ms |
15596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
17128 KB |
Output is correct |
2 |
Correct |
60 ms |
17432 KB |
Output is correct |
3 |
Correct |
71 ms |
17516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
17644 KB |
Output is correct |
2 |
Correct |
103 ms |
18284 KB |
Output is correct |
3 |
Correct |
77 ms |
18156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
18412 KB |
Output is correct |
2 |
Correct |
99 ms |
19308 KB |
Output is correct |
3 |
Correct |
121 ms |
19692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
234 ms |
21996 KB |
Output is correct |
2 |
Correct |
175 ms |
21356 KB |
Output is correct |
3 |
Correct |
191 ms |
22124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
22380 KB |
Output is correct |
2 |
Correct |
206 ms |
22124 KB |
Output is correct |
3 |
Correct |
239 ms |
24044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
346 ms |
24300 KB |
Output is correct |
2 |
Correct |
344 ms |
24844 KB |
Output is correct |
3 |
Correct |
361 ms |
28028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
473 ms |
26476 KB |
Output is correct |
2 |
Correct |
372 ms |
28780 KB |
Output is correct |
3 |
Correct |
437 ms |
29804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
426 ms |
27012 KB |
Output is correct |
2 |
Correct |
409 ms |
30316 KB |
Output is correct |
3 |
Correct |
398 ms |
29420 KB |
Output is correct |