Submission #254982

#TimeUsernameProblemLanguageResultExecution timeMemory
254982eohomegrownappsDancing Elephants (IOI11_elephants)C++14
Compilation error
0 ms0 KiB
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
ll n,l;

map<ll,pair<ll,ll>> positions; //{position, {nextpos, bucketstart}}
//num cameras to protrude outside bucket, right coord of bucketwidth
unordered_map<ll,ll> poscnt;
ll ind2coord[100000];
ll bucketx[100000]; //x coords of buckets + INF coord
int bsp=0;
ll INF = 1e9+1;
//denotes end of sequence
ll sizev;
ll qcount = 0;
void updateBucket(int ind){
    //cout<<"updating "<<ind<<" "<<bucketx[ind]<<'\n';
    //generate bucketstart, numcameras, nextpos from positions
    auto it = positions.lower_bound(bucketx[ind+1]);
    if (it==positions.begin()){return;}
    ll ptr = ind;
    do {
        it = prev(it);
        //cout<<it->first<<'\n';
        //process
        if (it->first<bucketx[ptr]){
            return;
        }
        ll rightedge = it->first+l; //upper_bound
        if (rightedge<bucketx[ptr+1]){
            auto ub = positions.upper_bound(rightedge);
            if (ub==positions.end()){
                (it->second).first = 1;
                (it->second).second = INF;
            } else if (ub->first>=bucketx[ptr+1]){
                (it->second).first = 1;
                (it->second).second = rightedge;
            } else {
                (it->second).first = (ub->second).first+1;
                (it->second).second = (ub->second).second;
            }
        } else {
            (it->second).first = 1;
            (it->second).second = rightedge;
        }
    } while (it!=positions.begin());
    //assert(ind==0||0==1);
}

void genBuckets(){
    //cout<<"generating\n";
    //bucketx.clear();
    ll len = 0;
    //bucketx.push_back(-1);
    bsp=0;
    bucketx[bsp]=-1;
    bsp++;
    for (auto p : positions){
        if (len==0){
            bucketx[bsp]=p.first;
            bsp++;
        }
        len++;
        if (len==sizev){
            len=0;
        }
    }
    bucketx[bsp]=INF;
    bsp++;
    
    /*for (ll i : bucketx){
        //cout<<i<<", ";
    }//cout<<"\n";*/

    for (ll i = bsp-2; i>=0; i--){
        updateBucket(i);
    }
}

void init(int N, int L, int X[]) {
    n = N;l=L;
    for (int i = 0; i<n; i++){
        ind2coord[i]=X[i];
    }
    for (ll i = 0; i<n; i++){
        if (poscnt.find(X[i])==poscnt.end()){
            poscnt[X[i]]++;
            positions[X[i]]={INF,INF};
        } else {
            poscnt[X[i]]++;
        }
    }
    sizev = min(max(sqrt(positions.size(),50),sqrt(positions.size())/2);
    genBuckets();
}

int update(int i, int y) {
    //cout<<"update "<<i<<" "<<y<<'\n';
    //remove thing at index i
    ll oldplace = ind2coord[i];
    ind2coord[i]=y;
    ll newplace = y;
    poscnt[oldplace]--;
    if (poscnt[oldplace]==0){
        positions.erase(oldplace);
    }
    if (poscnt[newplace]==0){
        positions[newplace]={INF,INF};
    }
    poscnt[newplace]++;
    qcount++;
    if (qcount%sizev==0){
        qcount=0;
        genBuckets();
    } else {
        //cout<<oldplace<<" "<<newplace<<'\n';
        updateBucket(upper_bound(bucketx,bucketx+bsp,oldplace)-bucketx-1);
        updateBucket(upper_bound(bucketx,bucketx+bsp,newplace)-bucketx-1);
    }
    ll cnt = 0;
    auto ptr = positions.begin();
    while (ptr!=positions.end()){
        cnt+=ptr->second.first;
        ptr = positions.upper_bound(ptr->second.second);
    }
    assert(cnt<INF);
    return cnt;
}

Compilation message (stderr)

elephants.cpp: In function 'void init(int, int, int*)':
elephants.cpp:94:45: error: no matching function for call to 'sqrt(std::map<int, std::pair<int, int> >::size_type, int)'
     sizev = min(max(sqrt(positions.size(),50),sqrt(positions.size())/2);
                                             ^
In file included from /usr/include/features.h:367:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:533,
                 from /usr/include/c++/7/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from elephants.cpp:2:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:156:1: note: candidate: double sqrt(double)
 __MATHCALL (sqrt,, (_Mdouble_ __x));
 ^
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:156:1: note:   candidate expects 1 argument, 2 provided
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41:0,
                 from elephants.cpp:2:
/usr/include/c++/7/cmath:463:3: note: candidate: constexpr float std::sqrt(float)
   sqrt(float __x)
   ^~~~
/usr/include/c++/7/cmath:463:3: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/7/cmath:467:3: note: candidate: constexpr long double std::sqrt(long double)
   sqrt(long double __x)
   ^~~~
/usr/include/c++/7/cmath:467:3: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/7/cmath:475:5: note: candidate: template<class _Tp> constexpr typename __gnu_cxx::__enable_if<std::__is_integer<_Tp>::__value, double>::__type std::sqrt(_Tp)
     sqrt(_Tp __x)
     ^~~~
/usr/include/c++/7/cmath:475:5: note:   template argument deduction/substitution failed:
elephants.cpp:94:45: note:   candidate expects 1 argument, 2 provided
     sizev = min(max(sqrt(positions.size(),50),sqrt(positions.size())/2);
                                             ^
In file included from /usr/include/c++/7/ccomplex:39:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from elephants.cpp:2:
/usr/include/c++/7/complex:899:5: note: candidate: template<class _Tp> std::complex<_Tp> std::sqrt(const std::complex<_Tp>&)
     sqrt(const complex<_Tp>& __z) { return __complex_sqrt(__z.__rep()); }
     ^~~~
/usr/include/c++/7/complex:899:5: note:   template argument deduction/substitution failed:
elephants.cpp:94:45: note:   mismatched types 'const std::complex<_Tp>' and 'std::map<int, std::pair<int, int> >::size_type {aka long unsigned int}'
     sizev = min(max(sqrt(positions.size(),50),sqrt(positions.size())/2);
                                             ^
In file included from /usr/include/c++/7/valarray:592:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95,
                 from elephants.cpp:2:
/usr/include/c++/7/bits/valarray_after.h:455:5: note: candidate: template<class _Dom> std::_Expr<std::_UnClos<std::_Sqrt, std::_Expr, _Dom>, typename _Dom::value_type> std::sqrt(const std::_Expr<_Dom1, typename _Dom1::value_type>&)
     _DEFINE_EXPR_UNARY_FUNCTION(sqrt, _Sqrt)
     ^
/usr/include/c++/7/bits/valarray_after.h:455:5: note:   template argument deduction/substitution failed:
elephants.cpp:94:45: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'std::map<int, std::pair<int, int> >::size_type {aka long unsigned int}'
     sizev = min(max(sqrt(positions.size(),50),sqrt(positions.size())/2);
                                             ^
In file included from /usr/include/c++/7/valarray:592:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95,
                 from elephants.cpp:2:
/usr/include/c++/7/bits/valarray_after.h:455:5: note: candidate: template<class _Tp> std::_Expr<std::_UnClos<std::_Sqrt, std::_ValArray, _Tp>, _Tp> std::sqrt(const std::valarray<_Tp>&)
     _DEFINE_EXPR_UNARY_FUNCTION(sqrt, _Sqrt)
     ^
/usr/include/c++/7/bits/valarray_after.h:455:5: note:   template argument deduction/substitution failed:
elephants.cpp:94:45: note:   mismatched types 'const std::valarray<_Tp>' and 'std::map<int, std::pair<int, int> >::size_type {aka long unsigned int}'
     sizev = min(max(sqrt(positions.size(),50),sqrt(positions.size())/2);
                                             ^