Submission #99569

# Submission time Handle Problem Language Result Execution time Memory
99569 2019-03-05T10:46:05 Z Mercenary Global Warming (CEOI18_glo) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>

using namespace std;
#define taskname "TEST"
#define pb	push_back
#define mp 	make_pair
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 5;

int n , x , a[maxn];
int prefix[maxn];

void enter()
{
    cin >> n >> x;
    for(int i = 1 ; i <= n ; ++i)
        cin >> a[i];
}

int b[maxn];

void solve()
{
    int m = 0;
    for(int i = 1 ; i <= n ; ++i)
    {
        int k = lower_bound(b + 1 , b + m + 1 , a[i]) - b;
        b[k] = a[i];
        m = max(m , k);
        prefix[i] = k;
        debug(prefix[i]);
    }
    int res = 0;
    m = 0;
    for(int i = n ; i >= 1 ; --i)
    {
        res = max(res , min(m , lower_bound(b + 1 , b + m + 1 , a[i] , greater<int>()) - b - 1) + prefix[i]);
        debug(*lower_bound(b + 1 , b + m + 1 , a[i] , greater<int>()));
        debug(lower_bound(b + 1 , b + m + 1 , a[i] , greater<int>()) - b);
        int k = lower_bound(b + 1 , b + m + 1 , a[i] + x , greater<int>()) - b;
        b[k] = a[i] + x;
        debug(prefix[i],k);
        m = max(m , k);
    }
    cout << res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    enter();
    solve();
}

Compilation message

glo.cpp: In function 'void _dbg(const char*, TH, TA ...)':
glo.cpp:9:3: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
   ^~~~~
glo.cpp:9:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
                                     ^~~~
glo.cpp: In function 'void solve()':
glo.cpp:51:95: error: no matching function for call to 'min(int&, long int)'
         res = max(res , min(m , lower_bound(b + 1 , b + m + 1 , a[i] , greater<int>()) - b - 1) + prefix[i]);
                                                                                               ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
glo.cpp:51:95: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long int')
         res = max(res , min(m , lower_bound(b + 1 , b + m + 1 , a[i] , greater<int>()) - b - 1) + prefix[i]);
                                                                                               ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
glo.cpp:51:95: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long int')
         res = max(res , min(m , lower_bound(b + 1 , b + m + 1 , a[i] , greater<int>()) - b - 1) + prefix[i]);
                                                                                               ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
glo.cpp:51:95: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
         res = max(res , min(m , lower_bound(b + 1 , b + m + 1 , a[i] , greater<int>()) - b - 1) + prefix[i]);
                                                                                               ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
glo.cpp:51:95: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
         res = max(res , min(m , lower_bound(b + 1 , b + m + 1 , a[i] , greater<int>()) - b - 1) + prefix[i]);
                                                                                               ^
glo.cpp:56:23: warning: left operand of comma operator has no effect [-Wunused-value]
         debug(prefix[i],k);
               ~~~~~~~~^
glo.cpp:15:21: note: in definition of macro 'debug'
 #define debug(...) (__VA_ARGS__)
                     ^~~~~~~~~~~
glo.cpp: In function 'int main()':
glo.cpp:67:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".INP", "r",stdin) ,
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
         freopen(taskname".OUT", "w",stdout);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
glo.cpp:67:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]