Submission #547965

# Submission time Handle Problem Language Result Execution time Memory
547965 2022-04-12T05:04:02 Z PikaQ Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
4 ms 6484 KB
#include<bits/stdc++.h>
#define int ll
#define forn(i,n) for(int i=0;i<(n);i++)
#define Forn(i,n) for(int i=1;i<=(n);i++)
#define ll long long
#define pb push_back
#define F first
#define S second
#define vi vector<long long>
#define pii pair<int,int>
#define all(p) p.begin(),p.end()
#define st0(p) memset((p),0,sizeof(p))
#define sz(x) (x).size()
#define rz resize
using namespace std;

 
inline void USACO(string filename){
  freopen((filename+".in").c_str(),"r",stdin);
  freopen((filename+".out").c_str(),"w",stdout);
}
 
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cerr << a << " "; debug(b...);}
const int N = (int) 2e5 + 9;
const int INF = (int) 1e9 + 7;
int n,k;

struct SegmentTree{
	int t[N<<2];
	void init(){
		for(auto &i : t) i = -INF;
	}
	void modify(int l,int r,int p,int v,int id){
		if(l == r){
			t[id] = v;
			return;
		}
		int m = (l+r)/2;
		if(p <= m) modify(l,m,p,v,2*id);
		else modify(m+1,r,p,v,2*id+1);
		t[id] = max(t[2*id],t[2*id+1]);
	}
	int query(int ql,int qr,int l,int r,int id){
		if(ql <= l  && qr >= r){
			return t[id];
		}
		int m = (l+r)/2;
		if(qr <= m) return query(ql,qr,l,m,2*id);
		else if(ql > m) return query(ql,qr,m+1,r,2*id+1);
		else return max(query(ql,qr,l,m,2*id),query(ql,qr,m+1,r,2*id+1));
	}
}seg;

void solve(){
	cin >> n >> k;
	vi a(n),rk(n);
	forn(i,n) cin >> a[i],rk[i] = a[i];
	rk.pb(0);
	sort(all(rk));
	rk.resize(unique(all(rk)) - rk.begin());
	vi lm(rk.size()+1);
	int cur = 0;
	Forn(i,rk.size()-1){
		while(rk[i] - rk[cur] > k){
			cur++;
		}
		lm[i+1] = cur+1;
	}
	forn(i,n) a[i] = upper_bound(all(rk),a[i]) - rk.begin();
	vi dp(n);
	seg.init();
	seg.modify(1,n+1,1,0,1);
	forn(i,n){
		dp[i] = seg.query(lm[a[i]],n+1,1,n+1,1) + 1;
		seg.modify(1,n+1,a[i],dp[i],1);
	}
	cout <<((n - seg.query(1,n+1,1,n+1,1) < 0) ? n : (n - seg.query(1,n+1,1,n+1,1))) << '\n';
}
signed main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	solve();
	return 0;
}

Compilation message

triusis.cpp: In function 'void solve()':
triusis.cpp:4:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define Forn(i,n) for(int i=1;i<=(n);i++)
      |                                ^
triusis.cpp:64:2: note: in expansion of macro 'Forn'
   64 |  Forn(i,rk.size()-1){
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6472 KB Output is correct
7 Correct 3 ms 6472 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 3 ms 6484 KB Output is correct
11 Correct 3 ms 6484 KB Output is correct
12 Incorrect 4 ms 6484 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6472 KB Output is correct
7 Correct 3 ms 6472 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 3 ms 6484 KB Output is correct
11 Correct 3 ms 6484 KB Output is correct
12 Incorrect 4 ms 6484 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6472 KB Output is correct
7 Correct 3 ms 6472 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 3 ms 6484 KB Output is correct
11 Correct 3 ms 6484 KB Output is correct
12 Incorrect 4 ms 6484 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6472 KB Output is correct
7 Correct 3 ms 6472 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 3 ms 6484 KB Output is correct
11 Correct 3 ms 6484 KB Output is correct
12 Incorrect 4 ms 6484 KB Output isn't correct
13 Halted 0 ms 0 KB -