Submission #810572

# Submission time Handle Problem Language Result Execution time Memory
810572 2023-08-06T11:25:26 Z Khizri Dancing Elephants (IOI11_elephants) C++17
Compilation error
0 ms 0 KB
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=2e5+5,MAX=1e9+5;
int n,k,arr[mxn],sz,block,loc[mxn],pos[mxn],clck;
bool cmp(int i,int j){
    return arr[i]<arr[j];
}
struct st{
    vector<vector<int>>vt,last,dis;
    void build(){
        vt.clear(),last.clear(),dis.clear();
        vector<int>p(n);
        iota(all(p),1);
        sort(all(p),cmp);
        int sz=sqrt(n);
        int idx=0,say=0;
        while(idx<n){
            say++;
            if(say==1){
                vt.pb({});
                vt.back().pb(p[idx]);
            }
            else{
                vt.back().pb(p[idx]);
            }
            idx++;
            if(say>=sz) say=0;
        }
        for(int id=0;id<vt.size();id++){
            vector<int>vx(sz*2+5);
            last.pb(vx);
            dis.pb(vx);
            int idx=vt[id].size()-1;
            for(int i=vt[id].size()-1;i>=0;i--){
                while(idx-1>=0&&arr[vt[id][i]]+k<arr[vt[id][idx-1]]){
                    idx--;
                }
                if(arr[vt[id][i]]+k>=arr[vt[id][idx]]){
                    last[id][i]=arr[vt[id][i]]+k+1;
                    dis[id][i]=1;
                }
                else{
                    last[id][i]=last[id][idx];
                    dis[id][i]=dis[id][idx]+1;
                }
            }
        }
    }
    int query(){
        int left=-5;
        int ans=0;
        for(int id=0;id<vt.size();id++){
            int l=0,r=vt[id].size()-1;
            int res=-1;
            while(l<=r){
                int m=(l+r)/2;
                if(arr[vt[id][m]]>left){
                    r=m-1;
                    res=m;
                }
                else{
                    l=m+1;
                }
            }
            if(res==-1) continue;
            left=last[id][res];
            ans+=dis[id][res];
        }
        return ans;
    }
};
st data;
void init(int N, int L, int X[])
{
    n=N,k=L;
    for(int i=1;i<=n;i++){
        arr[i]=X[i-1];
    }
    
}
int update(int i, int val)
{
    arr[i+1]=val;
    data.build();
    return data.query();
}
/*
g++ elephants.cpp grader.cpp ; .\a.exe
10 10 0
1 3 7 15 27 37 46 90 98 100
4 10 5 
10 15 17 20
2 16 1
1 25 2
3 25 2
0 38 2
2 0 3
*/

Compilation message

elephants.cpp: In member function 'void st::build()':
elephants.cpp:41:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for(int id=0;id<vt.size();id++){
      |                      ~~^~~~~~~~~~
elephants.cpp: In member function 'int st::query()':
elephants.cpp:64:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for(int id=0;id<vt.size();id++){
      |                      ~~^~~~~~~~~~
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:96:5: error: reference to 'data' is ambiguous
   96 |     data.build();
      |     ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from elephants.cpp:2:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
elephants.cpp:84:4: note:                 'st data'
   84 | st data;
      |    ^~~~
elephants.cpp:97:12: error: reference to 'data' is ambiguous
   97 |     return data.query();
      |            ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from elephants.cpp:2:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
elephants.cpp:84:4: note:                 'st data'
   84 | st data;
      |    ^~~~