Submission #520510

# Submission time Handle Problem Language Result Execution time Memory
520510 2022-01-30T08:07:21 Z kartel Autobahn (COI21_autobahn) C++14
100 / 100
494 ms 44212 KB
#include <bits/stdc++.h>
//#include<ext/rope>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC target("avx2")


#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define F first
#define S second
#define pb push_back
#define sz(x) int(x.size())
#define el '\n'
#define all(x) x.begin(), x.end()

using namespace std;
//using namespace __gnu_pbds;
//using  namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;
//typedef tree <ll, null_type, less <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 5e5 + 500;

ll pf[N];
ll cnt[N];
ll pf1[N];
ll l, r, t, n, k, x;
vector <ll> v;
vector <pair <ll, ll> > seg, ex;

int main()
{
//    cerr.precision(7);
//    cerr << fixed;
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    in("23.in");
//    in("input.txt");
//    out("output.txt");
//    clock_t start = clock();

    cin >> n >> k >> x;
    for (ll i = 1; i <= n; i++) {
        cin >> l >> t >> r;
        v.pb(l); v.pb(r); v.pb(r + 1);
        seg.pb({l, r});
        if (l + t <= r) {
            v.pb(l + t);
            ex.pb({l + t, r});
        }
    }

    map <ll, ll> mp;
    v.pb(2e9);
    sort(all(v));
    v.resize(unique(all(v)) - v.begin());
    for (ll i = 0; i < sz(v); i++) {
        mp[v[i]] = i + 1;
    }
    for (ll i = 0; i < sz(seg); i++) {
        pf[mp[seg[i].F]]++;
        pf[mp[seg[i].S + 1]]--;
    }
    for (ll i = 1; i <= sz(v); i++) {
        pf[i] += pf[i - 1];
        if (i != sz(v)) {
//            cout << "[" << v[i - 1] << ", " << v[i] << ")" << " = " << pf[i] << el;
        }
    }
    for (ll i = 0; i < sz(ex); i++) {
        pf1[mp[ex[i].F]]++;
        pf1[mp[ex[i].S + 1]]--;
    }
    for (ll i = 1; i <= sz(v); i++) {
        pf1[i] += pf1[i - 1];
        if (i != sz(v)) {
//            cout << "[" << v[i - 1] << ", " << v[i] << ")" << " = " << pf1[i] << el;
        }
    }
    for (ll i = 1; i <= sz(v); i++) {
        cnt[i] += cnt[i - 1];
        if (i < sz(v) && pf[i] >= k) {
            cnt[i] += pf1[i] * (v[i] - v[i - 1]);
        }
    }

    ll ans = 0;
    for (ll i = 1, j = 1; i < sz(v); i++) {
        while (j <= sz(v) && v[j - 1] - v[i - 1] < x) {
            j++;
        }
        ll cur = cnt[j - 1] - cnt[i - 1];
        if (pf[j - 1] >= k) {
            cur -= pf1[j - 1] * (v[j - 1] - (v[i - 1] + x - 1) - 1);
        }
//        cerr << v[i - 1] << " " << v[j - 1] << " " << cur << el;
        ans = max(ans, cur);
    }

    for (ll i = sz(v) - 1, j = i; i >= 1; i--) {
        while (j >= 1 && v[i] - v[j - 1] < x) {
            j--;
        }
        ll cur = cnt[i] - cnt[j - 1];
        if (pf[j] >= k) {
            cur -= pf1[j] * ((v[i] - x) - v[j - 1]);
        }
//        cerr << v[i - 1] << " " << v[j - 1] << " " << cur << el;
        ans = max(ans, cur);
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 474 ms 41460 KB Output is correct
22 Correct 480 ms 41512 KB Output is correct
23 Correct 475 ms 41508 KB Output is correct
24 Correct 476 ms 41492 KB Output is correct
25 Correct 477 ms 41516 KB Output is correct
26 Correct 474 ms 44164 KB Output is correct
27 Correct 487 ms 44168 KB Output is correct
28 Correct 494 ms 44212 KB Output is correct
29 Correct 472 ms 44204 KB Output is correct