Submission #481121

# Submission time Handle Problem Language Result Execution time Memory
481121 2021-10-19T13:56:46 Z s_samchenko Rabbit Carrot (LMIO19_triusis) C++17
100 / 100
197 ms 24292 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define ll long long
#define ff first
#define ss second
#define int ll
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define pii pair <int, int>
using namespace std;
const int inf = 1e15;
const int mod = 1e9+7;
const int N = 3e5+100;

struct segtree{
	int size;
	vector <int> t;
	
	segtree(int n){
		size = 1;
		while (size < n) size <<= 1;
		t.resize(2*size - 1);
	}
	
	void set(int i, int v, int x, int lx, int rx){
		if (rx - lx == 1){
			t[x] = v;
			return;
		}
		int m = (lx + rx) / 2;
		if (i < m) set(i, v, 2*x + 1, lx, m);
		else set(i, v, 2*x + 2, m, rx);
		t[x] = max(t[2*x + 1], t[2*x + 2]);
	}
	
	void set(int i, int v){
		set(i, v, 0, 0, size);
	}
	
	int get(int l, int r, int x, int lx, int rx){
		if (l >= rx || lx >= r) return 0;
		if (l <= lx && r >= rx) return t[x];
		int m = (lx + rx) / 2;
		return max(get(l, r, 2*x + 1, lx, m), get(l, r, 2*x + 2, m, rx));
	}
	
	
	int get(int l, int r){
		return get(l, r + 1, 0, 0, size);
	}
};

int longest_nondec_subseq(const vector<int>& seq) {
	vector<int> min_endings;
	for (int i : seq) {
		// note that we use upper_bound instead of lower_bound bc it just has to be nondecreasing
		int pos = std::upper_bound(min_endings.begin(), min_endings.end(), i) - min_endings.begin();
		// standard LIS protocol
		if (pos == min_endings.size()) {
			min_endings.push_back(i);
		} else {
			min_endings[pos] = i;
		}
	}
	return min_endings.size();
}

void solve(){
	int n, m;
	cin >> n >> m;
	vector <int> a(n+1);
	for (int i = 1; i <= n; ++i) cin >> a[i];
	vector <int> b;
	for (int i = 1; i <= n; ++i){
		if (a[i] > m * i) continue;
		b.pb(m * i - a[i]);
	}
	vector <int> c = b; sort(all(c));
	map <int, int> mp;
	for (int i = 0; i < b.size(); ++i)
		if (mp[c[i]] == 0) mp[c[i]] = i+1;
	
	vector <int> dp(n+100);
	segtree st(n+100);
	for (int i = 0; i < b.size(); ++i){
		dp[i] = st.get(0, mp[b[i]]) + 1;
		st.set(mp[b[i]], dp[i]);
	}
	cout << n - *max_element(all(dp));
}

signed main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int tt = 1;
	//cin >> tt;
	while (tt--){
		solve();
		cout << '\n';
	}
}

Compilation message

triusis.cpp: In function 'long long int longest_nondec_subseq(const std::vector<long long int>&)':
triusis.cpp:60:11: 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]
   60 |   if (pos == min_endings.size()) {
      |       ~~~~^~~~~~~~~~~~~~~~~~~~~
triusis.cpp: In function 'void solve()':
triusis.cpp:81:20: 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]
   81 |  for (int i = 0; i < b.size(); ++i)
      |                  ~~^~~~~~~~~~
triusis.cpp:86:20: 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]
   86 |  for (int i = 0; i < b.size(); ++i){
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 3 ms 716 KB Output is correct
21 Correct 3 ms 844 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 4 ms 844 KB Output is correct
24 Correct 4 ms 844 KB Output is correct
25 Correct 4 ms 844 KB Output is correct
26 Correct 4 ms 844 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 4 ms 844 KB Output is correct
30 Correct 5 ms 844 KB Output is correct
31 Correct 3 ms 716 KB Output is correct
32 Correct 4 ms 844 KB Output is correct
33 Correct 4 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 3 ms 844 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 4 ms 844 KB Output is correct
8 Correct 4 ms 844 KB Output is correct
9 Correct 4 ms 844 KB Output is correct
10 Correct 4 ms 844 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 2 ms 588 KB Output is correct
13 Correct 4 ms 844 KB Output is correct
14 Correct 5 ms 844 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 4 ms 844 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 4 ms 844 KB Output is correct
38 Correct 1 ms 588 KB Output is correct
39 Correct 2 ms 588 KB Output is correct
40 Correct 3 ms 716 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 5 ms 844 KB Output is correct
43 Correct 4 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 4 ms 844 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 5 ms 844 KB Output is correct
10 Correct 4 ms 844 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 3 ms 844 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 4 ms 844 KB Output is correct
18 Correct 4 ms 844 KB Output is correct
19 Correct 4 ms 844 KB Output is correct
20 Correct 4 ms 844 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 4 ms 844 KB Output is correct
24 Correct 5 ms 844 KB Output is correct
25 Correct 3 ms 716 KB Output is correct
26 Correct 4 ms 844 KB Output is correct
27 Correct 4 ms 844 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 197 ms 23204 KB Output is correct
45 Correct 34 ms 9412 KB Output is correct
46 Correct 164 ms 17352 KB Output is correct
47 Correct 174 ms 17220 KB Output is correct
48 Correct 192 ms 23740 KB Output is correct
49 Correct 191 ms 24292 KB Output is correct
50 Correct 72 ms 11952 KB Output is correct
51 Correct 68 ms 12748 KB Output is correct
52 Correct 135 ms 17832 KB Output is correct
53 Correct 21 ms 8772 KB Output is correct
54 Correct 187 ms 24252 KB Output is correct
55 Correct 188 ms 24080 KB Output is correct