답안 #708788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
708788 2023-03-12T09:52:23 Z PixelCat Two Dishes (JOI19_dishes) C++14
49 / 100
599 ms 57856 KB
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

// const int MAXN = 1000010;
const int MAXN = 200010;
const int INF = 9e18;

// range add, range max
#define L(id) ((id) * 2 + 1)
#define R(id) ((id) * 2 + 2)
struct SegTree {
    struct Node {
        int mx, add;
    } a[MAXN << 2];
    void init(int val) {
        For(i, 0, (MAXN << 2) - 1) {
            a[i].mx = val;
            a[i].add = 0;
        }
    }
    void _add(int id, int x) {
        a[id].add += x;
        a[id].mx += x;
    }
    void pull(int id) {
        a[id].mx = max(a[L(id)].mx, a[R(id)].mx);
    }
    void push(int id) {
        if(a[id].add != 0) {
            _add(L(id), a[id].add);
            _add(R(id), a[id].add);
            a[id].add = 0;
        }
    }
    void add(int id, int l, int r, int L, int R, int x) {
        // if(l > R || r < L) return;
        if(l >= L && r <= R) {
            _add(id, x);
            return;
        }
        push(id);
        int m = (l + r) / 2;
        if(L <= m) add(L(id), l, m, L, R, x);
        if(R > m)  add(R(id), m + 1, r, L, R, x);
        pull(id);
    }
    void set(int id, int l, int r, int i, int x) {
        if(l == r) {
            a[id].mx = x;
            a[id].add = 0;
            return;
        }
        push(id);
        int m = (l + r) / 2;
        if(i <= m) set(L(id), l, m, i, x);
        else       set(R(id), m + 1, r, i, x);
        pull(id);
    }
    int ask(int id, int l, int r, int L, int R) {
        if(l >= L && r <= R) return a[id].mx;
        push(id);
        int m = (l + r) / 2;
        int res = -INF;
        if(L <= m) res = max(res, ask(L(id), l, m, L, R));
        if(R > m)  res = max(res, ask(R(id), m + 1, r, L, R));
        return res;
    }
} seg, seg2, seg3;

int a1[MAXN];
int s1[MAXN];
int p1[MAXN];
int pr1[MAXN];
int t1[MAXN];

int a2[MAXN];
int s2[MAXN];
int p2[MAXN];
int pr2[MAXN];
int t2[MAXN];

// int su[MAXN][MAXN];
int dp[MAXN];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // NYA =^-w-^=
    int n, m;
// #define QWQ
#ifndef QWQ
    cin >> n >> m;
    assert(n <= MAXN);
    For(i, 1, n) {
        cin >> a1[i] >> s1[i] >> p1[i];
        pr1[i] = pr1[i - 1] + a1[i];
    }
    For(i, 1, m) {
        cin >> a2[i] >> s2[i] >> p2[i];
        pr2[i] = pr2[i - 1] + a2[i];
    }
#else
    mt19937 rng(48763);
    n = m = 5;
    For(i, 1, n) {
        a1[i] = rng() % 10 + 1;
        s1[i] = rng() % 100 + 1;
        p1[i] = 1;
        pr1[i] = pr1[i - 1] + a1[i];
    }
    For(i, 1, m) {
        a2[i] = rng() % 10 + 1;
        s2[i] = rng() % 100 + 1;
        p2[i] = 1;
        pr2[i] = pr2[i - 1] + a2[i];
    }
#endif

    vector<pii> v;
    For(i, 1, n) {
        auto it = upper_bound(pr2, pr2 + m + 1, s1[i] - pr1[i]);
        t1[i] = it - pr2 - 1;
        if(t1[i] >= 0) v.eb(t1[i], i);
    }
    sort(all(v));
    reverse(all(v));
    
    For(i, 1, m) {
        auto it = upper_bound(pr1, pr1 + n + 1, s2[i] - pr2[i]);
        t2[i] = it - pr1 - 1;
        // For(j, 0, t2[i]) {
        //     su[j][i]++;
        // }
    }

    // For(i, 0, n) For(j, 1, m) su[i][j] += su[i][j - 1];
    // int ans = su[0][m];
    // For(i, 1, n) if(t1[i] >= 0) {
    //     int add = 0;
    //     dp[i] = 0;
    //     Forr(i2, i - 1, 1) if(t1[i2] >= 0) {
    //         if(t1[i2] > t1[i]) add++;
    //         else {
    //             dp[i] = max(dp[i], dp[i2] + su[i2][t1[i]] - su[i2][t1[i2]] + add + 1);
    //         }
    //     }
    //     dp[i] = max(dp[i], su[0][t1[i]] + add + 1);
    //     ans = max(ans, dp[i] + su[i][m] - su[i][t1[i]]);
    // }
    
    seg.init(-INF);
    seg2.init(0);
    for(auto &i:v) {
        seg2.add(0, 0, n, i.S, n, 1);
    }
    seg.set(0, 0, n, 0, 0);

    int ans = 0;
    For(it, 0, m) {
        if(it && (t2[it] >= 0)) {
            seg.add(0, 0, n, 0, t2[it], 1);
        }
        while(sz(v) && v.back().F == it) {
            int i = v.back().S;
            v.pop_back();

            seg2.add(0, 0, n, i, n, -1);
            seg.add(0, 0, n, i, n, 1);
            
            int val = seg.ask(0, 0, n, 0, i - 1) + seg2.ask(0, 0, n, i, i) + 1;
            assert(val >= 0);
            // cout << i << " " << val << "\n";
            // For(j, 0, n) cout << seg2.ask(0, 0, n, j, j) << " \n"[j == n];
            // For(j, 0, n) cout << seg.ask(0, 0, n, j, j) << " \n"[j == n];
            seg.set(0, 0, n, i, val - seg2.ask(0, 0, n, i, i));
        }
    }
    cout << seg.ask(0, 0, n, 0, n) << "\n";
    return 0;

    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 357 ms 56384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25428 KB Output is correct
2 Correct 11 ms 25344 KB Output is correct
3 Correct 11 ms 25428 KB Output is correct
4 Correct 11 ms 25384 KB Output is correct
5 Correct 13 ms 25428 KB Output is correct
6 Correct 14 ms 25428 KB Output is correct
7 Correct 11 ms 25332 KB Output is correct
8 Correct 12 ms 25428 KB Output is correct
9 Correct 11 ms 25356 KB Output is correct
10 Correct 11 ms 25360 KB Output is correct
11 Correct 12 ms 25428 KB Output is correct
12 Correct 10 ms 25428 KB Output is correct
13 Correct 11 ms 25428 KB Output is correct
14 Correct 11 ms 25436 KB Output is correct
15 Correct 11 ms 25368 KB Output is correct
16 Correct 11 ms 25428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25428 KB Output is correct
2 Correct 11 ms 25344 KB Output is correct
3 Correct 11 ms 25428 KB Output is correct
4 Correct 11 ms 25384 KB Output is correct
5 Correct 13 ms 25428 KB Output is correct
6 Correct 14 ms 25428 KB Output is correct
7 Correct 11 ms 25332 KB Output is correct
8 Correct 12 ms 25428 KB Output is correct
9 Correct 11 ms 25356 KB Output is correct
10 Correct 11 ms 25360 KB Output is correct
11 Correct 12 ms 25428 KB Output is correct
12 Correct 10 ms 25428 KB Output is correct
13 Correct 11 ms 25428 KB Output is correct
14 Correct 11 ms 25436 KB Output is correct
15 Correct 11 ms 25368 KB Output is correct
16 Correct 11 ms 25428 KB Output is correct
17 Correct 13 ms 25556 KB Output is correct
18 Correct 13 ms 25556 KB Output is correct
19 Correct 14 ms 25556 KB Output is correct
20 Correct 14 ms 25644 KB Output is correct
21 Correct 15 ms 25672 KB Output is correct
22 Correct 14 ms 25576 KB Output is correct
23 Correct 13 ms 25656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25428 KB Output is correct
2 Correct 11 ms 25344 KB Output is correct
3 Correct 11 ms 25428 KB Output is correct
4 Correct 11 ms 25384 KB Output is correct
5 Correct 13 ms 25428 KB Output is correct
6 Correct 14 ms 25428 KB Output is correct
7 Correct 11 ms 25332 KB Output is correct
8 Correct 12 ms 25428 KB Output is correct
9 Correct 11 ms 25356 KB Output is correct
10 Correct 11 ms 25360 KB Output is correct
11 Correct 12 ms 25428 KB Output is correct
12 Correct 10 ms 25428 KB Output is correct
13 Correct 11 ms 25428 KB Output is correct
14 Correct 11 ms 25436 KB Output is correct
15 Correct 11 ms 25368 KB Output is correct
16 Correct 11 ms 25428 KB Output is correct
17 Correct 13 ms 25556 KB Output is correct
18 Correct 13 ms 25556 KB Output is correct
19 Correct 14 ms 25556 KB Output is correct
20 Correct 14 ms 25644 KB Output is correct
21 Correct 15 ms 25672 KB Output is correct
22 Correct 14 ms 25576 KB Output is correct
23 Correct 13 ms 25656 KB Output is correct
24 Correct 368 ms 54764 KB Output is correct
25 Correct 262 ms 53228 KB Output is correct
26 Correct 324 ms 54864 KB Output is correct
27 Correct 263 ms 53268 KB Output is correct
28 Correct 373 ms 54580 KB Output is correct
29 Correct 311 ms 55580 KB Output is correct
30 Correct 599 ms 54860 KB Output is correct
31 Correct 95 ms 38356 KB Output is correct
32 Correct 274 ms 41664 KB Output is correct
33 Correct 337 ms 52828 KB Output is correct
34 Correct 501 ms 54560 KB Output is correct
35 Correct 547 ms 48560 KB Output is correct
36 Correct 507 ms 48444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25428 KB Output is correct
2 Correct 11 ms 25344 KB Output is correct
3 Correct 11 ms 25428 KB Output is correct
4 Correct 11 ms 25384 KB Output is correct
5 Correct 13 ms 25428 KB Output is correct
6 Correct 14 ms 25428 KB Output is correct
7 Correct 11 ms 25332 KB Output is correct
8 Correct 12 ms 25428 KB Output is correct
9 Correct 11 ms 25356 KB Output is correct
10 Correct 11 ms 25360 KB Output is correct
11 Correct 12 ms 25428 KB Output is correct
12 Correct 10 ms 25428 KB Output is correct
13 Correct 11 ms 25428 KB Output is correct
14 Correct 11 ms 25436 KB Output is correct
15 Correct 11 ms 25368 KB Output is correct
16 Correct 11 ms 25428 KB Output is correct
17 Correct 13 ms 25556 KB Output is correct
18 Correct 13 ms 25556 KB Output is correct
19 Correct 14 ms 25556 KB Output is correct
20 Correct 14 ms 25644 KB Output is correct
21 Correct 15 ms 25672 KB Output is correct
22 Correct 14 ms 25576 KB Output is correct
23 Correct 13 ms 25656 KB Output is correct
24 Correct 368 ms 54764 KB Output is correct
25 Correct 262 ms 53228 KB Output is correct
26 Correct 324 ms 54864 KB Output is correct
27 Correct 263 ms 53268 KB Output is correct
28 Correct 373 ms 54580 KB Output is correct
29 Correct 311 ms 55580 KB Output is correct
30 Correct 599 ms 54860 KB Output is correct
31 Correct 95 ms 38356 KB Output is correct
32 Correct 274 ms 41664 KB Output is correct
33 Correct 337 ms 52828 KB Output is correct
34 Correct 501 ms 54560 KB Output is correct
35 Correct 547 ms 48560 KB Output is correct
36 Correct 507 ms 48444 KB Output is correct
37 Incorrect 348 ms 57856 KB Output isn't correct
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25428 KB Output is correct
2 Correct 11 ms 25344 KB Output is correct
3 Correct 11 ms 25428 KB Output is correct
4 Correct 11 ms 25384 KB Output is correct
5 Correct 13 ms 25428 KB Output is correct
6 Correct 14 ms 25428 KB Output is correct
7 Correct 11 ms 25332 KB Output is correct
8 Correct 12 ms 25428 KB Output is correct
9 Correct 11 ms 25356 KB Output is correct
10 Correct 11 ms 25360 KB Output is correct
11 Correct 12 ms 25428 KB Output is correct
12 Correct 10 ms 25428 KB Output is correct
13 Correct 11 ms 25428 KB Output is correct
14 Correct 11 ms 25436 KB Output is correct
15 Correct 11 ms 25368 KB Output is correct
16 Correct 11 ms 25428 KB Output is correct
17 Correct 13 ms 25556 KB Output is correct
18 Correct 13 ms 25556 KB Output is correct
19 Correct 14 ms 25556 KB Output is correct
20 Correct 14 ms 25644 KB Output is correct
21 Correct 15 ms 25672 KB Output is correct
22 Correct 14 ms 25576 KB Output is correct
23 Correct 13 ms 25656 KB Output is correct
24 Correct 368 ms 54764 KB Output is correct
25 Correct 262 ms 53228 KB Output is correct
26 Correct 324 ms 54864 KB Output is correct
27 Correct 263 ms 53268 KB Output is correct
28 Correct 373 ms 54580 KB Output is correct
29 Correct 311 ms 55580 KB Output is correct
30 Correct 599 ms 54860 KB Output is correct
31 Correct 95 ms 38356 KB Output is correct
32 Correct 274 ms 41664 KB Output is correct
33 Correct 337 ms 52828 KB Output is correct
34 Correct 501 ms 54560 KB Output is correct
35 Correct 547 ms 48560 KB Output is correct
36 Correct 507 ms 48444 KB Output is correct
37 Incorrect 348 ms 57856 KB Output isn't correct
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 357 ms 56384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 357 ms 56384 KB Output isn't correct
2 Halted 0 ms 0 KB -