답안 #520602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520602 2022-01-30T09:54:40 Z Vimmer Autobahn (COI21_autobahn) C++14
100 / 100
108 ms 8112 KB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)

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

#define F first
#define S second
#define PB push_back
#define M ll(1e9 + 7)
#define sz(x) (ll)x.size()
#define N 100500
#define pri(x) cout << x << endl
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

using namespace std;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;

ll a[N];

int main()
{
    istream::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, k, x;

    cin >> n >> k >> x;

    vector <int> vr; vr.clear();

    vector <int> dob; dob.clear();
    vector <int> del; del.clear();

    vector <int> db; db.clear();
    vector <int> dl; dl.clear();

    for (int i = 0; i < n; i++)
    {
        int l, r, t;

        cin >> l >> t >> r;

        dob.PB(l);

        del.PB(r + 1);

        vr.PB(r);

        if (l + t <= r)
        {
            db.PB(l + t);

            dl.PB(r + 1);
        }
    }

    sort(all(vr));

    vector <int> al; al.clear();

    vr.resize(unique(all(vr)) - vr.begin());

    vector <pair <int, int> > beg; beg.clear();

    vector <pair <int, int> > ed; ed.clear();

    for (int i = 0; i < sz(vr); i++)
    {
        beg.PB({max(1, vr[i] - x + 1), i});

        ed.PB({vr[i] + 1, i});
    }

    sort(all(beg));
    sort(all(ed));
    sort(all(dob));
    sort(all(del));
    sort(all(db));
    sort(all(dl));

    for (auto it : beg)
        al.PB(it.F);
    for (auto it : ed)
        al.PB(it.F);
    for (auto it : dob)
        al.PB(it);
    for (auto it : del)
        al.PB(it);
    for (auto it : db)
        al.PB(it);
    for (auto it : dl)
        al.PB(it);

    sort(all(al));

    ll ans = 0, cur = 0;

    int i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = 0, i6 = 0;

    int skok = 0, kol = 0;

    int lst = 0;

    for (auto x : al)
    {
//        pri(x _ cur);

        int len = x - lst;

        lst = x;

        if (skok >= k)
            cur += 1ll * len * kol;

        while (i1 < sz(beg) && beg[i1].F == x)
        {
            a[beg[i1].S] = cur;

            i1++;
        }

        while (i2 < sz(ed) && ed[i2].F == x)
        {
            ans = max(ans, cur - a[ed[i2].S]);

            i2++;
        }

        while (i3 < sz(dob) && dob[i3] == x)
        {
            skok++;

            i3++;
        }

        while (i4 < sz(del) && del[i4] == x)
        {
            skok--;

            i4++;
        }

        while (i5 < sz(db) && db[i5] == x)
        {
            kol++;

            i5++;
        }

        while (i6 < sz(dl) && dl[i6] == x)
        {
            kol--;

            i6++;
        }
    }

    pri(ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 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 1 ms 380 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 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 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 1 ms 380 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 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 99 ms 8036 KB Output is correct
22 Correct 101 ms 8048 KB Output is correct
23 Correct 97 ms 8056 KB Output is correct
24 Correct 108 ms 7996 KB Output is correct
25 Correct 97 ms 8056 KB Output is correct
26 Correct 98 ms 8112 KB Output is correct
27 Correct 97 ms 8052 KB Output is correct
28 Correct 95 ms 8092 KB Output is correct
29 Correct 98 ms 8048 KB Output is correct