This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define fi first
#define se second
using namespace std;
const int N = 2e5+15;
const int M = 550;
const ll mod = 998244353;
const ld base = 1e6;
const ll inf = 1e16;
const ld pi = acos(-1);
ll n, m, k, ans, cnt[N], t, h[N], c[N], tong, lab[N], a[N], b[N];
vector<ll> adj[N];
string s[N];
mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
vector<ll> kq;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n&1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
ll findp(ll u)
{
return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
void hop(ll u, ll v)
{
if(lab[u] > lab[v])swap(u, v);
lab[u] += lab[v];
lab[v] = u;
k = max(k, -lab[u]);
}
struct BIT
{
ll n;
vector<ll> fe;
BIT(ll _n)
{
n = _n;
fe.resize(n+1, 0);
}
void add(ll id, ll x)
{
for(; id <= n; id += id & -id)fe[id] = max(fe[id], x);
}
ll get(ll id)
{
ll total = 0;
for(; id; id -= id & -id)total = max(total, fe[id]);
return total;
}
};
void sol()
{
cin >> n >> k;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
kq.pb(a[i]);
}
ans = 0;
sort(kq.begin(), kq.end());
kq.erase(unique(kq.begin(), kq.end()), kq.end());
BIT l(n), r(n);
for(int i = 1; i <= n; i ++)
{
b[i] = lower_bound(kq.begin(), kq.end(), a[i]+k) - kq.begin() + 1;
a[i] = lower_bound(kq.begin(), kq.end(), a[i]) - kq.begin() + 1;
c[i] = l.get(a[i]-1);
m = max(l.get(b[i]-1), r.get(a[i]-1));
l.add(a[i], c[i]+1);
r.add(a[i], m+1);
}
cout << r.get(n);
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "tests"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
//cin >> test;
while(test -- > 0)sol();
return 0;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:95:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:96:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |