#include <cmath>
#include <iostream>
#include <set>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <iomanip>
#include <type_traits>
#include <string>
#include <queue>
#include <map>
using namespace std;
#define ll long long
template<class T> struct Seg { // comb(ID,b) = b
const T ID = 0; T comb(T a, T b) { return max(a,b); }
int n; vector<T> seg;
void init(int _n) { n = _n; seg.assign(2*n,ID); }
void pull(int p) { seg[p] = comb(seg[2*p],seg[2*p+1]); }
void upd(int p, T val) { // set val at position p
seg[p += n] = val; for (p /= 2; p; p /= 2) pull(p); }
T query(int l, int r) { // sum on interval [l, r]
T ra = ID, rb = ID;
for (l += n, r += n+1; l < r; l /= 2, r /= 2) {
if (l&1) ra = comb(ra,seg[l++]);
if (r&1) rb = comb(seg[--r],rb);
}
return comb(ra,rb);
}
};
int lis (vector<ll> v) {
int n = v.size();
Seg<int> st;
st.init(v.size() + 2);
vector<int> dp(v.size());
set<int> mySet;
for (int i = 0; i < v.size(); i++) {
dp[i] = 0;
mySet.insert(v[i]);
}
map<int,int> myMap;
int cntr = 0;
for (int i: mySet) {
myMap[i] = ++cntr;
}
for (int i = 0; i < n; i++) {
v[i] = myMap[v[i]];
}
for (int i = 0; i < n; i++) {
st.upd(v[i], st.query(0, v[i]) + 1);
}
return st.query(0, n);
}
int main() {
int n;
cin >> n;
int m;
cin >> m;
vector<ll> v(n + 1);
v[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> v[i];
v[i] = m * i - v[i];
}
vector<ll> vec;
for (int i = 0; i < v.size(); i++) {
if (v[i] >= 0) {
vec.push_back(v[i]);
}
}
cout << n + 1 - lis(vec);
}
Compilation message
triusis.cpp: In function 'int lis(std::vector<long long int>)':
triusis.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
triusis.cpp: In function 'int main()':
triusis.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i = 0; i < v.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 |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
292 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 |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
292 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 |
2 ms |
716 KB |
Output is correct |
21 |
Correct |
4 ms |
844 KB |
Output is correct |
22 |
Correct |
2 ms |
300 KB |
Output is correct |
23 |
Correct |
3 ms |
944 KB |
Output is correct |
24 |
Correct |
4 ms |
844 KB |
Output is correct |
25 |
Correct |
4 ms |
844 KB |
Output is correct |
26 |
Correct |
3 ms |
844 KB |
Output is correct |
27 |
Correct |
2 ms |
460 KB |
Output is correct |
28 |
Correct |
2 ms |
480 KB |
Output is correct |
29 |
Correct |
3 ms |
844 KB |
Output is correct |
30 |
Correct |
3 ms |
844 KB |
Output is correct |
31 |
Correct |
2 ms |
716 KB |
Output is correct |
32 |
Correct |
3 ms |
844 KB |
Output is correct |
33 |
Correct |
3 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 |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
4 ms |
844 KB |
Output is correct |
6 |
Correct |
2 ms |
300 KB |
Output is correct |
7 |
Correct |
3 ms |
944 KB |
Output is correct |
8 |
Correct |
4 ms |
844 KB |
Output is correct |
9 |
Correct |
4 ms |
844 KB |
Output is correct |
10 |
Correct |
3 ms |
844 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
2 ms |
480 KB |
Output is correct |
13 |
Correct |
3 ms |
844 KB |
Output is correct |
14 |
Correct |
3 ms |
844 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
3 ms |
844 KB |
Output is correct |
17 |
Correct |
3 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 |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 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 |
1 ms |
296 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
292 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
2 ms |
332 KB |
Output is correct |
35 |
Correct |
2 ms |
380 KB |
Output is correct |
36 |
Correct |
2 ms |
332 KB |
Output is correct |
37 |
Correct |
3 ms |
844 KB |
Output is correct |
38 |
Correct |
2 ms |
460 KB |
Output is correct |
39 |
Correct |
2 ms |
460 KB |
Output is correct |
40 |
Correct |
2 ms |
716 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
4 ms |
944 KB |
Output is correct |
43 |
Correct |
4 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
844 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
944 KB |
Output is correct |
10 |
Correct |
4 ms |
972 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 |
2 ms |
716 KB |
Output is correct |
15 |
Correct |
4 ms |
844 KB |
Output is correct |
16 |
Correct |
2 ms |
300 KB |
Output is correct |
17 |
Correct |
3 ms |
944 KB |
Output is correct |
18 |
Correct |
4 ms |
844 KB |
Output is correct |
19 |
Correct |
4 ms |
844 KB |
Output is correct |
20 |
Correct |
3 ms |
844 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
480 KB |
Output is correct |
23 |
Correct |
3 ms |
844 KB |
Output is correct |
24 |
Correct |
3 ms |
844 KB |
Output is correct |
25 |
Correct |
2 ms |
716 KB |
Output is correct |
26 |
Correct |
3 ms |
844 KB |
Output is correct |
27 |
Correct |
3 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 |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
1 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 |
1 ms |
296 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
292 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
164 ms |
26504 KB |
Output is correct |
45 |
Correct |
70 ms |
3640 KB |
Output is correct |
46 |
Correct |
163 ms |
15772 KB |
Output is correct |
47 |
Correct |
163 ms |
15768 KB |
Output is correct |
48 |
Correct |
149 ms |
26520 KB |
Output is correct |
49 |
Correct |
161 ms |
27172 KB |
Output is correct |
50 |
Correct |
84 ms |
7764 KB |
Output is correct |
51 |
Correct |
83 ms |
9120 KB |
Output is correct |
52 |
Correct |
107 ms |
17572 KB |
Output is correct |
53 |
Correct |
51 ms |
2952 KB |
Output is correct |
54 |
Correct |
159 ms |
27116 KB |
Output is correct |
55 |
Correct |
171 ms |
26956 KB |
Output is correct |