Submission #966854

#TimeUsernameProblemLanguageResultExecution timeMemory
966854Trisanu_DasEvent Hopping 2 (JOI21_event2)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> v; set<pair<int,int>> S; int L[100005], R[100005], J[17][200005]; int get(int l, int r){ int T = 0; for(int i = 16; i >= 0; i--) if(J[i][l] <= r) l = J[i][l], T += (1 << i); return T; } int main(){ cin >> n >> k; for(int i = 1; i <= n; i++) cin >> L[i] >> R[i], v.pb(L[i]), v.pb(R[i]); sort(v.begin(), v.end); v.erase(unique(v.begin(), v.end()), v.end()); int m = v.size(); for(int i = 0; i <= m; i++) J[0][i] = m; for(int i = 1; i <= n; i++){ L[i] = lower_bound(all(v),L[i])-begin(v); R[i] = lower_bound(all(v),R[i])-begin(v); J[0][L[i]] = min(J[0][L[i]],R[i]); } for(int i = m - 1; i >= 0; i--) J[0][i] = min(J[0][i],J[0][i+1]); for(int i = 1; i < 17; i++) for(int j = 0; j <= m; j++) J[i][j] = J[i - 1][J[i - 1][j]]; int T = get(0, m - 1); if(T < k){cout << -1; return 0;} S.insert({0, 0}), S.insert({m - 1, m - 1}); for(int i = 1; i <= n; i++){ auto it = S.lower_bound({R[i],0}); int r = it->first, l = (--it)->second; int num = T-get(l,r)+get(l,L[i])+get(R[i],r)+1; if(L[i]>=l and num>=k){ cout << i << "\n"; T=num; S.insert({L[i],R[i]}); if(S.size()==k+2) break; } } }

Compilation message (stderr)

event2.cpp: In function 'int main()':
event2.cpp:18:56: error: 'class std::vector<int>' has no member named 'pb'
   18 |     for(int i = 1; i <= n; i++) cin >> L[i] >> R[i], v.pb(L[i]), v.pb(R[i]);
      |                                                        ^~
event2.cpp:18:68: error: 'class std::vector<int>' has no member named 'pb'
   18 |     for(int i = 1; i <= n; i++) cin >> L[i] >> R[i], v.pb(L[i]), v.pb(R[i]);
      |                                                                    ^~
event2.cpp:19:26: error: no matching function for call to 'sort(std::vector<int>::iterator, <unresolved overloaded function type>)'
   19 |     sort(v.begin(), v.end); v.erase(unique(v.begin(), v.end()), v.end());
      |                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from event2.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4849:5: note: candidate: 'void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
 4849 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/10/bits/stl_algo.h:4849:63: note:   no known conversion for argument 2 from '<unresolved overloaded function type>' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >'
 4849 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |                                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/10/bits/stl_algo.h:4880:5: note: candidate: 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
 4880 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/10/bits/stl_algo.h:4880:5: note:   template argument deduction/substitution failed:
event2.cpp:19:26: note:   candidate expects 3 arguments, 2 provided
   19 |     sort(v.begin(), v.end); v.erase(unique(v.begin(), v.end()), v.end());
      |                          ^
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from event2.cpp:1:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:292:1: note:   template argument deduction/substitution failed:
event2.cpp:19:26: note:   candidate expects 4 arguments, 2 provided
   19 |     sort(v.begin(), v.end); v.erase(unique(v.begin(), v.end()), v.end());
      |                          ^
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from event2.cpp:1:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:296:1: note:   template argument deduction/substitution failed:
event2.cpp:19:26: note:   candidate expects 3 arguments, 2 provided
   19 |     sort(v.begin(), v.end); v.erase(unique(v.begin(), v.end()), v.end());
      |                          ^
event2.cpp:23:28: error: 'all' was not declared in this scope; did you mean 'std::filesystem::perms::all'?
   23 |         L[i] = lower_bound(all(v),L[i])-begin(v);
      |                            ^~~
      |                            std::filesystem::perms::all
In file included from /usr/include/c++/10/filesystem:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from event2.cpp:1:
/usr/include/c++/10/bits/fs_fwd.h:148:7: note: 'std::filesystem::perms::all' declared here
  148 |       all  =  0777,
      |       ^~~
event2.cpp:40:24: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |             if(S.size()==k+2) break;
      |                ~~~~~~~~^~~~~