#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"
void printVector(vector<int> a){
for (auto x: a) cout << x << " ";
cout << endl;
}
int max(int x, int y){
if (x > y) return x;
else return y;
}
vector<int> tree;
vector<int> a;
int query(int l, int r, int pos, int ql, int qr){
if (ql > r || l > qr) { //no intersection case
return 0;
}
if (ql <= l && r <= qr) { //total intersection case
// cout << tree[pos] << pos << endl;
return tree[pos];
}
int mid = (l+r)/2;
return max(query(l, mid, pos*2, ql, qr), query(mid+1, r, pos*2+1, ql, qr));
}
void update(int l, int r, int pos, int qval, int qpos){
// cout << l << r << endl;
if (l == r){
tree[pos] = qval;
return;
}
int mid = (l+r)/2;
if (qpos <= mid){
update(l, mid, pos*2, qval, qpos);
}else{
update(mid+1, r, pos*2+1, qval, qpos);
}
tree[pos] = max(tree[pos*2], tree[pos*2+1]);
}
bool compare(int x, int y){
if (a[x] < a[y]) return true;
if (a[x] == a[y]){
if (x < y) return true;
}
return false;
}
int lis(vector<int> u){
a = u;
int n = a.size();
int N = n;
while (__builtin_popcount(N) != 1){
N++;
}
tree.resize(2*N);
vector<int> p(n);
FOR(i,0,n) p[i] = i;
sort(all(p), compare);
vector<vector<int>> components;
vector<int> component;
int current = 1;
FOR(i,0,n){
if (i == 0){
component.pb(p[i]);
}else{
if (a[p[i]] == a[p[i-1]]) component.pb(p[i]);
else{
components.pb(component);
component = {p[i]};
}
}
}
if (component.size()) components.pb(component);
// printVector(p);
for (auto component: components){
vector<int> o(component.size());
int m = component.size();
FOR(i,0,m){
o[i] = query(0, N-1, 1, 0, component[i]);
update(0, N-1, 1, o[i]+1, component[i]);
}
}
// printVector(tree);
return query(0, N-1, 1, 0, n);
}
void solve(){
int n, m; cin >> n >> m;
vector<int> a(n+1);
FOR(i,1,n+1) cin >> a[i];
vector<int> b(n+1);
FOR(i,1,n+1) b[i] = m*i-a[i];
// printVector(b);
vector<int> k;
FOR(i,1,n+1){
if (b[i]>= 0) k.pb(b[i]);
}
// printVector(k);
cout << n-lis(k) << endl;
// printVector(dp);
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", stdin)
int t = 1; // cin >> t;
while (t--) solve();
}
Compilation message
triusis.cpp: In function 'long long int lis(std::vector<long long int>)':
triusis.cpp:71:9: warning: unused variable 'current' [-Wunused-variable]
71 | int current = 1;
| ^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
1112 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
1116 KB |
Output is correct |
24 |
Correct |
2 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
1116 KB |
Output is correct |
26 |
Correct |
2 ms |
1116 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
860 KB |
Output is correct |
29 |
Correct |
2 ms |
1116 KB |
Output is correct |
30 |
Correct |
2 ms |
1116 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
2 ms |
1116 KB |
Output is correct |
33 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
2 ms |
1112 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
1116 KB |
Output is correct |
8 |
Correct |
2 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
1116 KB |
Output is correct |
17 |
Correct |
2 ms |
1116 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
2 ms |
1116 KB |
Output is correct |
38 |
Correct |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
2 ms |
860 KB |
Output is correct |
40 |
Correct |
2 ms |
860 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
2 ms |
1116 KB |
Output is correct |
43 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
1116 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
856 KB |
Output is correct |
15 |
Correct |
2 ms |
1112 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
1116 KB |
Output is correct |
18 |
Correct |
2 ms |
1116 KB |
Output is correct |
19 |
Correct |
2 ms |
1116 KB |
Output is correct |
20 |
Correct |
2 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
1116 KB |
Output is correct |
24 |
Correct |
2 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
1116 KB |
Output is correct |
27 |
Correct |
2 ms |
1116 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
98 ms |
26032 KB |
Output is correct |
45 |
Correct |
17 ms |
5352 KB |
Output is correct |
46 |
Correct |
69 ms |
17100 KB |
Output is correct |
47 |
Correct |
71 ms |
16580 KB |
Output is correct |
48 |
Correct |
80 ms |
26816 KB |
Output is correct |
49 |
Correct |
80 ms |
26684 KB |
Output is correct |
50 |
Correct |
67 ms |
17900 KB |
Output is correct |
51 |
Correct |
96 ms |
22092 KB |
Output is correct |
52 |
Correct |
86 ms |
23248 KB |
Output is correct |
53 |
Correct |
15 ms |
4968 KB |
Output is correct |
54 |
Correct |
95 ms |
26168 KB |
Output is correct |
55 |
Correct |
81 ms |
26820 KB |
Output is correct |