Submission #612199

# Submission time Handle Problem Language Result Execution time Memory
612199 2022-07-29T11:30:39 Z 1bin The Potion of Great Power (CEOI20_potion) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(), v.end()
const int NMAX = 1e5 + 5;
const int sqt = 40;
int n, d, u, q, h[NMAX], a, b, A[2 * NMAX], B[2 * NMAX];
vector<int> ix[NMAX];
auto cmp = [](int a, int b){return h[a] < h[b];};
vector<set<int, decltype(cmp)>> v[NMAX];
set<int, decltype(cmp)> l, r;

void init(int N, int D, int H[]){
    n = N; d = D;
    for(int i = 0; i < n; i++) h[i] = H[i];
    return;
}

void curseChanges(int U, int A_[], int B_[]){
    u = U;
    for(int i = 0; i < u; i++) A[i] = A_[i], B[i] = B_[i];
    for(int i = 0; i < u; i++){
        a = A[i]; b = B[i];
        ix[a].emplace_back(i);
        ix[b].emplace_back(i);
    }
    for(int i = 0; i < n; i++){
        set<int, decltype(cmp)> s;
        for(int j = 0; j < ix[i].size(); j++){
            int t = A[ix[i][j]] == i ? B[ix[i][j]] : A[ix[i][j]];
            if(s.find(t) == s.end()) s.emplace(t);
            else s.erase(t);
            
            if(j % sqt == sqt - 1) v[i].emplace_back(s);
        }
    }
    return;
}

int question(int x, int y, int V){
    int ans = 1e9, xb, yb, lsz, rsz;
    int xsz = lower_bound(all(ix[x]), V) - ix[x].begin();
    int ysz = lower_bound(all(ix[y]), V) - ix[y].begin();
    xb = (xsz - 1) / sqt; yb = (ysz - 1) / sqt;
    if(xb >= 1) for(auto& t : v[x][xb - 1]) l.emplace(t);
    if(yb >= 1) for(auto& t : v[y][yb - 1]) r.emplace(t);
    for(int i = xb * sqt; i < xsz; i++) {
        int t = (A[ix[x][i]] == x) ? B[ix[x][i]] : A[ix[x][i]];
        if(l.find(t) == l.end()) l.emplace(t);
        else l.erase(t);
    }
    for(int i = yb * sqt; i < ysz; i++) {
        int t = (A[ix[y][i]] == y) ? B[ix[y][i]] : A[ix[y][i]];
        if(r.find(t) == r.end()) r.emplace(t);
        else r.erase(t);
    }
    auto xi = l.begin();
    auto yi = r.begin();
    lsz = l.size(); rsz = r.size();
    while(xi != l.end() && yi != r.end()){
        ans = min(ans, abs(h[*xi] - h[*yi]));
        h[*xi] < h[*yi] ? xi++ : yi++;
    }
   l.clear(); r.clear();
    return ans;
}

Compilation message

potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:30:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(int j = 0; j < ix[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:42:28: warning: variable 'lsz' set but not used [-Wunused-but-set-variable]
   42 |     int ans = 1e9, xb, yb, lsz, rsz;
      |                            ^~~
potion.cpp:42:33: warning: variable 'rsz' set but not used [-Wunused-but-set-variable]
   42 |     int ans = 1e9, xb, yb, lsz, rsz;
      |                                 ^~~
In file included from /usr/include/c++/10/map:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from potion.cpp:1:
/usr/include/c++/10/bits/stl_tree.h: In instantiation of 'std::_Rb_tree_key_compare<_Key_compare>::_Rb_tree_key_compare() [with _Key_compare = <lambda(int, int)>]':
/usr/include/c++/10/bits/stl_tree.h:688:22:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Rb_tree_impl<_Key_compare, <anonymous> >::_Rb_tree_impl() [with _Key_compare = <lambda(int, int)>; bool <anonymous> = false; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = <lambda(int, int)>; _Alloc = std::allocator<int>]'
/usr/include/c++/10/bits/stl_tree.h:935:7:   required from here
/usr/include/c++/10/bits/stl_tree.h:149:24: error: use of deleted function '<lambda(int, int)>::<lambda>()'
  149 |       : _M_key_compare()
      |                        ^
potion.cpp:10:13: note: a lambda closure type has a deleted default constructor
   10 | auto cmp = [](int a, int b){return h[a] < h[b];};
      |             ^