Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <map>
- #include <cstring>
- #include <algorithm>
- #include <stack>
- #include <queue>
- using namespace std;
- vector<int>v;
- const int maxn=2e5;
- int segment[maxn*3];
- void build_tree(int L, int R, int pos){
- if(L==R){
- segment[pos]=v[L];
- }
- else{
- int middle=(L+R)/2;
- build_tree(L, middle, pos*2);
- build_tree(middle+1, R, pos*2+1);
- segment[pos]=min(segment[2*pos], segment[2*pos+1]);
- }
- }
- ///l r i l r j l r
- int query(int L, int R, int pos, int i, int j){
- if(i<=L and j>=R){
- return segment[pos];
- }
- if(R<i or j<L){
- return 2e9;
- }
- int middle=(R+L)/2;
- return min(query(L, middle, pos*2, i, j), query(middle+1, R, pos*2+1, i, j));
- }
- int main() {
- int n, k, l;
- cin>>n>>l>>k;
- for(int i=0; i<n; i++){
- int a; cin>>a;
- v.push_back(a);
- }
- build_tree(0, n-1, 1);
- int counter=0;
- for(int i=0; i<v.size(); i++){
- if(v[i]<l){
- continue;
- }
- if(i + k >= v.size()) {
- continue;
- }
- if(query(0, n-1, 1, i+1, i+k)>=l){
- counter++;
- }
- }
- cout<<counter;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement