Submission #520509

# Submission time Handle Problem Language Result Execution time Memory
520509 2022-01-30T08:06:42 Z kartel Autobahn (COI21_autobahn) C++14
50 / 100
380 ms 31188 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;

int pf[N];
ll cnt[N];
int pf1[N];
int l, r, t, n, k, x;
vector <int> v;
vector <pair <int, int> > 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 (int 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 <int, int> mp;
    v.pb(2e9);
    sort(all(v));
    v.resize(unique(all(v)) - v.begin());
    for (int i = 0; i < sz(v); i++) {
        mp[v[i]] = i + 1;
    }
    for (int i = 0; i < sz(seg); i++) {
        pf[mp[seg[i].F]]++;
        pf[mp[seg[i].S + 1]]--;
    }
    for (int 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 (int i = 0; i < sz(ex); i++) {
        pf1[mp[ex[i].F]]++;
        pf1[mp[ex[i].S + 1]]--;
    }
    for (int 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 (int 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 (int 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 (int 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 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 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 1 ms 204 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 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 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 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 2 ms 336 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 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 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 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 380 ms 31188 KB Output is correct
22 Correct 348 ms 31160 KB Output is correct
23 Correct 368 ms 31096 KB Output is correct
24 Correct 343 ms 31164 KB Output is correct
25 Incorrect 345 ms 31148 KB Output isn't correct
26 Halted 0 ms 0 KB -