Submission #1309916

#TimeUsernameProblemLanguageResultExecution timeMemory
1309916michael12사탕 분배 (IOI21_candies)C++20
Compilation error
0 ms0 KiB
#include "candies.h"
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
const int maxn = 200005;
struct segtree {
    vector<int> tree, lazy;
    int     n;
    segtree(int n) : n(n) {
        tree.assign(4 * n, 0);
        lazy.assign(4 * n, 0);
    }
    // void build(int node, int start, int end, const vector<int> &a) {
    //     if (start == end) {
    //         tree[node] = a[start];
    //         return;
    //     }
    //     int mid = (start + end) / 2;
    //     build(2 * node, start, mid, a);
    //     build(2 * node + 1, mid + 1, end, a);
    //     tree[node] = min(tree[2 * node], tree[2 * node + 1]);
    // }
    void push(int node, int start, int end, vector<int>& c) {
    if(lazy[node] != 0){
        if(start == end){
            if(lazy[node] > 0){
                tree[node] = min(c[start], tree[node] + lazy[node]);
            } 
            else{
                tree[node] = max(0, tree[node] + lazy[node]);

            }
        } else {
            lazy[2 * node] += lazy[node];              
            lazy[2 *node + 1] += lazy[node];
        }
        lazy[node] = 0;
    }
    }

    void update(int node, int start, int end, int l, int r, int val, vector<int>& c) {
        push(node, start, end, c);
        if (start > r || end < l) return;
        if (l <= start && end <= r) {
            lazy[node] += val;
            push(node, start, end, c);
            return;
        }
        int mid = (start + end) / 2;
        update(2 * node, start, mid, l, r, val, c);
        update(2 * node + 1, mid + 1, end, l, r, val, c);
    }
    int get(int node, int start, int end, int id, vector<int>& c){
        push(node, start, end, c);
        if(start == end){
           return tree[node];
        }
        else{
            int mid = (start + end) / 2;
            if(mid >= id){
                return get(2 * node, start, mid, id, c);
            }
            else{
                return get(2 * node + 1, mid + 1, end, id, c);
            }
        }
    }
};

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v){
     int sz = c.size();
     segtree ST(sz);
     for(int dy = 0; dy < v.size(); dy++){
          ST.update(1, 0, sz - 1, l[dy], r[dy], v[dy], c);
     }
     vector<int> ans(sz);
     for(int i = 0; i < sz; i++){
         ans[i] = ST.get(1, 0, sz - 1, i, c);
     }
     return ans;
}

Compilation message (stderr)

candies.cpp: In member function 'void segtree::push(long long int, long long int, long long int, std::vector<long long int>&)':
candies.cpp:34:33: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   34 |                 tree[node] = max(0, tree[node] + lazy[node]);
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:62,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
candies.cpp:34:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   34 |                 tree[node] = max(0, tree[node] + lazy[node]);
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
candies.cpp:34:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   34 |                 tree[node] = max(0, tree[node] + lazy[node]);
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from candies.cpp:2:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
candies.cpp:34:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   34 |                 tree[node] = max(0, tree[node] + lazy[node]);
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
candies.cpp:34:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   34 |                 tree[node] = max(0, tree[node] + lazy[node]);
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~