Submission #1019539

# Submission time Handle Problem Language Result Execution time Memory
1019539 2024-07-11T03:23:07 Z aufan Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include "candies.h"
#include <bits/stdc++.h>

using namespace std;

const long long inf = 1e9;

struct node {
    long long val, lz, lb, ub;
    int st, en;
    node *left, *right;

    void build(int start, int end) {
        st = start;
        en = end;
        lz = 0;
        lb = -inf;
        ub = inf;

        if (st == en) {
            val = 0;
            return;
        }

        int md = (st + en) / 2;
        left = new node();
        right = new node();

        left->build(st, md);
        right->build(md + 1, en);
    }

    void lazy() {
        left->val += lz;
        left->lz += lz;
        left->val = max(left->val, lb);
        left->lb = max(left->lb, lb);
        left->ub = max(left->ub, lb);
        left->val = min(left->val, ub);
        left->lb = min(left->lb, ub);
        left->ub = min(left->ub, ub);

        right->val += lz;
        right->lz += lz;
        right->val = max(right->val, lb);
        right->lb = max(right->lb, lb);
        right->ub = max(right->ub, lb);
        right->val = min(right->val, ub);
        right->lb = min(right->lb, ub);
        right->ub = min(right->ub, ub);

        lz = 0;
        lb = -inf;
        ub = inf;
    }

    long long query(int id) {
        if (st > id || en < id) return 0ll;
        if (st == en) return val;
        lazy();
        return left->query(id) + right->query(id);
    }

    void update(int lf, int rg, int x) {
        if (st > rg || en < lf) return;
        if (lf <= st && en <= rg) {
            val += lz;
            lz += x;
            return;
        }

        lazy();
        left->update(lf, rg, x);
        right->update(lf, rg, x);
    }

    void update2(int lf, int rg, int x, int y) {
        if (st > rg || en < lf) return;
        if (lf <= st && en <= rg) {
            val = max(val, x);
            lb = max(lb, x);
            ub = max(ub, x);
            
            val = min(val, y);
            lb = min(lb, y);
            ub = min(ub, y);
            return;
        }

        lazy();
        left->update2(lf, rg, x, y);
        right->update2(lf, rg, x, y);
    }
} sg;

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int n = c.size(), q = (int)l.size();
    vector<int> s(n);
    sg.build(0, n - 1);
    for (int i = 0; i < q; i++) {
        sg.update(l[i], r[i], v[i]);
        sg.update2(0, n - 1, 0, c[0]);
    }

    for (int i = 0; i < n; i++) {
        s[i] = sg.query(i);
    }

    return s;
}

Compilation message

candies.cpp: In member function 'void node::update2(int, int, int, int)':
candies.cpp:80:29: error: no matching function for call to 'max(long long int&, int&)'
   80 |             val = max(val, x);
      |                             ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
candies.cpp:80:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   80 |             val = max(val, x);
      |                             ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
candies.cpp:80:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   80 |             val = max(val, x);
      |                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
candies.cpp:80:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   80 |             val = max(val, x);
      |                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
candies.cpp:80:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   80 |             val = max(val, x);
      |                             ^
candies.cpp:81:27: error: no matching function for call to 'max(long long int&, int&)'
   81 |             lb = max(lb, x);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
candies.cpp:81:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   81 |             lb = max(lb, x);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
candies.cpp:81:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   81 |             lb = max(lb, x);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
candies.cpp:81:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   81 |             lb = max(lb, x);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
candies.cpp:81:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   81 |             lb = max(lb, x);
      |                           ^
candies.cpp:82:27: error: no matching function for call to 'max(long long int&, int&)'
   82 |             ub = max(ub, x);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
candies.cpp:82:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   82 |             ub = max(ub, x);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
candies.cpp:82:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   82 |             ub = max(ub, x);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
candies.cpp:82:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   82 |             ub = max(ub, x);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
candies.cpp:82:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   82 |             ub = max(ub, x);
      |                           ^
candies.cpp:84:29: error: no matching function for call to 'min(long long int&, int&)'
   84 |             val = min(val, y);
      |                             ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
candies.cpp:84:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   84 |             val = min(val, y);
      |                             ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
candies.cpp:84:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   84 |             val = min(val, y);
      |                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
candies.cpp:84:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   84 |             val = min(val, y);
      |                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
candies.cpp:84:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   84 |             val = min(val, y);
      |                             ^
candies.cpp:85:27: error: no matching function for call to 'min(long long int&, int&)'
   85 |             lb = min(lb, y);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
candies.cpp:85:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   85 |             lb = min(lb, y);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
candies.cpp:85:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   85 |             lb = min(lb, y);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
candies.cpp:85:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   85 |             lb = min(lb, y);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
candies.cpp:85:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   85 |             lb = min(lb, y);
      |                           ^
candies.cpp:86:27: error: no matching function for call to 'min(long long int&, int&)'
   86 |             ub = min(ub, y);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
candies.cpp:86:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   86 |             ub = min(ub, y);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
candies.cpp:86:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   86 |             ub = min(ub, y);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
candies.cpp:86:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   86 |             ub = min(ub, y);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
candies.cpp:86:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   86 |             ub = min(ub, y);
      |                           ^