이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
// author : a1abay
#define pb push_back
#define all(v) v.begin(), v.end()
#define int ll
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b / (__gcd(a, b)))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int inf = 1e9 + 7;
const int inff = 1e18 + 7;
const int sz = 2e5 + 5;
using namespace std;
int n, x;
vector<int> v;
int a[sz];
struct BIT
{
vector<int> t;
void init(){t.resize(sz, 0);}
int get(int i)
{
int r = 0;
for(; i > 0; i -= i & -i)r += t[i];
return r;
}
void upd(int i, int x)
{
for(; i < sz; i += i & -i)t[i] = x;
}
};
int ind(int x)
{
return upper_bound(all(v), x) - v.begin();
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> x;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
v.pb(a[i]);
v.pb(a[i] + x);
}
sort(all(v));
v.erase(unique(all(v)), v.end());
BIT l, r;
l.init();
r.init();
for(int i = 1; i <= n; i++)r.upd(ind(a[i] + x), 1);
int ans = 1;
for(int i = 1; i <= n; i++)
{
l.upd(ind(a[i]), 1);
r.upd(ind(a[i]), -1);
int lx = l.get(ind(a[i])) ;
int rx = r.get(ind(v.back())) - r.get(ind(a[i]));
ans = max(ans, lx + rx);
}
cout << ans;
}
# | 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... |