Submission #549836

#TimeUsernameProblemLanguageResultExecution timeMemory
549836lobo_prixHoliday (IOI14_holiday)C++17
Compilation error
0 ms0 KiB
//[Author] tuxedcat //[Date] 2022.04.17 //[File] src/holiday.cpp //[Library] https://github.com/tuxedcat/pslib #pragma GCC optimize("O3") #include <bits/stdc++.h> #define _EXT_CODECVT_SPECIALIZATIONS_H 1 #define _EXT_ENC_FILEBUF_H 1 #include <bits/extc++.h> using namespace std; #define int i64 #define FP_EPS 1e-11 #define COUT_FP 11 using f64=double; //long double(살짝느림),__float128(매우느림) // #define CPP20 1 #define DBG_SETW 3 // #define endl '\n' //remove it when interactive #define fi first #define se second #define mkp make_pair #define mkt make_tuple #define lb lower_bound #define ub upper_bound #define bs binary_search #define itos to_string #define head(x) (x.begin()) #define tail(x) prev(x.end()) #define dbg(...) void(0) #define dbgif(...) void(0) #define dbg1(...) void(0) #define dbg1if(...) void(0) using i64=long long;using u64=unsigned long long;using u32=unsigned; using pint=pair<int,int>;using tint=tuple<int,int,int>; template<class T>using Str=basic_string<T>; template<class T,class CMP=less<>>using PQ=std::priority_queue<T,vector<T>,CMP>; //functions before include <arr.h> //Math #if !(CPP20) #define countl_zero(x) __builtin_clzll(x) #define popcount(x) __builtin_popcountll(x) #define bit_ceil(x) 1<<clg2(x) #endif #if CPP20 // #define sz ssize template<class T>int sz(const T& x){return x.size();} #else template<class T>int sz(const T& x){return x.size();} #endif int fdiv(int a,int b){if(b<0)a=-a,b=-b;return (a>0)?a/b:(a-b+1)/b;} int cdiv(int a,int b){if(b<0)a=-a,b=-b;return (a>0)?(a+b-1)/b:a/b;} i64 flg2(u64 x){return 63-countl_zero(x);} i64 clg2(u64 x){return x-1==0?0:64-countl_zero(x-1);} int fsqrt(i64 n) {i64 i=1;while(i*i<=n)i++;return i-1;} int csqrt(i64 n) {i64 i=1;while(i*i<n)i++;return i;} template<class T>T sq(T x){return x*x;} template<class T>constexpr T inf(){return numeric_limits<T>::max()/2;} template<class T>constexpr T nan(){return inf<T>()+1;} #ifdef CPP20 template<typename T> concept MemberInf=requires(T t){t.inf();}; template<typename T> concept MemberNan=requires(T t){t.nan();}; template<MemberInf T>T inf(){return T().inf();} template<MemberNan T>T nan(){return T().nan();} #endif //IO & misc template<class...A>void print(A...a){((cout<<a),...);} template<class...A>void println(A...a){((cout<<a),...,(cout<<endl));} template<class T=int>T input(){T x;cin>>x;return x;} template<class T,class U>bool assmin(T& a,U&& b){return a>b?a=b,true:false;} template<class T,class U>bool assmax(T& a,U&& b){return a<b?a=b,true:false;} void MUST(bool expr){ #if DEBUG #include <csignal> if(!expr) raise(SIGINT); #endif } #define ARG(...) __VA_ARGS__ #define func(RetT,fname,...) function<RetT(__VA_ARGS__)> fname=[&](__VA_ARGS__)->RetT #define lam(expr,...) [&](__VA_ARGS__){return expr;} #define lamp(expr,...) [](__VA_ARGS__){return expr;} template<class T, class P=vector<T>> struct Arr:public P{ Arr(){P::shrink_to_fit();} explicit Arr(signed n):P(n){} explicit Arr(signed n,T init):P(n,init){} Arr(initializer_list<T>il):P(il){} Arr(auto its, auto ite):P(its,ite){} inline T& operator[](signed i){ int n=sz(*this); if(i<0)i+=n,dbg1("Neg Index Found"); if(i>=n)i-=n,dbg1("Over Index Found"); return P::operator[](i); } const T& operator[](signed i)const{ int n=sz(*this); if(i<0)i+=n,dbg1("Neg Index Found"); if(i>=n)i-=n,dbg1("Over Index Found"); return P::operator[](i); } T& at(signed i){return *this[i];} const T& at(signed i)const{return *this[i];} }; template<class... A> auto ARR(auto n,A&&... a) {if constexpr(!sizeof...(a)) return n; else return Arr(n,ARR(a...));} //Consts // const f64 pi=numbers::pi_v<f64>,eps=FP_EPS; const f64 pi=acos(-1),eps=FP_EPS; const int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}}; //functions after include <arr.h> template<class T>int argmin(const Arr<T>& a){return min_element(a.begin(),a.end())-a.begin();} template<class T>int argmax(const Arr<T>& a){return max_element(a.begin(),a.end())-a.begin();} Arr<int> permuinv(const Arr<int>& a){Arr<int> r(sz(a));for(int i=0;i<sz(a);i++)r[a[i]]=i;return r;} template<class T>map<T,Arr<int>> classify(const Arr<T>& a){ map<T,Arr<int>> r; for(int i=0;i<sz(a);i++) r[a[i]].push_back(i); return r; } //Pre-runs #if !(DEBUG) auto __PR1=(ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)); #endif auto& __PR2=(cout<<fixed<<setprecision(COUT_FP)); // #ifdef CPP20 template<typename T> concept Monoid=requires(T t){ T::f(T::id(),T::id()); T::fn(T::id(),0); //T::T; }; #else #define Monoid class #endif template<class T, class M> T fn(T x,int n){ //f(...f(f(id,x),x),...,x) n겹 O(log(n)) if(!n)return M::id(); T res=fn<T,M>(x,n/2); return n%2?M::f(M::f(res,res),x):M::f(res,res); } template<class T>struct MAdd{ static T id(){return T(0);} static T f(T x,T y){return x+y;} static T fn(T x,int n){return x*n;} }; template<class T>struct MMul{ static T id(){return T(1);} static T f(T x,T y){return x*y;} static T fn(T x,int n){return ::fn<T,MMul<T>>(x,n);} }; template<class T>struct MAss{ static T id(){return nan<T>();} static T f(T x,T y){return y==id()?x:y;} static T fn(T x,int n){return x;} }; template<class T>struct MMin{ static T id(){return inf<T>();} static T f(T x,T y){return min(x,y);} static T fn(T x,int n){return x;} }; template<class T>struct MMax{ static T id(){return -inf<T>();} static T f(T x,T y){return max(x,y);} static T fn(T x,int n){return x;} }; template<class T>struct MXor{ static T id(){return T(0);} static T f(T x,T y){return x^y;} static T fn(T x,int n){return n%2?x:0;} }; template<class T>struct MGcd{ static T id(){return T(0);} static T f(T x,T y){return gcd(x,y);} static T fn(T x,int n){return x;} }; template<class T>struct MFunc{ static T id(){return T();} static T f(T x,T y){return x.f(y);} static T fn(T x,int n){return ::fn<T,MFunc<T>>(x,n);} }; #ifdef CPP20 //NOTE: non-empty. empty-able일시 max(0,val.m)하면 됨 struct TMaxSubArr{ int s=0,l=-inf<int>(),m=-inf<int>(),r=-inf<int>(); TMaxSubArr f(TMaxSubArr x)const{return {s+x.s,max(l,s+x.l),max({m,r+x.l,x.m}),max(r+x.s,x.r)};} TMaxSubArr nan()const{return {::nan<int>(),::nan<int>(),::nan<int>(),::nan<int>()};} friend strong_ordering operator<=>(const TMaxSubArr&,const TMaxSubArr&)=default; TMaxSubArr rev()const{return {s,r,m,l};}//for commutativeless query, refer boj13519 }; template<Monoid M> auto scanl(auto s,auto e){ using T=decltype(M::id()); int n=e-s; Arr<T> b={M::id()}; while(s!=e) b.emplace_back(M::f(b.back(),*s++)); rotate(b.begin(),b.begin()+1,b.end()); return b; } template<Monoid M> auto scanr(auto s,auto e){ using T=decltype(M::id()); int n=e-s; Arr<T> b={M::id()}; while(s!=e) b.emplace_back(M::f(b.back(),*--e)); reverse(b.begin(),b.end()); return b; } #endif template<Monoid Q,auto fupd,int xlo=0,int xhi=inf<signed>()> struct SegPersi{ using T=decltype(Q::id()); T v=Q::id(); SegPersi *l{},*r{}; ~SegPersi(){/*double free?*/} SegPersi* upd(int i,T x,int cs=xlo,int ce=xhi){ if(ce<=i or i+1<=cs) return this; if(i<=cs and ce<=i+1) return new SegPersi{fupd(v,x)}; int cm=(cs+ce)/2; if(!l)l=new SegPersi; if(!r)r=new SegPersi; auto ret=new SegPersi; ret->l=l->upd(i,x,cs,cm); ret->r=r->upd(i,x,cm,ce); ret->v=Q::f(ret->l->v,ret->r->v); return ret; } T q(int s,int e, int cs=xlo, int ce=xhi){ if(ce<=s or e<=cs)return Q::id(); if(s<=cs and ce<=e) return v; int cm=(cs+ce)/2; if(!l)l=new SegPersi; if(!r)r=new SegPersi; return Q::f(l->q(s,e,cs,cm),r->q(s,e,cm,ce)); } }; void dnc(Arr<int>& a,const Arr<int>& b,function<int(int,int)> c,int s,int e,int ks,int ke){ if(e-s<=0)return; int m=(s+e)/2,km=ks; for(int k=ks;k<ke;k++) if(a[m]>b[k]+c(k+1,m+1)) a[m]=b[k]+c(k+1,m+1),km=k; dnc(a,b,c,s,m,ks,km+1),dnc(a,b,c,m+1,e,km,ke); } void dnc(Arr<int>& a,const Arr<int>& b,function<int(int,int)> c,int s,int e){dnc(a,b,c,s,e,s-1,e);} struct A{ int cnt,sum; A(int cnt=0,int sum=0):cnt(cnt),sum(sum){} A operator+(A o)const{return {cnt+o.cnt,sum+o.sum};} }; using PST=SegPersi<MAdd<A>,[](A x, A y){return y;},0,3333>; int calc(Arr<int> a,int p,int d){ int n=sz(a); Arr<int> o(n); iota(o.begin(),o.end(),0); sort(o.begin(),o.end(),lam(a[i]>a[j],int i,int j)); Arr<PST*> ver(n+1); ver[-1]=new PST; for(int i=0;i<n;i++) ver[i]=ver[i-1]->upd(o[i],{1,a[o[i]]}); func(int,f,int s,int e){ int move=abs(p-s)+e-s-1; int c=min<int>(d-move,e-s); //TODO: select largest c numbers in [s,e) int ss=-1,ee=n-1; while(ee-ss>1){ int mm=(ss+ee)/2; if(ver[mm]->q(s,e).cnt<c) ss=mm; else ee=mm; } return -ver[ee]->q(s,e).sum; }; Arr<int> arr(n+1); dnc(arr,Arr<int>(n+1),f,0,n); return -*min_element(arr.begin(),arr.end()); } void solve(){ int n,p,d; cin>>n>>p>>d; Arr<int> a(n); for(auto&i:a)cin>>i; auto b=a; reverse(b.begin(),b.end()); println(max(calc(a,p,d),calc(b,n-1-p,d))); } signed main(){ solve(); }

Compilation message (stderr)

holiday.cpp:92:6: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   92 |  Arr(auto its, auto ite):P(its,ite){}
      |      ^~~~
holiday.cpp:92:16: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   92 |  Arr(auto its, auto ite):P(its,ite){}
      |                ^~~~
holiday.cpp:108:31: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
  108 | template<class... A> auto ARR(auto n,A&&... a)
      |                               ^~~~
holiday.cpp:264:28: error: lambda-expression in template-argument only available with '-std=c++2a' or '-std=gnu++2a'
  264 | using PST=SegPersi<MAdd<A>,[](A x, A y){return y;},0,3333>;
      |                            ^
holiday.cpp:264:58: error: template argument 2 is invalid
  264 | using PST=SegPersi<MAdd<A>,[](A x, A y){return y;},0,3333>;
      |                                                          ^
holiday.cpp: In function 'i64 calc(Arr<long long int>, i64, i64)':
holiday.cpp:271:6: error: 'PST' was not declared in this scope
  271 |  Arr<PST*> ver(n+1);
      |      ^~~
holiday.cpp:271:10: error: template argument 1 is invalid
  271 |  Arr<PST*> ver(n+1);
      |          ^
holiday.cpp:271:10: error: template argument 2 is invalid
holiday.cpp:272:5: error: invalid types 'int[int]' for array subscript
  272 |  ver[-1]=new PST;
      |     ^
holiday.cpp:272:14: error: 'PST' does not name a type
  272 |  ver[-1]=new PST;
      |              ^~~
holiday.cpp:274:6: error: invalid types 'int[i64 {aka long long int}]' for array subscript
  274 |   ver[i]=ver[i-1]->upd(o[i],{1,a[o[i]]});
      |      ^
holiday.cpp:274:13: error: invalid types 'int[i64 {aka long long int}]' for array subscript
  274 |   ver[i]=ver[i-1]->upd(o[i],{1,a[o[i]]});
      |             ^
holiday.cpp: In lambda function:
holiday.cpp:284:10: error: invalid types 'int[i64 {aka long long int}]' for array subscript
  284 |    if(ver[mm]->q(s,e).cnt<c) ss=mm;
      |          ^
holiday.cpp:287:14: error: invalid types 'int[i64 {aka long long int}]' for array subscript
  287 |   return -ver[ee]->q(s,e).sum;
      |              ^