Submission #365808

# Submission time Handle Problem Language Result Execution time Memory
365808 2021-02-12T12:04:25 Z vaaven Two Dishes (JOI19_dishes) C++14
5 / 100
449 ms 91500 KB
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <stack>
#include <iomanip>
#include <bitset>
#include <map>
#include <cassert>
#include <array>
#include <queue>
#include <cstring>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
#define int long  long

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;

const int inf = 1e9;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-14;


void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen("cbs.in", "r", stdin);
//    freopen("cbs.out", "w", stdout);
}

const int maxn = 1e6 + 228;

vpii kek[maxn];
int t[maxn*4];
int cnt[maxn*4];
int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];

void push(int v, int l, int r){
    if(cnt[v] != 0){
        t[v] += cnt[v];
        if(l != r){
            cnt[v*2] += cnt[v];
            cnt[v*2+1] += cnt[v];
        }
        cnt[v] = 0;
    }
}

int get(int v, int l, int r, int ql, int qr){
    push(v, l, r);
    if(ql <= l && r <= qr){
        return t[v];
    } else if(l > qr || ql > r){
        return -1e18;
    } else{
        int mid = (l + r)/2;
        int ans = max(get(v*2, l, mid, ql, qr), get(v*2+1, mid+1, r, ql, qr));
        t[v] = max(t[v*2], t[v*2+1]);
        return ans;
    }
}

void add(int v, int l, int r, int ql, int qr, int k){
    push(v, l, r);
    if(ql <= l && r <= qr){
        cnt[v] += k;
        push(v, l, r);
    } else if(l > qr || ql > r){
        return;
    } else{
        int mid = (l+r)/2;
        add(v*2, l, mid, ql, qr, k);
        add(v*2+1, mid+1, r, ql, qr, k);
        t[v] = max(t[v*2], t[v*2+1]);
    }
}

void upd(int v, int l, int r, int k, int k_new){
    push(v, l, r);
    if(l==r){
        t[v] = max(k_new, t[v]);
    } else{
        int mid = (l+r)/2;
        if(k <= mid){
            upd(v*2, l, mid, k, k_new);
        } else{
            upd(v*2+1, mid+1, r, k, k_new);
        }
        t[v] = max(t[v*2], t[v*2+1]);
    }
}

void solve(){
    int n, m;
    cin >> n >> m;
    for(int &i:t)
        i = -1e18;
//    cout << t[0] << endl;
    upd(1, 0, maxn, 0, 0);
    for(int i=1; i<=n; i++){
        cin >> A[i] >> S[i] >> P[i];
        A[i] += A[i-1];
    }
    for(int i=1; i<=m; i++){
        cin >> B[i] >> T[i] >> Q[i];
        B[i] += B[i-1];
    }
    int ans = 0;
    for(int i=1; i<=n; i++){
        if(A[i] > S[i]){
            continue;
        }
        int l = 0, r = m;
        int j = 0;
        while(l<=r){
            int mid = (l+r)/2;
            if(B[mid] <= S[i]-A[i]){
                l = mid+1;
                j = mid;
            } else{
                r = mid-1;
            }
        }
        kek[i].pb(make_pair(j, P[i]));
    }
    for(int i=1; i<=m; i++){
        if(B[i] > T[i]){
            continue;
        }
        int l = 0, r = n;
        int j = 0;
        while(l<=r){
            int mid = (l+r)/2;
            if(A[mid] <= T[i]-B[i]){
                l = mid+1;
                j = mid;
            } else{
                r = mid-1;
            }
        }
        ans += Q[i];
        if(j < n){
            kek[j+1].pb(make_pair(i-1, -Q[i]));
        }
    }
    for(int i=0; i<=n; i++){
        sort(all(kek[i]));
        while(!kek[i].empty()){
            while(kek[i].size() > 1){
                if(kek[i][kek[i].size()-1].first == kek[i][kek[i].size()-2].first){
                    kek[i][kek[i].size()-2].second += kek[i][kek[i].size()-1].second;
                    kek[i].pop_back();
                } else{
                    break;
                }
            }
            int lol = get(1, 0, maxn, 0, kek[i].back().first);
            upd(1, 0, maxn, kek[i].back().first+1, lol);
            add(1, 0, maxn, 0, kek[i].back().first, kek[i].back().second);
            kek[i].pop_back();
        }
    }
    cout << ans + get(1, 0, maxn, 0, m) << endl;
}

/*
4 3
2 1 1
3 8 1
2 13 1
1 13 1
3 6 1
2 11 1
2 15 1
======
5 7
16 73 16
17 73 10
20 73 1
14 73 16
18 73 10
3 73 2
10 73 7
16 73 19
12 73 4
15 73 15
20 73 14
15 73 8
=========
 9 11
 86 565 58
 41 469 -95
 73 679 28
 91 585 -78
 17 513 -63
 48 878 -66
 66 901 59
 72 983 -70
 68 1432 11
 42 386 -87
 36 895 57
 100 164 10
 96 812 -6
 23 961 -66
 54 193 51
 37 709 82
 62 148 -36
 28 853 22
 15 44 53
 77 660 -19
 */

signed main(){
     fast_io();
//  srand(time(NULL));
    cout << fixed << setprecision(10);
    int q = 1;
//    cin >> q;
    while(q--)
        solve();
}

# Verdict Execution time Memory Grader output
1 Correct 437 ms 91244 KB Output is correct
2 Correct 449 ms 91500 KB Output is correct
3 Correct 365 ms 84460 KB Output is correct
4 Correct 339 ms 86400 KB Output is correct
5 Correct 34 ms 55148 KB Output is correct
6 Correct 426 ms 89580 KB Output is correct
7 Correct 120 ms 66832 KB Output is correct
8 Correct 273 ms 73228 KB Output is correct
9 Correct 396 ms 85356 KB Output is correct
10 Correct 358 ms 85100 KB Output is correct
11 Correct 320 ms 78748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 55276 KB Output is correct
2 Correct 35 ms 55144 KB Output is correct
3 Correct 36 ms 55276 KB Output is correct
4 Correct 36 ms 55276 KB Output is correct
5 Correct 36 ms 55296 KB Output is correct
6 Correct 34 ms 55148 KB Output is correct
7 Correct 35 ms 55276 KB Output is correct
8 Correct 35 ms 55276 KB Output is correct
9 Correct 34 ms 55276 KB Output is correct
10 Incorrect 34 ms 55276 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 55276 KB Output is correct
2 Correct 35 ms 55144 KB Output is correct
3 Correct 36 ms 55276 KB Output is correct
4 Correct 36 ms 55276 KB Output is correct
5 Correct 36 ms 55296 KB Output is correct
6 Correct 34 ms 55148 KB Output is correct
7 Correct 35 ms 55276 KB Output is correct
8 Correct 35 ms 55276 KB Output is correct
9 Correct 34 ms 55276 KB Output is correct
10 Incorrect 34 ms 55276 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 55276 KB Output is correct
2 Correct 35 ms 55144 KB Output is correct
3 Correct 36 ms 55276 KB Output is correct
4 Correct 36 ms 55276 KB Output is correct
5 Correct 36 ms 55296 KB Output is correct
6 Correct 34 ms 55148 KB Output is correct
7 Correct 35 ms 55276 KB Output is correct
8 Correct 35 ms 55276 KB Output is correct
9 Correct 34 ms 55276 KB Output is correct
10 Incorrect 34 ms 55276 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 55276 KB Output is correct
2 Correct 35 ms 55144 KB Output is correct
3 Correct 36 ms 55276 KB Output is correct
4 Correct 36 ms 55276 KB Output is correct
5 Correct 36 ms 55296 KB Output is correct
6 Correct 34 ms 55148 KB Output is correct
7 Correct 35 ms 55276 KB Output is correct
8 Correct 35 ms 55276 KB Output is correct
9 Correct 34 ms 55276 KB Output is correct
10 Incorrect 34 ms 55276 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 55276 KB Output is correct
2 Correct 35 ms 55144 KB Output is correct
3 Correct 36 ms 55276 KB Output is correct
4 Correct 36 ms 55276 KB Output is correct
5 Correct 36 ms 55296 KB Output is correct
6 Correct 34 ms 55148 KB Output is correct
7 Correct 35 ms 55276 KB Output is correct
8 Correct 35 ms 55276 KB Output is correct
9 Correct 34 ms 55276 KB Output is correct
10 Incorrect 34 ms 55276 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 437 ms 91244 KB Output is correct
2 Correct 449 ms 91500 KB Output is correct
3 Correct 365 ms 84460 KB Output is correct
4 Correct 339 ms 86400 KB Output is correct
5 Correct 34 ms 55148 KB Output is correct
6 Correct 426 ms 89580 KB Output is correct
7 Correct 120 ms 66832 KB Output is correct
8 Correct 273 ms 73228 KB Output is correct
9 Correct 396 ms 85356 KB Output is correct
10 Correct 358 ms 85100 KB Output is correct
11 Correct 320 ms 78748 KB Output is correct
12 Correct 35 ms 55276 KB Output is correct
13 Correct 35 ms 55144 KB Output is correct
14 Correct 36 ms 55276 KB Output is correct
15 Correct 36 ms 55276 KB Output is correct
16 Correct 36 ms 55296 KB Output is correct
17 Correct 34 ms 55148 KB Output is correct
18 Correct 35 ms 55276 KB Output is correct
19 Correct 35 ms 55276 KB Output is correct
20 Correct 34 ms 55276 KB Output is correct
21 Incorrect 34 ms 55276 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 437 ms 91244 KB Output is correct
2 Correct 449 ms 91500 KB Output is correct
3 Correct 365 ms 84460 KB Output is correct
4 Correct 339 ms 86400 KB Output is correct
5 Correct 34 ms 55148 KB Output is correct
6 Correct 426 ms 89580 KB Output is correct
7 Correct 120 ms 66832 KB Output is correct
8 Correct 273 ms 73228 KB Output is correct
9 Correct 396 ms 85356 KB Output is correct
10 Correct 358 ms 85100 KB Output is correct
11 Correct 320 ms 78748 KB Output is correct
12 Correct 35 ms 55276 KB Output is correct
13 Correct 35 ms 55144 KB Output is correct
14 Correct 36 ms 55276 KB Output is correct
15 Correct 36 ms 55276 KB Output is correct
16 Correct 36 ms 55296 KB Output is correct
17 Correct 34 ms 55148 KB Output is correct
18 Correct 35 ms 55276 KB Output is correct
19 Correct 35 ms 55276 KB Output is correct
20 Correct 34 ms 55276 KB Output is correct
21 Incorrect 34 ms 55276 KB Output isn't correct
22 Halted 0 ms 0 KB -