Submission #893337

# Submission time Handle Problem Language Result Execution time Memory
893337 2023-12-27T02:24:08 Z ReLice Railway Trip (JOI17_railway_trip) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class _T>
bool chmin(_T &x, const _T &y){
    bool flag=false;
    if(x>=y){
        x=y;flag|=true;
    }
    return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag=false;
    if (x<=y){
        x=y;flag|=true;
    }
    return flag;
}
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e9+7;
const ll mod=1e9+7;
const ll N=3e3+5;
const ld eps=1e-9;
ll up[N][20][2];
ll p[N][20][2];
ll t[N*4];
ll a[N];
void build(ll v,ll tl,ll tr){
    if(tl==tr){
        t[v]=a[tl];
        return;
    }
    ll tm=(tl+tr)/2;
    build(v*2,tl,tm);
    build(v*2+1,tm+1,tr);
    t[v]=max(t[v*2],t[v*2+1]);
}
ll get(ll v,ll tl,ll tr,ll l,ll r){
    if(tl>r || tr<l) return 0;
    if(l<=tl && tr<=r)return t[v];
    ll tm=(tl+tr)/2;
    return max(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r));
}
void solve(){
	ll i,j;
	ll n,k,q;
	cin>>n>>k>>q;
	vector<vll> v(k+5);
	for(i=1;i<=n;i++){
        cin>>a[i];
        v[a[i]].pb(i);
	}
	build(1,1,n);
	for(i=0;i<20;i++) up[0][i][0]=up[0][i][1]=inf;
	for(i=1;i<=n;i++){
        if(a[i]==k) {
            for(j=19;j>=0;j--){
                up[i][j][0]=up[i][j][1]=inf;
            }
            continue;
        }
        ll low=lb(all(v[a[i]+1]),i)-v[a].begin()-1;
        if(low>=0 && low<v[a[i]+1].sz)[
            p[i][0][0]=v[a[i]+1][low];
            ll low2=lb(all(v[a[i]]))
            up[i][0][0]=abs(i-v[a[i]+1][low]);
        }
        low++;
        if(low>=0 && low<v[a[i]+1].sz)[
            p[i][0][1]=v[a[i]+1][low];
            up[i][0][1]=i-v[a[i]+1][low];
        }
	}
    for(ll i1=k-1;i1>0;i1--){
        for(i=0;i<v[i1].sz;i++){
            for(j=1;j<20;j++){
                ll a=v[i1][i];
                p[a][j][0]=p[p[a][j-1][0]][j-1][0];
                p[a][j][1]=p[p[a][j-1][1]][j-1][1];
                up[a][j][0]=min(up[a][j-1][0]+up[p[a][j-1][0]][j-1][0],up[a][j-1][1]+up[p[a][j-1][1]][j-1][0]+1);
                up[a][j][1]=min(up[a][j-1][0]+up[p[a][j-1][0]][j-1][1],up[a][j-1][1]+up[p[a][j-1][1]][j-1][1]+1);
            }
        }
	}
	ll x,y;
	a[0]=inf;
	for(i=0;i<q;i++){
        cin>>x>>y;
        ll ans=inf,H=get(1,1,n,x,y);
        ll l=x,r=x,suml=0,sumr=0;
        for(j=20;j>=0;j--){
            if(abs(H+1-a[l])>=(1ll<<j) && abs(H-a[r]>=(1ll<<j))){
                suml+=up[l][j];
                sumr+=up[r][j];
                l=p[l][j];
                r=p[r][j];
            }
        }
        for(j=20;j>=0;j--){
            if(abs(H-a[l]+1)>=(1ll<<j))
        }
	}
}
signed main(){
	start();
    ll t=1;
	//cin>>t;
    while(t--) solve();
    return 0;
}
/*






*/

Compilation message

railway_trip.cpp: In function 'void solve()':
railway_trip.cpp:90:39: error: invalid conversion from 'long long int*' to 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-fpermissive]
   90 |         ll low=lb(all(v[a[i]+1]),i)-v[a].begin()-1;
      |                                       ^
      |                                       |
      |                                       long long int*
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from railway_trip.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; std::vector<_Tp, _Alloc>::reference = std::vector<long long int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
railway_trip.cpp:92:13: warning: capture of variable 'p' with non-automatic storage duration
   92 |             p[i][0][0]=v[a[i]+1][low];
      |             ^
railway_trip.cpp:53:4: note: 'long long int p [3005][20][2]' declared here
   53 | ll p[N][20][2];
      |    ^
railway_trip.cpp:92:14: error: expected ',' before '[' token
   92 |             p[i][0][0]=v[a[i]+1][low];
      |              ^
      |              ,
railway_trip.cpp:92:14: error: expected identifier before '[' token
railway_trip.cpp:92:38: error: expected ']' before ';' token
   92 |             p[i][0][0]=v[a[i]+1][low];
      |                                      ^
      |                                      ]
railway_trip.cpp: In lambda function:
railway_trip.cpp:92:38: error: expected '{' before ';' token
railway_trip.cpp: In function 'void solve()':
railway_trip.cpp:93:36: error: no matching function for call to 'lower_bound(std::vector<long long int>::iterator, std::vector<long long int>::iterator)'
   93 |             ll low2=lb(all(v[a[i]]))
      |                                    ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 railway_trip.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:1350:5: note: candidate: 'template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)'
 1350 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_algobase.h:1350:5: note:   template argument deduction/substitution failed:
railway_trip.cpp:93:36: note:   candidate expects 3 arguments, 2 provided
   93 |             ll low2=lb(all(v[a[i]]))
      |                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from railway_trip.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:2031:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> _FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare)'
 2031 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_algo.h:2031:5: note:   template argument deduction/substitution failed:
railway_trip.cpp:93:36: note:   candidate expects 4 arguments, 2 provided
   93 |             ll low2=lb(all(v[a[i]]))
      |                                    ^
railway_trip.cpp:96:9: error: 'low' was not declared in this scope; did you mean 'pow'?
   96 |         low++;
      |         ^~~
      |         pow
railway_trip.cpp:98:13: warning: capture of variable 'p' with non-automatic storage duration
   98 |             p[i][0][1]=v[a[i]+1][low];
      |             ^
railway_trip.cpp:53:4: note: 'long long int p [3005][20][2]' declared here
   53 | ll p[N][20][2];
      |    ^
railway_trip.cpp:98:14: error: expected ',' before '[' token
   98 |             p[i][0][1]=v[a[i]+1][low];
      |              ^
      |              ,
railway_trip.cpp:98:14: error: expected identifier before '[' token
railway_trip.cpp:98:38: error: expected ']' before ';' token
   98 |             p[i][0][1]=v[a[i]+1][low];
      |                                      ^
      |                                      ]
railway_trip.cpp: In lambda function:
railway_trip.cpp:98:38: error: expected '{' before ';' token
railway_trip.cpp: At global scope:
railway_trip.cpp:101:2: error: expected declaration before '}' token
  101 |  }
      |  ^
railway_trip.cpp:102:5: error: expected unqualified-id before 'for'
  102 |     for(ll i1=k-1;i1>0;i1--){
      |     ^~~
railway_trip.cpp:102:19: error: 'i1' does not name a type; did you mean 'y1'?
  102 |     for(ll i1=k-1;i1>0;i1--){
      |                   ^~
      |                   y1
railway_trip.cpp:102:24: error: 'i1' does not name a type; did you mean 'y1'?
  102 |     for(ll i1=k-1;i1>0;i1--){
      |                        ^~
      |                        y1
railway_trip.cpp:114:2: error: 'a' does not name a type
  114 |  a[0]=inf;
      |  ^
railway_trip.cpp:115:2: error: expected unqualified-id before 'for'
  115 |  for(i=0;i<q;i++){
      |  ^~~
railway_trip.cpp:115:10: error: 'i' does not name a type
  115 |  for(i=0;i<q;i++){
      |          ^
railway_trip.cpp:115:14: error: 'i' does not name a type
  115 |  for(i=0;i<q;i++){
      |              ^
railway_trip.cpp:131:1: error: expected declaration before '}' token
  131 | }
      | ^
railway_trip.cpp: In function 'void fre(std::string)':
railway_trip.cpp:42:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
railway_trip.cpp:42:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~