Submission #1053218

# Submission time Handle Problem Language Result Execution time Memory
1053218 2024-08-11T09:50:33 Z dozer Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define pb push_back
#define pii pair<int, int>
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define st first
#define nd second
#define ll long long
#define LL node * 2
#define RR node * 2 + 1
#define N 300005
#define LOGN 20

const int modulo = 1e9 + 7;
const ll INF = 2e18 + 7;


ll tree[4 * N], lazy[4 * N], lazy_set[4 * N];
int arr[N];


void push(int node, int l, int r){
    tree[node] += lazy[node];
    if (lazy_set[node] != -1){
        if (l == r){
            if (lazy_set[node] == 1) tree[node] = arr[l];
            else if (lazy_set[node] == 0) tree[node] = 0;
        }
        else{
            lazy_set[LL] = lazy_set[node];
            lazy_set[RR] = lazy_set[node];
        }
    }

    if (l != r){
        lazy[LL] += lazy[node];
        lazy[RR] += lazy[node];
    }
    lazy[node] = 0;
    lazy_set[node] = -1;
}

void build(int node, int l, int r){
    tree[node] = 0;
    lazy[node] = 0;
    lazy_set[node] = -1;
    if (l == r) return;
    int mid = (l + r) / 2;
    build(LL,l, mid);
    build(RR, mid + 1, r);
}

void update1(int node, int l, int r, int sl, int sr, int val){
    push(node, l, r);
    if (l > sr || r < sl) return;
    if (l >= sl && r <= sr){
        lazy[node] += val;
        push(node, l , r);
        return;
    }

    int mid = (l + r) / 2;
    update1(LL, l, mid, sl, sr, val);
    update1(RR, mid + 1, r, sl, sr, val);
}

void update2(int node, int l, int r, int sl, int sr, int val){
    push(node, l, r);
    if (l > sr || r < sl) return;
    if (l >= sl && r <= sr){
        lazy_set[node] = val;
        push(node, l, r);
        return;
    }
    int mid = (l + r) / 2;
    update2(LL, l, mid, sl, sr, val);
    update2(RR, mid + 1, r, sl, sr, val);   
}



ll query(int node, int l, int r, int sl){
    push(node, l, r);
    if (l > r || l > sl || r < sl) return 0;
    if (l == r) {
        return tree[node];
    }
    int mid = (l + r) / 2;
    if (sl <= mid) return query(LL, l, mid, sl);
    return query(RR, mid + 1, r, sl);
}


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

    for (int i = 0; i < n; i++){
        s[i] = min(c[i], query(1, 0, n - 1, i));
    }
    return s;
}

/*
int main() {
    fileio();
    int n;
    assert(1 == scanf("%d", &n));
    std::vector<int> c(n);
    for(int i = 0; i < n; ++i) {
        assert(scanf("%d", &c[i]) == 1);
    }

    int q;
    assert(1 == scanf("%d", &q));
    std::vector<int> l(q), r(q), v(q);
    for(int i = 0; i < q; ++i) {
        assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
    }

    std::vector<int> ans = distribute_candies(c, l, r, v);

    for(int i = 0; i < n; ++i) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", ans[i]);
    }
    printf("\n");
    fclose(stdout);
    return 0;
}
*/

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:108:47: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, long long int)'
  108 |         s[i] = min(c[i], query(1, 0, n - 1, i));
      |                                               ^
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:108:47: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  108 |         s[i] = min(c[i], query(1, 0, n - 1, i));
      |                                               ^
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:108:47: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  108 |         s[i] = min(c[i], query(1, 0, n - 1, i));
      |                                               ^
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:108:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  108 |         s[i] = min(c[i], query(1, 0, n - 1, i));
      |                                               ^
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:108:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  108 |         s[i] = min(c[i], query(1, 0, n - 1, i));
      |                                               ^
candies.cpp:101:9: warning: unused variable 'm' [-Wunused-variable]
  101 |     int m = l.size();
      |         ^