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<utility>
#include<set>
#include<algorithm>
using namespace std;
multiset<int> secik;
set<pair<int,int>> wynik;
int t[1000000];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,d;
cin>>n>>d;
for(int i=1;i<=n;i++)
cin>>t[i];
t[0]=1e9;
for(int i=1;i<=n;i++)
{
secik.insert(t[i-1]);
if(i-d-1>=0)
secik.erase(t[i-d-1]);
//cout<<"ok\n";
while(wynik.size() && *secik.begin()>(*wynik.begin()).first)
wynik.erase(wynik.begin());
auto it=wynik.lower_bound({t[i],0});
//cout<<"ok2\n";
if(it==wynik.end())
{
if(wynik.size()==0)
wynik.insert({t[i],1});
else{
it--;
wynik.insert({t[i],(*it).second+1});
}
}
else if((*it).first!=t[i])
{
//cout<<"tako\n";
if(it==wynik.begin())
{
if((*it).second==1)
wynik.erase(it);
wynik.insert({t[i],1});
}
else{
auto it2=it;
it2--;
if((*it).second==(*it2).second+1)
wynik.erase(it);
wynik.insert({t[i],(*it2).second+1});
}
//cout<<"koniec\n";
}
}
//cout<<"zyje\n";
auto it=wynik.rbegin();
cout<<(*it).second;
return 0;
}
# | 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... |