Submission #896123

#TimeUsernameProblemLanguageResultExecution timeMemory
896123MackerQuality Of Living (IOI10_quality)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "quality.h"
 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define ckmin(a, b) a = min(a, b)

void add(int x, set<int>& low, set<int>& hig){
    int m;
    if(low.size() == 0) m = 0;
    else m = *(--low.end());
    if(x >= m){
        hig.insert(x);
        while(hig.size() >= low.size()){
            low.insert(*hig.begin());
            hig.erase(*hig.begin());
        }
    }
    else {
        low.insert(x);
        while(low.size() > hig.size() + 1) {
            hig.insert(*(--low.end()));
            low.erase(--low.end());
        }
    }
}

void remove(int x, set<int>& low, set<int>& hig){
    if(low.find(x) != low.end()){
        low.erase(low.find(x));
        while(hig.size() >= low.size()){
            low.insert(*hig.begin());
            hig.erase(*hig.begin());
        }
    }
    else {
        hig.erase(hig.find(x));
        while(low.size() > hig.size() + 1) {
            hig.insert(*(--low.end()));
            low.erase(--low.end());
        }
    }
}


void rectangle(int r, int c, int h, int w, vector<vector<int>> v){
    multiset<int> low, hig;
    int mn = INT_MAX;
    for (int i = 0; i < r - h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 0; k < h; k++){
                add(v[i + k][j], low, hig);   
            }
        }
        mn = min(mn, (*--low.end()));
        
        for (int j = w; j < c; j++) {
            for (int k = 0; k < h; k++) {
                remove(v[i + k][j - w], low, hig);
            }
            for (int k = 0; k < h; k++) {
                add(v[i + k][j], low, hig);
            }
                
            mn = min(mn, (*--low.end()));
        }
    }
    
    cout << mn << endl;
}

Compilation message (stderr)

quality.cpp: In function 'void rectangle(int, int, int, int, std::vector<std::vector<int> >)':
quality.cpp:57:34: error: invalid initialization of reference of type 'std::set<int>&' from expression of type 'std::multiset<int>'
   57 |                 add(v[i + k][j], low, hig);
      |                                  ^~~
quality.cpp:13:27: note: in passing argument 2 of 'void add(int, std::set<int>&, std::set<int>&)'
   13 | void add(int x, set<int>& low, set<int>& hig){
      |                 ~~~~~~~~~~^~~
quality.cpp:64:49: error: no matching function for call to 'remove(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, std::multiset<int>&, std::multiset<int>&)'
   64 |                 remove(v[i + k][j - w], low, hig);
      |                                                 ^
In file included from /usr/include/c++/10/cstdio:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:46,
                 from quality.cpp:1:
/usr/include/stdio.h:146:12: note: candidate: 'int remove(const char*)'
  146 | extern int remove (const char *__filename) __THROW;
      |            ^~~~~~
/usr/include/stdio.h:146:12: note:   candidate expects 1 argument, 3 provided
quality.cpp:33:6: note: candidate: 'void remove(int, std::set<int>&, std::set<int>&)'
   33 | void remove(int x, set<int>& low, set<int>& hig){
      |      ^~~~~~
quality.cpp:33:30: note:   no known conversion for argument 2 from 'std::multiset<int>' to 'std::set<int>&'
   33 | void remove(int x, set<int>& low, set<int>& hig){
      |                    ~~~~~~~~~~^~~
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from quality.cpp:1:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:224:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::remove(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  224 | remove(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:224:1: note:   template argument deduction/substitution failed:
quality.cpp:64:49: note:   candidate expects 4 arguments, 3 provided
   64 |                 remove(v[i + k][j - w], low, hig);
      |                                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from quality.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:870:5: note: candidate: 'template<class _FIter, class _Tp> _FIter std::remove(_FIter, _FIter, const _Tp&)'
  870 |     remove(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~
/usr/include/c++/10/bits/stl_algo.h:870:5: note:   template argument deduction/substitution failed:
quality.cpp:64:49: note:   deduced conflicting types for parameter '_FIter' ('int' and 'std::multiset<int>')
   64 |                 remove(v[i + k][j - w], low, hig);
      |                                                 ^
quality.cpp:67:34: error: invalid initialization of reference of type 'std::set<int>&' from expression of type 'std::multiset<int>'
   67 |                 add(v[i + k][j], low, hig);
      |                                  ^~~
quality.cpp:13:27: note: in passing argument 2 of 'void add(int, std::set<int>&, std::set<int>&)'
   13 | void add(int x, set<int>& low, set<int>& hig){
      |                 ~~~~~~~~~~^~~