Submission #1227599

#TimeUsernameProblemLanguageResultExecution timeMemory
1227599minhpkFurniture (JOI20_furniture)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a,b;
int r[1001][1001];
struct cmp{
      bool operator()(const pair<int,int> &a,const pair<int,int> &b){
           return a.first<b.first;
      }
};

set<pair<int,int>,cmp> s[2001];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b;
    for (int i=1;i<=a;i++){
         for (int j=1;j<=b;j++){
              int x;
              cin >> x;
              if (x==1){
                  r[i][j]=1;
              }
         }
    }
    for (int i=1;i<=b;i++){
         r[a+1][i]=1;
    }

    for (int i=1;i<=a;i++){
         for (int j=1;j<=b;j++){
              if (r[i-1][j] && r[i][j-1]){
                  r[i][j]=1;
              }
         }
    }
    for (int i=a;i>=1;i--){
         for (int j=b;j>=1;j--){

              if (r[i][j+1]&& r[i+1][j]){
                  r[i][j]=1;
              }
         }
    }

//    for (int i=1;i<=a;i++){
//         for (int j=1;j<=b;j++){
//             cout << r[i][j] << " ";
//         }
//         cout << "\n";
//    }
    for (int i=1;i<=a;i++){
         for (int j=1;j<=b;j++){
              if (r[i][j]==0){
                  s[i+j].insert({i,j});
              }
         }
    }
    int q;
    cin >> q;
    while (q--){
         int x,y;
         cin >> x >> y;
         if (r[x][y]){
             cout << 1 << "\n";
         }else{
             if (s[x+y].size()>1){
                 cout << 1 << "\n";
                 auto it=s[x+y].find({x,y});
                 s[x+y].erase(it);
                 r[x][y]=1;

                 if (r[x+1][y-1] && !r[x+1][y]){
                     auto it1=s[x+y+1].find({x+1,y});
                     s[x+y+1].erase(it1);
                     r[x+1][y]=1;
                 }
                 if (r[x-1][y+1] && !r[x][y+1]){
                     auto it1=s[x+y+1].find({x,y+1});
                     s[x+y+1].erase(it1);
                     r[x][y+1]=1;
                 }
                 if (r[x+1][y-1] && !r[x][y-1]){
                     auto it1=s[x+y-1].find({x,y-1});
                     s[x+y-1].erase(it1);
                     r[x][y-1]=1;
                 }
                 if (r[x-1][y+1] && !r[x-1][y]){
                     auto it1=s[x+y-1].find({x-1,y});
                     s[x+y-1].erase(it1);
                     r[x-1][y]=1;
                 }
             }else{
                 cout << 0 << "\n";
             }
         }
    }
    return 0;
}

Compilation message (stderr)

In file included from /usr/include/c++/11/map:60,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:81,
                 from furniture.cpp:1:
/usr/include/c++/11/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type) [with _Key = std::pair<long long int, long long int>; _Val = std::pair<long long int, long long int>; _KeyOfValue = std::_Identity<std::pair<long long int, long long int> >; _Compare = cmp; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type = const std::_Rb_tree_node<std::pair<long long int, long long int> >*]':
/usr/include/c++/11/bits/stl_tree.h:2071:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = std::pair<long long int, long long int>; _Val = std::pair<long long int, long long int>; _KeyOfValue = std::_Identity<std::pair<long long int, long long int> >; _Compare = cmp; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = std::pair<long long int, long long int>]'
/usr/include/c++/11/bits/stl_tree.h:2124:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = std::pair<long long int, long long int>; _Key = std::pair<long long int, long long int>; _Val = std::pair<long long int, long long int>; _KeyOfValue = std::_Identity<std::pair<long long int, long long int> >; _Compare = cmp; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
/usr/include/c++/11/bits/stl_set.h:521:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<long long int, long long int>; _Compare = cmp; _Alloc = std::allocator<std::pair<long long int, long long int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, cmp, std::allocator<std::pair<long long int, long long int> > >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<std::pair<long long int, long long int> >; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::rebind<std::pair<long long int, long long int> >; typename _Alloc::value_type = std::pair<long long int, long long int>; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<long long int, long long int>]'
furniture.cpp:57:32:   required from here
/usr/include/c++/11/bits/stl_tree.h:770:15: error: static assertion failed: comparison object must be invocable as const
  770 |               is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/stl_tree.h:770:15: note: 'std::is_invocable_v<const cmp&, const std::pair<long long int, long long int>&, const std::pair<long long int, long long int>&>' evaluates to false