답안 #947953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947953 2024-03-17T09:43:44 Z yeediot 휴가 (IOI14_holiday) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())
#define __lg(x) 63-__builtin_clzll(x)
#define pow2(x) (1LL<<x)
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
const int mxn=1e5+5;
multiset<long long>bg,sm;
long long n,st,d,L,R;
long long cur,v[mxn];
void sir(int l,int r,int k){
    while(L>l){
        bg.insert(v[--L]);
        cur+=v[L];
        
    }
    while(R<r){
        bg.insert(v[++R]);
        cur+=v[R];
    }
    while(L<l){
        if(bg.find(v[L])!=bg.end()){
            cur-=v[L];
            bg.erase(bg.find(v[L]));
        }
        else{
            sm.erase(sm.find(v[L]));
        }
        L++;
    }
    while(R>r){
        if(bg.find(v[R])!=bg.end()){
            cur-=v[R];
            bg.erase(bg.find(v[R]));
        }
        else{
            sm.erase(sm.find(v[R]));
        }
        R--;
    }
    while(sz(bg) and sz(bg)>k){
        cur-=*bg.begin();
        sm.insert(*bg.begin());
        bg.erase(bg.begin());
    }
    while(sz(sm) and sz(bg)<k){
        cur+=*prev(sm.end());
        bg.insert(*prev(sm.end()));
        sm.erase(prev(sm.end()));
    }
}

long long ans;
void solve(int l,int r,int ql,int qr){
    //debug(l,r,ql,qr);
    if(l>r){
        return;
    }
    int mm=l+r>>1;
    long long mx=-1;
    long long best=-1;
    for(int i=max(ql,mm);i<=qr;i++){
        int x=max(0,d-(min(i-st,st-mm)+i-mm));
        if(x<=0)break;
        sir(mm,i,x);
        debug(mm,i,x);
        if((mx==-1 or cur>mx) and sz(bg)<=x){
            best=i;
            mx=cur;
        }
    }
    chmax(ans,mx);
    solve(l,mm-1,ql,best);
    solve(mm+1,r,best,qr);
}
long long findMaxAttraction(int N,int ST,int D,int a[]){
    n=N,st=ST,d=D;
    for(int i=0;i<n;i++){
        v[i]=a[i];
    }
    bg.insert(v[0]);
    cur+=v[0];
    sir(0,n-1,n);
    solve(0,n-1,0,n-1);
    return ans;
}
#ifdef local
int main(){
    setio();
    int a,b,c;
    cin>>a>>b>>c;
    int x[n];
    for(int i=0;i<a;i++){
        cin>>x[i];
    }
    cout<<findMaxAttraction(a,b,c,x)<<'\n';
}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

 /*
 input:
 
 */















 

Compilation message

holiday.cpp: In function 'void solve(int, int, int, int)':
holiday.cpp:92:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   92 |     int mm=l+r>>1;
      |            ~^~
holiday.cpp:96:45: error: no matching function for call to 'max(int, long long int)'
   96 |         int x=max(0,d-(min(i-st,st-mm)+i-mm));
      |                                             ^
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 holiday.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
holiday.cpp:96:45: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   96 |         int x=max(0,d-(min(i-st,st-mm)+i-mm));
      |                                             ^
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 holiday.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
holiday.cpp:96:45: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   96 |         int x=max(0,d-(min(i-st,st-mm)+i-mm));
      |                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from holiday.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
holiday.cpp:96:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   96 |         int x=max(0,d-(min(i-st,st-mm)+i-mm));
      |                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from holiday.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
holiday.cpp:96:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   96 |         int x=max(0,d-(min(i-st,st-mm)+i-mm));
      |                                             ^