제출 #1018411

#제출 시각아이디문제언어결과실행 시간메모리
1018411YassirSalamaElection (BOI18_election)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define endl "\n"
// #define int ll
using ull=unsigned long long;
using ll=long long;
using pii=pair<int,int>;
const int mod=1e9+7;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
template <typename T> istream& operator>>(istream& is, vector<T> &a) {
    copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;}
#ifdef IOI
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int mxn=5e5+100;
struct Node{
    int sum;
    int mxl;
    int mxr;
    int ans;
} tree[mxn];
int arr[mxn];
Node merge(Node a,Node b){
    Node c;
    c.sum=a.sum+b.sum;
    c.mxl=max(a.mxl,a.sum+b.mxl);
    c.mxr=max(b.mxr,b.sum+a.mxr);
    c.ans=max({a.mxl+b.mxr,a.sum+b.ans,b.sum+a.ans});
    return c;
}
void build(int node,int l,int r){
    if(l==r){
        int x=max(0LL,arr[l]);
        tree[node]={arr[l],x,x,x};
        return;
    }
    int mid=(l+r)/2;
    build(node<<1,l,mid);
    build(node<<1|1,mid+1,r);
    tree[node]=merge(tree[node<<1],tree[node<<1|1]);
}
Node query(int node,int l,int r,int ql,int qr){
    if(ql>r||qr<l) return {0,0,0,0};
    if(ql<=l&&r<=qr) return tree[node];
    int mid=(l+r)/2;
    return merge(
        query(node<<1,l,mid,ql,qr),
        query(node<<1|1,mid+1,r,ql,qr)
        );
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n;
cin>>n;
string s;
cin>>s;
// int arr[n];
for(int i=0;i<n;i++){
    if(s[i]=='C') arr[i]=-1;
    else arr[i]=1;
}
build(1,0,n-1);
int q;
cin>>q;
while(q--){
    int l,r;
    cin>>l>>r;
    cout<<query(1,0,n-1,l-1,r-1).ans<<endl;
}
}

컴파일 시 표준 에러 (stderr) 메시지

election.cpp: In function 'void build(int, int, int)':
election.cpp:45:29: error: no matching function for call to 'max(long long int, int&)'
   45 |         int x=max(0LL,arr[l]);
      |                             ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from election.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:
election.cpp:45:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   45 |         int x=max(0LL,arr[l]);
      |                             ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from election.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:
election.cpp:45:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   45 |         int x=max(0LL,arr[l]);
      |                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from election.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:
election.cpp:45:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   45 |         int x=max(0LL,arr[l]);
      |                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from election.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:
election.cpp:45:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   45 |         int x=max(0LL,arr[l]);
      |                             ^