Submission #47318187
Source Code Expand
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
// typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
typedef tree<pair<long long , long long>, null_type, less_equal<pair<long long , long long>>, rb_tree_tag, tree_order_statistics_node_update> pbds1; // find_by_order, order_of_key
// typedef tree<pair<long long , long long>, null_type, greater<pair<long long , long long>>, rb_tree_tag, tree_order_statistics_node_update> pbds2; // find_by_order, order_of_key
#define ll long long
// #define ll
// #define ll int
#define ld long double
#define int long long
#define inf 1000000000000000005
// #define inf 1000000005
#define mod 998244353
typedef pair<int, int> pii;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
#define pb push_back
#define ppb pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sz(x) (ll)x.size()
// #define ckmin(a,b) a = min(a,b)
// #define ckmax(a,b) a = max(a,b)
#define _BENZ_ ios_base::sync_with_stdio(false);cin.tie(NULL);
// const int N = 2e5 + 10;
template<class T> bool ckmin(T&a, T&b) { bool B = a > b; a = min(a,b); return B; }
template<class T> bool ckmax(T&a, T&b) { bool B = a < b; a = max(a,b); return B; }
// std::cout << std::fixed;
// std::cout << std::setprecision(12);
// floor(2.3)
// ceil(2.3)
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
}; // unordered_map<ll , ll , custom_hash> mp;
long long expo(long long a, long long b, long long mod1) {long long res = 1; while (b > 0) {if (b & 1ll)res = (res * a) % mod1; a = (a * a) % mod1; b = b >> 1ll;} return res;}
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::: SOLUTION TO THE PROBLEM :::::::::::::::::::::::::::::::::::::::::::::::::*/
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
/*
~By Editorial.
ANALYSE THE SAMPLES.
Kuch bold mein likha hai toh use dyan se do bar padho.
Think of the edge case (n == 1 ?).
Don't get stuck on a single approach for a long time.
Also don't get stuck on a single problem for a long time :)
target : want to be in top 100 of div2 contest( CODEFORCES ).
Agar kabhi koi easy problem kafi tough lagne lage problem ko do bar padh aur samples ko analyse kar
*/
/*
*/
const int _N = 200001;
void Pre() {
}
/*
Dp se bhi soch
Dp se bhi soch
Dp se bhi soch
*/
ll dx[] = {0 , 0 , 1 , -1 , 1 , 1 , -1 , -1};
ll dy[] = {1 , -1 , 0 , 0 , -1 , 1 , 1 , -1};
ll n , d , w;
vll _t;
vector<vll> adj;
class ST{
public:
vll t , lazy;
ST(ll _n) {
t.assign(4ll * (_n) + 7ll , 0ll);
lazy.assign(4ll * (_n) + 7ll , 0ll);
}
void build(ll ind , ll l , ll r) {
if(l == r) {
t[ind] = _t[l];
return;
}
ll mid = (l + r) / 2ll;
build(2ll * ind , l , mid);
build((2ll * ind) + 1ll , mid + 1ll , r);
t[ind] = max(t[2ll * ind] , t[(2ll * ind) + 1ll]);
}
void update(ll ind , ll l , ll r , ll lx , ll rx , ll val) {
if(lazy[ind]) {
t[ind] += lazy[ind];
if(l != r) {
lazy[2ll * ind] += lazy[ind];
lazy[(2ll * ind) + 1ll] += lazy[ind];
}
lazy[ind] = 0;
}
if((l > rx) or (r < lx)) return;
if((l >= lx) and (r <= rx)) {
t[ind] += val;
lazy[2ll * ind] += val; lazy[(2ll * ind) + 1ll] += val;
return;
}
ll mid = (l + r) / 2ll;
update(2ll * ind , l , mid , lx , rx , val);
update((2ll * ind) + 1ll , mid + 1ll , r , lx , rx , val);
t[ind] = max(t[2ll * ind] , t[(2ll * ind) + 1ll]);
}
ll get_max() {
return t[1ll];
}
};
void solve() {
// cout << "HAR HAR MAHADEV" << "\n";
cin >> n >> d >> w;
ST _s(_N); adj.assign(_N + 7ll , {}); _t.assign(_N + 7ll , 0ll);
for(ll i = 1; i <= n; ++i) {
ll x , t; cin >> t >> x;
adj[x].pb(t);
}
for(ll i = 1; i <= _N - 1ll; ++i) {
sort(adj[i].begin() , adj[i].end());
}
for(ll i = 1; i <= min(_N - 1ll , w); ++i) {
for(ll j = 0; j < sz(adj[i]); ++j) {
_t[adj[i][j]]++;
}
}
ll sum = 0ll;
for(ll i = 1; i <= min(d , _N - 1ll); ++i) {
sum += _t[i];
}
for(ll i = 1ll; i <= (_N - 1ll) - d + 1ll ; ++i) {
ll _sum = sum;
sum -= _t[i]; sum += _t[i + d];
_t[i] = _sum;
// ++_inx;
}
_s.build(1ll , 1ll , _N - 1ll);
ll ans = 0ll;
ans = max(_s.get_max() , ans);
for(ll i = 1ll; i <= (_N - 1ll) - w + 1ll ; ++i) {
for(ll j = 0; j < sz(adj[i]); ++j) {
_s.update(1ll , 1ll , _N - 1ll , max(adj[i][j] - d + 1ll , 1ll) , adj[i][j] , -1);
}
for(ll j = 0; j < sz(adj[i + w]); ++j) {
_s.update(1ll , 1ll , _N - 1ll , max(adj[i + w][j] - d + 1ll , 1ll) , adj[i + w][j] , 1);
}
ans = max(ans , _s.get_max());
}
cout << ans << "\n";
}
int32_t main(){
// freopen("teamwork.in","r",stdin);
// freopen("teamwork.out","w",stdout);
// //OR
// ifstream fin("input.in");
// ofstream fout("output.out");
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
_BENZ_
Pre();
ll t = 1;
// cin >> t;
while(t--){
solve();
}
// for(ll i = 1; i <= t; ++i) {
// cout << "Case "<<i<<": ";
// solve();
// }
return 0;
}
/*
*/
Submission Info
| Submission Time |
|
| Task |
F - Apples |
| User |
palsatyam877 |
| Language |
C++ 20 (gcc 12.2) |
| Score |
0 |
| Code Size |
6588 Byte |
| Status |
WA |
| Exec Time |
320 ms |
| Memory |
26116 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 550 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example_00.txt |
| All |
example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt |
| Case Name |
Status |
Exec Time |
Memory |
| example_00.txt |
AC |
11 ms |
21752 KiB |
| hand_00.txt |
AC |
126 ms |
24220 KiB |
| hand_01.txt |
AC |
129 ms |
24300 KiB |
| hand_02.txt |
AC |
69 ms |
23872 KiB |
| hand_03.txt |
AC |
66 ms |
26056 KiB |
| hand_04.txt |
AC |
78 ms |
24212 KiB |
| hand_05.txt |
AC |
10 ms |
21796 KiB |
| hand_06.txt |
AC |
10 ms |
21820 KiB |
| random_00.txt |
AC |
12 ms |
21752 KiB |
| random_01.txt |
AC |
11 ms |
21920 KiB |
| random_02.txt |
WA |
11 ms |
21792 KiB |
| random_03.txt |
AC |
11 ms |
21740 KiB |
| random_04.txt |
AC |
105 ms |
26100 KiB |
| random_05.txt |
WA |
258 ms |
26032 KiB |
| random_06.txt |
AC |
202 ms |
25980 KiB |
| random_07.txt |
AC |
320 ms |
26116 KiB |
| random_08.txt |
AC |
127 ms |
26028 KiB |
| random_09.txt |
AC |
233 ms |
26056 KiB |
| random_10.txt |
WA |
110 ms |
26116 KiB |
| random_11.txt |
AC |
254 ms |
26012 KiB |
| random_12.txt |
AC |
279 ms |
25188 KiB |
| random_13.txt |
AC |
263 ms |
24908 KiB |
| random_14.txt |
WA |
268 ms |
25520 KiB |
| random_15.txt |
AC |
263 ms |
25708 KiB |
| random_16.txt |
AC |
145 ms |
24728 KiB |
| random_17.txt |
AC |
172 ms |
24452 KiB |
| random_18.txt |
AC |
179 ms |
24644 KiB |
| random_19.txt |
AC |
151 ms |
24644 KiB |
| random_20.txt |
AC |
131 ms |
24432 KiB |
| random_21.txt |
AC |
128 ms |
24172 KiB |
| random_22.txt |
AC |
142 ms |
24464 KiB |
| random_23.txt |
AC |
78 ms |
24380 KiB |
| random_24.txt |
AC |
116 ms |
23668 KiB |
| random_25.txt |
AC |
94 ms |
23652 KiB |
| random_26.txt |
AC |
91 ms |
24532 KiB |
| random_27.txt |
AC |
105 ms |
23940 KiB |