Submission #1039844

# Submission time Handle Problem Language Result Execution time Memory
1039844 2024-07-31T10:27:42 Z Thunnus Wall (IOI14_wall) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "wall.h"
using namespace std;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()

struct SegTree{
    struct node{
        int min = 0, max = LLONG_MAX;
    };
    vector<node> st;
    SegTree(int n) : st(4 * n) {}

    inline combine(const node &a, const node &b){
        node c;
        c.min = max(a.min, b.min);
        c.max = min(a.max, b.max);
        return c;
    }

    inline void apply(int p, int v){
        st[v].min = max(st[p].min, st[v].min);
        st[v].min = min(st[p].max, st[v].min);
        st[v].max = min(st[p].max, st[v].max);
        st[v].max = max(st[p].min, st[v].max);
    }

    inline void propagate(int v){
        apply(v, 2 * v);
        apply(v, 2 * v + 1);
    }

    void update(int l, int r, int val, int type, int v, int tl, int tr){
        if(l > tr || r < tl) return;
        if(tl >= l && tr <= r){
            if(type == 1)
                st[v].min = max(st[v].min, val);
            else
                st[v].max = min(st[v].max, val);
            return;
        }
        int mid = (tl + tr) / 2;
        propagate(v);
        update(l, r, val, type, 2 * v, tl, mid);
        update(l, r, val, type, 2 * v + 1, mid + 1, tr);
        st[v] = combine(st[2 * v], st[2 * v + 1]);
    }

    void query(int a[], int v, int tl, int tr){
        if(tl == tr){
            a[tl - 1] = st[v].min;
            return;
        }
        int mid = (tl + tr) / 2;
        propagate(v);
        query(a, 2 * v, tl, mid);
        query(a, 2 * v + 1, mid + 1, tr);
    }
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    SegTree st(n);
    for(int i = 0; i < k; i++){
        st.update(left[i], right[i], height[i], op[i], 1, 1, n);
    }
    st.query(finalHeight, 1, 1, n);
    return finalHeight;
}

Compilation message

wall.cpp:21:12: error: ISO C++ forbids declaration of 'combine' with no type [-fpermissive]
   21 |     inline combine(const node &a, const node &b){
      |            ^~~~~~~
wall.cpp: In member function 'int SegTree::combine(const SegTree::node&, const SegTree::node&)':
wall.cpp:25:16: error: cannot convert 'SegTree::node' to 'int' in return
   25 |         return c;
      |                ^
wall.cpp: In member function 'void SegTree::update(i64, i64, i64, i64, i64, i64, i64)':
wall.cpp:53:49: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<SegTree::node>, SegTree::node>::value_type' {aka 'SegTree::node'} and 'int')
   53 |         st[v] = combine(st[2 * v], st[2 * v + 1]);
      |                                                 ^
wall.cpp:15:12: note: candidate: 'constexpr SegTree::node& SegTree::node::operator=(const SegTree::node&)'
   15 |     struct node{
      |            ^~~~
wall.cpp:15:12: note:   no known conversion for argument 1 from 'int' to 'const SegTree::node&'
wall.cpp:15:12: note: candidate: 'constexpr SegTree::node& SegTree::node::operator=(SegTree::node&&)'
wall.cpp:15:12: note:   no known conversion for argument 1 from 'int' to 'SegTree::node&&'
wall.cpp: In function 'void buildWall(i64, i64, i64*, i64*, i64*, i64*, i64*)':
wall.cpp:74:12: error: return-statement with a value, in function returning 'void' [-fpermissive]
   74 |     return finalHeight;
      |            ^~~~~~~~~~~