Submission #828456

# Submission time Handle Problem Language Result Execution time Memory
828456 2023-08-17T09:49:51 Z minhcool Comparing Plants (IOI20_plants) C++17
Compilation error
0 ms 0 KB
//#define local
#ifndef local
#include "plants.h"
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const int oo = 1e9 + 7, mod = 1e9 + 7;

mt19937 rng(1);

int rnd(int l, int r){
	int temp = rng() % (r - l + 1);
	return abs(temp) + l;
}

int a[N];

int mini[N << 2], laz[N << 2];

void build(int id, int l, int r){
    if(l == r){
        mini[id] = a[id];
        return;
    }
    int mid = (l + r) >> 1;
    build(id << 1, l, mid);
    build(id << 1 | 1, mid + 1, r);
    mini[id] = min(mini[id << 1], mini[id << 1 | 1]);
}

void lazy(int id){
    int t = laz[id];
    if(!t) return;
    mini[id << 1] += t;
    mini[id << 1 | 1] += t;
    laz[id << 1] += t;
    laz[id << 1 | 1] += t;
    laz[id] = 0;
}

void upd(int id, int l, int r, int L, int R, int val){
    if(l > R || r < L) return;
    if(l >= L && r <= R){
        mini[id] += val;
        laz[id] += val;
        return;
    }
    lazy(id);
    int mid = (l + r) >> 1;
    upd(id << 1, l, mid, L, R, val);
    upd(id << 1 | 1, mid + 1, r, L, R, val);
    mini[id] = min(mini[id], mini[id << 1]);
}

void er(int id, int l, int r, int pos){
    if(l == r){
        mini[id] = oo;
        return;
    }
    lazy(id);
    int mid = (l + r) >> 1;
    if(pos <= mid) er(id << 1, l, mid, pos);
    else er(id << 1 | 1, mid + 1, r, pos);
}

int get(int id, int l, int r){
    if(mini[id] > 0) return oo;
    if(l == r) return l;
    lazy(id);
    int mid = (l + r) >> 1;
    if(mini[id << 1] == 0) return get(id << 1, l, mid);
    else return get(id << 1 | 1, mid + 1, r);
}

int b[N];

void init(int k, vector<int> r){
    k--;
    int n = r.size();
    for(int i = 0; i < n; i++) a[i] = r[i];
    build(1, 0, n - 1);
    for(int i = 0; i < n; i++){
        int temp = get(1, 0, n - 1);
        if(temp == oo) return;
        b[temp] = i;
        er(1, 0, n - 1, temp);
        upd(1, 0, n - 1, max(0LL, i - k), i - 1, -1);
        if(i < k) upd(1, 0, n - 1, n + i - k, n - 1, -1);
    }
}

int compare_plants(int x, int y){
    if(a[x] < a[y]) return -1;
    if(a[x] > a[y]) return 1;
    return 0;
}


#ifdef local
void process(){

}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	process();
}
#endif

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:102:40: error: no matching function for call to 'max(long long int, int)'
  102 |         upd(1, 0, n - 1, max(0LL, i - k), i - 1, -1);
      |                                        ^
In file included from /usr/include/c++/10/vector:60,
                 from plants.h:1,
                 from plants.cpp:3:
/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:
plants.cpp:102:40: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  102 |         upd(1, 0, n - 1, max(0LL, i - k), i - 1, -1);
      |                                        ^
In file included from /usr/include/c++/10/vector:60,
                 from plants.h:1,
                 from plants.cpp:3:
/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:
plants.cpp:102:40: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  102 |         upd(1, 0, n - 1, max(0LL, i - k), i - 1, -1);
      |                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from plants.cpp:5:
/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:
plants.cpp:102:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  102 |         upd(1, 0, n - 1, max(0LL, i - k), i - 1, -1);
      |                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from plants.cpp:5:
/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:
plants.cpp:102:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  102 |         upd(1, 0, n - 1, max(0LL, i - k), i - 1, -1);
      |                                        ^