Submission #281683

#TimeUsernameProblemLanguageResultExecution timeMemory
281683VimmerSky Walking (IOI19_walk)C++14
Compilation error
0 ms0 KiB
#include "walk.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100001

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> ptr;
typedef array <int, 3> a3;

vector <vector <int> > g;

vector <a3> edge;

vector <int> nums[N], who[N], db[N];

vector <ll> dst;

gp_hash_table <int, int> idr[N];

void add(int a, int b, int cost)
{
    g[a].pb(sz(edge));

    g[b].pb(sz(edge));

    edge.pb({a, b, cost});
}

ll min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int to)
{
    int n = sz(x);

    int m = sz(l);

    set <pair <int, int> > st; st.clear();

    for (int j = 0; j < m; j++)
        {db[l[j]].pb(j); del[r[j]].pb(j);}

    for (int i = 0; i < n; i++)
    {
        for (auto j : db[i])
            st.insert({y[j], j});

        auto it = st.upper_bound(ptr(h[i], 1e9));

        if (it != st.begin())
        {
            it--;

            while (1)
            {
                nums[i].pb((*it).S);

                if (it == st.begin()) break;

                it--;
            }
        }
        for (auto j : del[i])
            st.erase({y[j], j});
    }

    int id = 0;

    ll ans = 1e18;

    set <pair <ll, int> > str;

    set <pair <int, int> > se; se.clear();

    for (int i = 0; i < n; i++)
      for (auto j : nums[i])
      {
          if (i == s) se.insert({id, y[j]});

          idr[i][j] = id++;

          g.emplace_back();

          dst.pb(-1);

          for (auto jr : nums[i])
          {
              if (jr == j) break;

              add(id - 1, idr[i][jr], abs(y[jr] - y[j]));
          }

          if (to == i) {dst[id - 1] = 0; str.insert({y[j], id - 1});}
      }

    for (int i = 0; i < n; i++)
        for (auto j : nums[i])
        {
            for (auto I : who[j])
              add(idr[i][j], idr[I][j], abs(x[i] - x[I]));

            who[j].pb(i);
        }

    while (sz(str))
    {
        pair <ll, int> pt = *str.begin(); str.erase(str.begin());

        if (pt.F >= ans) return ans;

        auto it = se.upper_bound(ptr(pt.S, 1e9 + 1e9));

        if (it != se.begin())
        {
            it--;

            if ((*it).F == pt.S) {ans = min(ans, pt.F + (*it).S); se.erase(it); if (sz(se) == 0) return ans;}
        }

        for (auto ip : g[pt.S])
        {
            a3 itr = edge[ip];

            ll s = pt.F + itr[2];

            if (itr[0] == pt.S) swap(itr[0], itr[1]);

            if (dst[itr[0]] != - 1 && dst[itr[0]] <= s) continue;

            if (ans <= s) continue;

            str.erase({dst[itr[0]], itr[0]});

            dst[itr[0]] = s;

            str.insert({s, itr[0]});
        }
    }

    if (ans == 1e18) return -1;

	return ans;
}


Compilation message (stderr)

walk.cpp: In function 'll min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:47:26: error: 'del' was not declared in this scope
   47 |         {db[l[j]].pb(j); del[r[j]].pb(j);}
      |                          ^~~
walk.cpp:69:23: error: 'del' was not declared in this scope
   69 |         for (auto j : del[i])
      |                       ^~~
walk.cpp:70:31: error: no matching function for call to 'std::set<std::pair<int, int> >::erase(<brace-enclosed initializer list>)'
   70 |             st.erase({y[j], j});
      |                               ^
In file included from /usr/include/c++/9/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:87,
                 from walk.cpp:2:
/usr/include/c++/9/bits/stl_set.h:654:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >]'
  654 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/9/bits/stl_set.h:654:28: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::set<std::pair<int, int> >::const_iterator' {aka 'std::_Rb_tree_const_iterator<std::pair<int, int> >'}
  654 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/9/bits/stl_set.h:684:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::size_type = long unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<int, int>]'
  684 |       erase(const key_type& __x)
      |       ^~~~~
/usr/include/c++/9/bits/stl_set.h:684:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<int, int>&'}
  684 |       erase(const key_type& __x)
      |             ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_set.h:706:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::const_iterator) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >]'
  706 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/9/bits/stl_set.h:706:7: note:   candidate expects 2 arguments, 1 provided