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<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define int long long
const int mod=9901,mxn=3*1e5+5,inf=1e18,lg=25,minf=-1e18;
int n;
struct seg{
int v[2*mxn+10];
void update(int pos,int val){
pos+=n;
v[pos]=val;
for(;pos>0;pos>>=1)v[pos>>1]=max(v[pos],v[pos^1]);
}
int qry(int l,int r){
int ans=0;
for(l+=n,r+=n;l<=r;l>>=1,r>>=1){
if(l&1)ans=max(ans,v[l++]);
if(!(r&1))ans=max(ans,v[r--]);
}
return ans;
}
}t;
int32_t main(){
fastio
int d;cin>>n>>d;
vector<pii>v(n);
for(int i=0;i<n;i++)cin>>v[i].f,v[i].s=i;
sort(all(v));
vector<pii>up;
for(int i=0;i<v.size();i++){
int cur=i;
up.clear();
while(cur<n&&v[i].f==v[cur].f){
up.pb({v[cur].s,t.qry(max(0ll,v[cur].s-d),v[cur].s)+1});
cur++;
}
i=cur-1;
for(auto i:up)t.update(i.f,i.s);
}
cout<<t.qry(max(0ll,n-d-1),n-1);
}
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:57:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# | 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... |