답안 #365863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365863 2021-02-12T13:08:01 Z vaaven Two Dishes (JOI19_dishes) C++14
컴파일 오류
0 ms 0 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>//#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];
ll lzy[4*maxn];
ll mx[4*maxn];
void push(int n) {
    lzy[2*n] += lzy[n];
    lzy[2*n+1] += lzy[n];
    mx[2*n] += lzy[n];
    mx[2*n+1] += lzy[n];
    lzy[n] = 0;
}
void add(int n, int tl, int tr, int l, int r, ll ad) {
    if (tr < l || r < tl) {
        return;
    }
    if (l <= tl && tr <= r) {
        lzy[n] += ad;
        mx[n] += ad;
    }
    else {
        push(n);
        int tm = (tl + tr)/2;
        add(2*n, tl, tm, l, r, ad);
        add(2*n+1, tm+1, tr, l, r, ad);
        mx[n] = max(mx[2*n], mx[2*n+1]);
    }
}
ll get(int n, int tl, int tr, int l, int r) {
   if (tr < l || r < tl) {
        return -1e18;
    }
    if (l <= tl && tr <= r) {
        return mx[n];
    }
    else {
        push(n);
        int tm = (tl + tr)/2;
        return max(get(2*n, tl, tm, l, r), get(2*n+1, tm+1, tr, l, r));
    }
}
void upd(int n, int tl, int tr, int i, ll val) {
    if (tl == tr) {
        mx[n] = max(mx[n], val);
        lzy[n] = 0;
    }
    else {
        push(n);
        int tm = (tl + tr)/2;
        if (i <= tm) {
            upd(2*n, tl, tm, i, val);
        }
        else {
            upd(2*n+1, tm+1, tr, i, val);
        }
        mx[n] = max(mx[2*n], mx[2*n+1]);
    }
}

void solve(){
    int n, m;
    cin >> n >> m;
    for(int &i:mx)
        i = -1e18;
//    cout << t[0] << endl;
    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;
        }
        if(A[i] + B[m] <= S[i]){
            ans += P[i];
            continue;
        }
        int l = 0, r = m;
        int j = 0;
        while(l<r){
            int mid = (l+r+1)/2;
            if(B[mid] <= S[i]-A[i]){
                l = mid;
                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+1)/2;
            if(A[mid] <= T[i]-B[i]){
                l = mid;
                j = mid;
            } else{
                r = mid-1;
            }
        }
        ans += Q[i];
        if(j < n){
            kek[j+1].pb(make_pair(i-1, -Q[i]));
        }
    }
    upd(1, 0, maxn, 0, 0);
    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();
        }
    }
    ans += mx[1];
    cout << ans << 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();
}


#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){
    if(l==r){
        t[v] = max(k_new, t[v]);
        cnt[v] = 0;
    } 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;
        }
        if(A[i] + B[m] <= S[i]){
            ans += P[i];
            continue;
        }
        int l = 0, r = m;
        int j = 0;
        while(l<r){
            int mid = (l+r+1)/2;
            if(B[mid] <= S[i]-A[i]){
                l = mid;
                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+1)/2;
            if(A[mid] <= T[i]-B[i]){
                l = mid;
                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();
        }
    }
    ans += t[1];
    cout << ans << 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();
}

Compilation message

dishes.cpp:287:11: error: redefinition of 'const long long int inf'
  287 | const int inf = 1e9;
      |           ^~~
dishes.cpp:50:11: note: 'const long long int inf' previously defined here
   50 | const int inf = 1e9;
      |           ^~~
dishes.cpp:288:10: error: redefinition of 'const ll mod'
  288 | const ll mod = 1e9 + 7;
      |          ^~~
dishes.cpp:51:10: note: 'const ll mod' previously defined here
   51 | const ll mod = 1e9 + 7;
      |          ^~~
dishes.cpp:289:10: error: redefinition of 'const ll mod2'
  289 | const ll mod2 = 998244353;
      |          ^~~~
dishes.cpp:52:10: note: 'const ll mod2' previously defined here
   52 | const ll mod2 = 998244353;
      |          ^~~~
dishes.cpp:290:10: error: redefinition of 'const ld eps'
  290 | const ld eps = 1e-14;
      |          ^~~
dishes.cpp:53:10: note: 'const ld eps' previously defined here
   53 | const ld eps = 1e-14;
      |          ^~~
dishes.cpp:293:6: error: redefinition of 'void fast_io()'
  293 | void fast_io(){
      |      ^~~~~~~
dishes.cpp:56:6: note: 'void fast_io()' previously defined here
   56 | void fast_io(){
      |      ^~~~~~~
dishes.cpp:300:11: error: redefinition of 'const long long int maxn'
  300 | const int maxn = 1e6 + 228;
      |           ^~~~
dishes.cpp:63:11: note: 'const long long int maxn' previously defined here
   63 | const int maxn = 1e6 + 228;
      |           ^~~~
dishes.cpp:302:6: error: redefinition of 'vpii kek [1000228]'
  302 | vpii kek[maxn];
      |      ^~~
dishes.cpp:65:6: note: 'vpii kek [1000228]' previously declared here
   65 | vpii kek[maxn];
      |      ^~~
dishes.cpp:303:5: error: redefinition of 'long long int t [4000912]'
  303 | int t[maxn*4];
      |     ^
dishes.cpp:66:5: note: 'long long int t [4000912]' previously declared here
   66 | int t[maxn*4];
      |     ^
dishes.cpp:304:5: error: redefinition of 'long long int cnt [4000912]'
  304 | int cnt[maxn*4];
      |     ^~~
dishes.cpp:67:5: note: 'long long int cnt [4000912]' previously declared here
   67 | int cnt[maxn*4];
      |     ^~~
dishes.cpp:305:5: error: redefinition of 'long long int A [1000228]'
  305 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |     ^
dishes.cpp:68:5: note: 'long long int A [1000228]' previously declared here
   68 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |     ^
dishes.cpp:305:14: error: redefinition of 'long long int B [1000228]'
  305 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |              ^
dishes.cpp:68:14: note: 'long long int B [1000228]' previously declared here
   68 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |              ^
dishes.cpp:305:23: error: redefinition of 'long long int S [1000228]'
  305 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |                       ^
dishes.cpp:68:23: note: 'long long int S [1000228]' previously declared here
   68 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |                       ^
dishes.cpp:305:32: error: redefinition of 'long long int T [1000228]'
  305 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |                                ^
dishes.cpp:68:32: note: 'long long int T [1000228]' previously declared here
   68 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |                                ^
dishes.cpp:305:41: error: redefinition of 'long long int P [1000228]'
  305 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |                                         ^
dishes.cpp:68:41: note: 'long long int P [1000228]' previously declared here
   68 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |                                         ^
dishes.cpp:305:50: error: redefinition of 'long long int Q [1000228]'
  305 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |                                                  ^
dishes.cpp:68:50: note: 'long long int Q [1000228]' previously declared here
   68 | int A[maxn], B[maxn], S[maxn], T[maxn], P[maxn], Q[maxn];
      |                                                  ^
dishes.cpp:318:5: error: redefinition of 'long long int get(long long int, long long int, long long int, long long int, long long int)'
  318 | int get(int v, int l, int r, int ql, int qr){
      |     ^~~
dishes.cpp:94:4: note: 'll get(long long int, long long int, long long int, long long int, long long int)' previously defined here
   94 | ll get(int n, int tl, int tr, int l, int r) {
      |    ^~~
dishes.cpp:332:6: error: redefinition of 'void add(long long int, long long int, long long int, long long int, long long int, long long int)'
  332 | void add(int v, int l, int r, int ql, int qr, int k){
      |      ^~~
dishes.cpp:78:6: note: 'void add(long long int, long long int, long long int, long long int, long long int, ll)' previously defined here
   78 | void add(int n, int tl, int tr, int l, int r, ll ad) {
      |      ^~~
dishes.cpp:347:6: error: redefinition of 'void upd(long long int, long long int, long long int, long long int, long long int)'
  347 | void upd(int v, int l, int r, int k, int k_new){
      |      ^~~
dishes.cpp:107:6: note: 'void upd(long long int, long long int, long long int, long long int, ll)' previously defined here
  107 | void upd(int n, int tl, int tr, int i, ll val) {
      |      ^~~
dishes.cpp:362:6: error: redefinition of 'void solve()'
  362 | void solve(){
      |      ^~~~~
dishes.cpp:125:6: note: 'void solve()' previously defined here
  125 | void solve(){
      |      ^~~~~
dishes.cpp:487:8: error: redefinition of 'int main()'
  487 | signed main(){
      |        ^~~~
dishes.cpp:250:8: note: 'int main()' previously defined here
  250 | signed main(){
      |        ^~~~