#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define ent "\n"
const int inf = (int)1e9 + 100;
const int maxn = 5e5 + 100;
const ll INF = (ll)1e18;
const int MOD = 1e9 + 7;
const int maxl = 62500;
const ll P = 31, T = 0;
int n, m;
ll a[maxn];
int t[maxn];
int get(int i){
int res = 0;
for(; i > 0; i = (i & (i + 1)) - 1) res = max(res, t[i]);
return res;
}
void upd(int i, int x){
for(; i <= n; i |= (i + 1)) t[i] = max(t[i], x);
}
void test(){
cin >> n >> m;
vector<int> ord(1, 0);
for(int i = 1; i <= n; i++){
cin >> a[i];
a[i] -= 1ll * i * m;
ord.push_back(i);
}
sort(ord.begin(), ord.end(), [](int i, int j){
if(a[i] != a[j]) return a[i] < a[j];
return i > j;
});
int ans;
for(int i: ord){
int d = get(n - i + 1) + 1;
upd(n - i + 1, d);
if(!i) ans = n - d + 1;
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t = 1;
if(T) cin >> t;
while(t--) test();
}
Compilation message
triusis.cpp: In function 'void test()':
triusis.cpp:47:10: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
47 | cout << ans;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |