답안 #1020754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1020754 2024-07-12T09:24:02 Z Blistering_Barnacles 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
//#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    struct Node{
        int cntmx, cntmn;
        int64_t lazy, mx1, mx2, mn1, mn2;
        Node(){
            mx1 = mx2 = (int64_t)-1e18;
            mn1 = mn2 = (int64_t)1e18;
            cntmn = cntmx = lazy = 0;
        }
        Node(int v){
            mx1 = mn1 = v;
            mn2 = (int)1e9 + 15, mx2 = (int)-1e9;
            cntmn = cntmx = 1;
            lazy = 0;
        }
    };
    int n = c.size(), q = (int)l.size(), k = c[0];
    vector<int> a(n);
    vector<Node> tree(4 * n + 15);
    auto mrg = [&](Node &a, Node &b){
        Node ret;
        if(a.mn1 == b.mn1){
            ret.mn1 = a.mn1, ret.mn2 = min(a.mn2, b.mn2), ret.cntmn = a.cntmn + b.cntmn;
        }
        else if(a.mn1 < b.mn1){
            ret.mn1 = a.mn1, ret.mn2 = min(b.mn1, a.mn2), ret.cntmn = a.cntmn;
        }
        else{
            ret.mn1 = b.mn1, ret.mn2 = min(b.mn2, a.mn1), ret.cntmn = b.cntmn;
        }
        if(a.mx1 == b.mx1){
            ret.mx1 = a.mx1, ret.mx2 = max(a.mx2, b.mx2), ret.cntmx = a.cntmx + b.cntmx;
        }
        else if(a.mx1 > b.mx1){
            ret.mx1 = a.mx1, ret.mx2 = max(a.mx2, b.mx1), ret.cntmx = a.cntmx;
        }
        else{
            ret.mx1 = b.mx1, ret.mx2 = max(a.mx1, b.mx2), ret.cntmx = b.cntmx;
        }
        return ret;
    };
    function<void(int, int, int)> build = [&](int s, int e, int node){
        if(s == e){
            tree[node] = Node(0);
            return;
        }
        int lx = node * 2, rx = node * 2 + 1, md = s + (e - s) / 2;
        build(s, md, lx), build(md + 1, e, rx);
        tree[node] = mrg(tree[lx], tree[rx]);
    };
    auto lz_add = [&](int s, int e, int node, int64_t val){
        if(!val)return;
        tree[node].mn1 += val, tree[node].mx1 += val;
        if(cntmx != e - s + 1)tree[node].mx2 += val;
        if(cntmn != e - s + 1)tree[node].mn2 += val;
        tree[node].lazy += val;
    };
    auto lz_mn = [&](int s, int e, int node, int64_t val){
        if(tree[node].mx1 <= val)return;
        tree[node].mx1 = val;
        if(cntmn == e - s + 1){
            tree[node].mn1 = val;
        }
        else if(tree[node].mn2 > val){
            tree[node].mn2 = val;
        }
    };
    auto lz_mx = [&](int s, int e, int node, int64_t val){
        if(tree[node].mn1 >= val)return;
        tree[node].mn1 = val;
        if(cntmx == e - s + 1){
            tree[node].mx1 = val;
        }
        else if(tree[node].mx2 < val){
            tree[node].mx2 = val;
        }
    };
    auto lz = [&](int s, int e, int node){
        if(s == e)return;
        int lx = node * 2, rx = node * 2 + 1, md = s + (e - s) / 2;
        lz_add(s, md, lx, tree[node].lazy), lz_add(md + 1, e, rx, tree[node].lazy);
        tree[node].lazy = 0;
        lz_mn(s, md, lx, tree[node].mx1), lz_mn(md + 1, e, rx, tree[nodee].mx1);
        lz_mx(s, md, lx, tree[node].mn1), lz_mx(md + 1, e, rx, tree[node].mn1);
    };
    function<void(int, int, int, int, int, int)> update_add = [&](int s, int e, int node, int l, int r, int val){
        lz(s, e, node);
        if(s > r || e < l)return;
        if(l <= s && e <= r){
            lz_add(s, e, node, val);
            return;
        }
        int lx = node * 2, rx = node * 2 + 1, md = s + (e - s) / 2;
        update_add(s, md, lx, l, r, val), update_add(md + 1, e, rx, l, r, val);
        tree[node] = mrg(tree[lx], tree[rx]);
    };
    function<void(int, int, int, int, int, int)> update_mn = [&](int s, int e, int node, int l, int r, int val){
        lz(s, e, node);
        if(s > r || e < l || tree[node].mx1 <= val)return;
        if(l <= s && e <= r && tree[node].mx2 < val){
            lz_mn(s, e, node, val);
            return;
        }
        int lx = node * 2, rx = node * 2 + 1, md = s + (e - s) / 2;
        update_mn(s, md, lx, l, r, val), update_mn(md + 1, e, rx, l, r, val);
        tree[node] = mrg(tree[lx], tree[rx]);
    };
    function<void(int, int, int, int, int, int)> update_mx = [&](int s, int e, int node, int l, int r, int val){
        lz(s, e, node);
        if(s > r || e < l || tree[node].mn1 >= val)return;
        if(l <= s && e <= r && tree[node].mn2 > val){
            lz_mx(s, e, node, val);
            return;
        }
        int lx = node * 2, rx = node * 2 + 1, md = s + (e - s) / 2;
        update_mx(s, md, lx, l, r, val), update_mx(md + 1, e, rx, l, r, val);
        tree[node] = mrg(tree[lx], tree[rx]);
    };
    function<void(int, int, int)> go = [&](int s, int e, int node){
        if(s == e){
            a[s] = tree[node].mx1;
            return;
        }
        lz(s, e, node);
        int lx = node * 2, rx = node * 2 + 1, md = s + (e - s) / 2;
        go(s, md, lx), go(md + 1, e, rx);
        tree[node] = mrg(tree[lx], tree[rx]);
    };
    build(0, n - 1, 1);
    for(int i = 0; i < q; i++){
        update_add(0, n - 1, 1, l[i], r[i], v[i]);
        if(v[i] > 0){
            update_mn(0, n - 1, 1, l[i], r[i], k);
        }
        else{
            update_mx(0, n - 1, 1, l[i], r[i], 0);
        }
    }
    go(0, n - 1, 1);
    return a;
}

Compilation message

candies.cpp: In lambda function:
candies.cpp:57:12: error: 'cntmx' was not declared in this scope
   57 |         if(cntmx != e - s + 1)tree[node].mx2 += val;
      |            ^~~~~
candies.cpp:58:12: error: 'cntmn' was not declared in this scope
   58 |         if(cntmn != e - s + 1)tree[node].mn2 += val;
      |            ^~~~~
candies.cpp: In lambda function:
candies.cpp:64:12: error: 'cntmn' was not declared in this scope
   64 |         if(cntmn == e - s + 1){
      |            ^~~~~
candies.cpp: In lambda function:
candies.cpp:74:12: error: 'cntmx' was not declared in this scope
   74 |         if(cntmx == e - s + 1){
      |            ^~~~~
candies.cpp: In lambda function:
candies.cpp:86:69: error: 'nodee' was not declared in this scope; did you mean 'node'?
   86 |         lz_mn(s, md, lx, tree[node].mx1), lz_mn(md + 1, e, rx, tree[nodee].mx1);
      |                                                                     ^~~~~
      |                                                                     node