Submission #438618

# Submission time Handle Problem Language Result Execution time Memory
438618 2021-06-28T10:08:50 Z SorahISA Autobahn (COI21_autobahn) C++17
100 / 100
396 ms 41252 KB
// #pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define X first
#define Y second
#define eb emplace_back
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline int getRand(int L, int R) {
    if (L > R) swap(L, R);
    return (int)(rng() % (uint64_t)(R - L + 1) + L);
}

template<typename T1, typename T2>
ostream& operator << (ostream &os, pair<T1, T2> p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template<typename T>
ostream& operator << (ostream &os, vector<T> vec) {
    for (int i = 0; i < vec.size(); ++i) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}

const int INF = INT_MAX;

struct People {
    int l, t, r;
    
    friend istream& operator >> (istream &is, People &people) {
        is >> people.l >> people.t >> people.r;
        return is;
    }
};

void solve() {
    int N, K, X; cin >> N >> K >> X;
    
    vector<People> people(N);
    // vector<int> cnt(1005, 0), sum(1005, 0);
    map<int, pii> cnt;
    for (auto &p : people) {
        cin >> p, ++cnt[p.l].X, --cnt[p.r+1].X;
        ++cnt[p.l+p.t].Y, --cnt[p.r+1].Y;
    }
    
    // partial_sum(ALL(cnt), begin(cnt));
    vector<pair<int, pii>> precnt(1, {0, {0, 0}});
    for (auto &[key, val] : cnt) precnt.eb(key, pii{precnt.back().Y.X + val.X, precnt.back().Y.Y + val.Y});
    for (auto &[key, val] : precnt) if (val.X < K) val.Y = 0;
    
    vector<pair<pii, int>> val;
    for (int i = 1; i < precnt.size()-1; ++i) {
        if (precnt[i].Y.Y) val.eb(pii{precnt[i].X, precnt[i+1].X-1}, precnt[i].Y.Y);
    }
    
    int ans = 0;
    for (int L = val[0].X.X, R = val[0].X.Y, tokL = 0, tokR = 0, sum = 0; tokR < val.size(); R = val[++tokR].X.Y) {
        sum += (val[tokR].X.Y - val[tokR].X.X + 1) * val[tokR].Y;
        while (L <= R - X) {
            if (val[tokL].X.Y > R - X) {
                sum -= ((R - X + 1) - L) * val[tokL].Y;
                L = R - X + 1;
            }
            else {
                sum -= (val[tokL].X.Y - L + 1) * val[tokL].Y;
                L = val[++tokL].X.X;
            }
        }
        // cout << sum << "\n";
        ans = max(ans, sum);
    }
    cout << ans << "\n";
    
    // cout << cnt << "\n";
    // cout << precnt << "\n";
    // cout << val << "\n";
}

int32_t main() {
    fastIO();
    
    int t = 1; // cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        // cout << "Case #" << _ << ": ";
        solve();
    }
    
    return 0;
}

Compilation message

autobahn.cpp: In function 'void solve()':
autobahn.cpp:70:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for (int i = 1; i < precnt.size()-1; ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~
autobahn.cpp:75:80: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for (int L = val[0].X.X, R = val[0].X.Y, tokL = 0, tokR = 0, sum = 0; tokR < val.size(); R = val[++tokR].X.Y) {
      |                                                                           ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 2 ms 444 KB Output is correct
13 Correct 2 ms 448 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 452 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 2 ms 432 KB Output is correct
20 Correct 2 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 2 ms 444 KB Output is correct
13 Correct 2 ms 448 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 452 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 2 ms 432 KB Output is correct
20 Correct 2 ms 440 KB Output is correct
21 Correct 371 ms 41248 KB Output is correct
22 Correct 352 ms 41128 KB Output is correct
23 Correct 389 ms 41252 KB Output is correct
24 Correct 352 ms 41252 KB Output is correct
25 Correct 371 ms 41220 KB Output is correct
26 Correct 380 ms 41104 KB Output is correct
27 Correct 396 ms 41108 KB Output is correct
28 Correct 368 ms 41200 KB Output is correct
29 Correct 366 ms 41200 KB Output is correct