Submission #331415

# Submission time Handle Problem Language Result Execution time Memory
331415 2020-11-28T12:04:41 Z Sho10 Restore Array (RMI19_restore) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,a[5005],check=0;
bool cmp(kth x,kth y){
return x.r<y.r;
}
map<ll,ll>viz;
struct kth{
int l,r,value,k;
};
kth b[100005];
void solve(ll pos,ll val){
    if(check==1){
        return;
    }
    a[pos]=val;
if(pos==n){
    for(ll i=1;i<=m;i++)
    {
        ll cnt=0;
        for(ll j=b[i].l;j<=b[i].r;j++)
        {
            if(a[j]==0){
                cnt++;
            }
        }
        if(b[i].value==0){
            if(cnt<b[i].k){
                a[pos]=-1;
                return;
            }
        }
        if(b[i].value==1){
            if(cnt>=b[i].k){
                a[pos]=-1;
                return;
            }
        }
    }
    check=1;
    for(ll i=1;i<=n;i++)
    {
        cout<<a[i]<<' ';
    }
    a[pos]=-1;
    return;
}
solve(pos+1,0);
solve(pos+1,1);
a[pos]=-1;
return;
}
int32_t main(){
CODE_START;
cin>>n>>m;
if(n<=18&&m<=200){
for(ll i=1;i<=m;i++)
{
    cin>>b[i].l>>b[i].r>>b[i].k>>b[i].value;
    b[i].l++;
    b[i].r++;
}
solve(1,0);
solve(1,1);
if(check==1){
   return 0;
}
rc("-1");
}else {
for(ll i=1;i<=n;i++)
{
    a[i]=-1;
}
for(ll i=1;i<=m;i++)
{
    cin>>b[i].l>>b[i].r>>b[i].k>>b[i].value;
    b[i].l++;
    b[i].r++;
    if(b[i].value==1&&b[i].k==1){
    for(ll j=b[i].l;j<=b[i].r;j++)
    {
        if(a[j]==0){
            rc("-1");
        }
        a[j]=1;
    }
}else if(b[i].value==0&&b[i].k==b[i].r-b[i].l+1){
for(ll j=b[i].l;j<=b[i].r;j++)
{
if(a[j]==1){
    rc("-1");
}
a[j]=0;
}
}
}
sort(b+1,b+m+1,cmp);
for(ll i=1;i<=n;i++)
{
    if(a[i]==-1){
        a[i]=0;
        viz[i]=1;
    }
}
for(ll i=1;i<=m;i++){
    if(b[i].value==0&&b[i].k==b[i].r-b[i].l+1){
        continue;
    }
    if(b[i].value==1&&b[i].k==1){
        continue;
    }
    if(b[i].value==0&&b[i].k==1){
            ll s1=0;
    for(ll j=b[i].l;j<=b[i].r;j++)
    {
        if(a[j]==0){
            s1=1;
        }
    }
    if(s1==0){
            rc("-1");
    }
        continue;
    }
    ll cnt=0;
    for(ll j=b[i].l;j<=b[i].r;j++)
    {
        if(a[j]==1){
            cnt++;
        }
    }
    if(cnt!=0){
        continue;
    }
    ll check=0;
    for(ll j=b[i].l;j<=b[i].r;j++)
    {
if(viz[j]==1&&a[j]==0){
    a[j]=1;
    viz[j]=0;
    check=1;
    break;
}
    }
    if(check==0){
        rc("-1");
    }

}
for(ll i=1;i<=n;i++)
{
    cout<<a[i]<<' ';
}
}
}
/*
Subtask 1:
4 5
0 1 2 1
0 2 2 0
2 2 1 0
0 1 1 0
1 2 1 0
*/

Compilation message

restore.cpp:22:10: error: 'kth' was not declared in this scope
   22 | bool cmp(kth x,kth y){
      |          ^~~
restore.cpp:22:16: error: 'kth' was not declared in this scope
   22 | bool cmp(kth x,kth y){
      |                ^~~
restore.cpp:22:21: error: expression list treated as compound expression in initializer [-fpermissive]
   22 | bool cmp(kth x,kth y){
      |                     ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from restore.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = kth*; _Iterator2 = kth*; _Compare = bool]':
/usr/include/c++/9/bits/stl_algo.h:81:17:   required from 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = kth*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:1920:34:   required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = kth*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:1952:38:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = kth*; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:1967:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = kth*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:4899:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = kth*; _Compare = bool]'
restore.cpp:115:19:   required from here
/usr/include/c++/9/bits/predefined_ops.h:143:18: error: expression cannot be used as a function
  143 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = kth; _Iterator = kth*; _Compare = bool]':
/usr/include/c++/9/bits/stl_algo.h:1827:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = kth*; _Compare = __gnu_cxx::__ops::_Val_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:1854:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = kth*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:1884:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = kth*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:1970:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = kth*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:4899:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = kth*; _Compare = bool]'
restore.cpp:115:19:   required from here
/usr/include/c++/9/bits/predefined_ops.h:215:11: error: expression cannot be used as a function
  215 |  { return bool(_M_comp(__val, *__it)); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = kth*; _Value = kth; _Compare = bool]':
/usr/include/c++/9/bits/stl_heap.h:133:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = kth*; _Distance = long int; _Tp = kth; _Compare = __gnu_cxx::__ops::_Iter_comp_val<bool>]'
/usr/include/c++/9/bits/stl_heap.h:237:23:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = kth*; _Distance = long int; _Tp = kth; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_heap.h:342:22:   required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = kth*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:1671:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = kth*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:1932:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = kth*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:1947:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = kth*; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:1967:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = kth*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool>]'
/usr/include/c++/9/bits/stl_algo.h:4899:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = kth*; _Compare = bool]'
restore.cpp:115:19:   required from here
/usr/include/c++/9/bits/predefined_ops.h:177:11: error: expression cannot be used as a function
  177 |  { return bool(_M_comp(*__it, __val)); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~