Submission #425441

#TimeUsernameProblemLanguageResultExecution timeMemory
425441errorgornGlobal Warming (NOI13_gw)C++17
Compilation error
0 ms0 KiB
#include <cstdio> #include <algorithm> #include <utility> #include <vector> using namespace std; typedef pair<int,int> ii; vector<ii> v; int n,t,islands,max_islands,prev=1; bool arr[1000005]; int main(){ scanf("%d",&n); for (int x=1;x<=n;x++){ scanf("%d",&t); v.push_back(ii (-t,x)); } sort(v.begin(),v.end()); for (vector<ii>::iterator it=v.begin();it!=v.end();it++){ if ((*it).first!=prev){ prev=(*it).first; max_islands=max(islands,max_islands); } t=(*it).second; if (!(arr[t-1] || arr[t+1])){ islands++; } else if (arr[t-1] && arr[t+1]){ islands--; } arr[t]=true; } printf("%d\n",max(max_islands,islands)); }

Compilation message (stderr)

gw.cpp: In function 'int main()':
gw.cpp:18:22: error: reference to 'prev' is ambiguous
   18 |     if ((*it).first!=prev){
      |                      ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/algorithm:61,
                 from gw.cpp:2:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:224:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename std::iterator_traits<_Iter>::difference_type)'
  224 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
gw.cpp:8:29: note:                 'int prev'
    8 | int n,t,islands,max_islands,prev=1;
      |                             ^~~~
gw.cpp:19:9: error: reference to 'prev' is ambiguous
   19 |         prev=(*it).first;
      |         ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/algorithm:61,
                 from gw.cpp:2:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:224:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename std::iterator_traits<_Iter>::difference_type)'
  224 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
gw.cpp:8:29: note:                 'int prev'
    8 | int n,t,islands,max_islands,prev=1;
      |                             ^~~~
gw.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
gw.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d",&t);
      |     ~~~~~^~~~~~~~~