Submission #1273443

#TimeUsernameProblemLanguageResultExecution timeMemory
1273443YSH2020Poklon (COCI17_poklon)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; struct node { int s, e, m; node *l, *r; int val; node (int _s, int _e) { s = _s; e=_e; m=(s+e)/2; val=0; if (s!=e){ l = new node(s, m); r = new node(m+1, e);} } void upd(int x, int v) { if (s==e) {val=v; return;} if (x>m) r->upd(x,v); else l->upd(x,v); val=(l->val+ r->val); } int qry(int x, int y) { if (x<=s and y>=e) return val; if (x > m) return r->qry(x,y); if (y <= m) return l->qry(x,y); return (l->qry(x,m)+ r->qry(m+1, y)); } }*root1, *root2, *root3; int main() { int n, q; cin >> n >> q; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; map<int,int> t; int last[n]; vector<int> l(n), ll(n), lll(n); for (int i = n-1; i >= 0; i--) { if (t.find(a[i]) == t.end()) last[i] = n+5; else last[i]=t[a[i]]; t[a[i]]=i; l.push_back({last[i], i}); } int lastlast[n]; for (int i = 0; i < n; i++) { if (last[i]==n+5) lastlast[i]=n+5; else lastlast[i]=last[last[i]]; ll.push_back({lastlast[i], i}); } int lastlastlast[n]; for (int i = 0; i < n; i++) { if (lastlast[i]==n+5)lastlastlast[i]=n+5; else lastlastlast[i]=last[lastlast[i]]; lll.push_back({lastlastlast[i], i}); } vector<pair<int, pair<int,int>>> query(q); int ans[q]; for (int i = 0; i < q; i++) { cin >> query[i].second.first; cin >> query[i].first; query[i].second.second=i; } sort(query.begin(), query.end()); reverse(query.begin(), query.end()); sort(l.begin(), l.end()); sort(ll.begin(), ll.end()); sort(lll.begin(), lll.end()); int idx1=n-1, idx2=n-1, idx3=n-1; root1 = new node(0, n); root2 = new node(0, n); root3 = new node(0, n); for (int i = 0; i < q; i++) { while (idx1 != -1 and l[idx1].first > q[i].first) { root1->upd(l[idx1].second, 1); idx1--; } while (idx2 != -1 and ll[idx2].first > q[i].first) { root2->upd(ll[idx2].second, 1); idx2--; } while (idx3 != -1 and lll[idx3].first > q[i].first) { root3->upd(lll[idx3].second, 1); idx3--; } int b=root2->qry(q[i].second.first, q[i].first); int a=root1->qry(q[i].second.first, q[i].first); int c=root3->qry(q[i].second.first, q[i].first); ans[q[i].second.second]=2*b-a-c; } for (int i = 0; i < q; i++) cout << ans[i] << '\n'; }

Compilation message (stderr)

poklon.cpp: In function 'int main()':
poklon.cpp:41:20: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   41 |         l.push_back({last[i], i});
      |         ~~~~~~~~~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from poklon.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
poklon.cpp:46:21: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   46 |         ll.push_back({lastlast[i], i});
      |         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
poklon.cpp:51:22: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   51 |         lll.push_back({lastlastlast[i], i});
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
poklon.cpp:70:39: error: request for member 'first' in 'l.std::vector<int>::operator[](((std::vector<int>::size_type)idx1))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   70 |         while (idx1 != -1 and l[idx1].first > q[i].first) {
      |                                       ^~~~~
poklon.cpp:70:48: error: invalid types 'int[int]' for array subscript
   70 |         while (idx1 != -1 and l[idx1].first > q[i].first) {
      |                                                ^
poklon.cpp:71:32: error: request for member 'second' in 'l.std::vector<int>::operator[](((std::vector<int>::size_type)idx1))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   71 |             root1->upd(l[idx1].second, 1);
      |                                ^~~~~~
poklon.cpp:74:40: error: request for member 'first' in 'll.std::vector<int>::operator[](((std::vector<int>::size_type)idx2))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   74 |         while (idx2 != -1 and ll[idx2].first > q[i].first) {
      |                                        ^~~~~
poklon.cpp:74:49: error: invalid types 'int[int]' for array subscript
   74 |         while (idx2 != -1 and ll[idx2].first > q[i].first) {
      |                                                 ^
poklon.cpp:75:33: error: request for member 'second' in 'll.std::vector<int>::operator[](((std::vector<int>::size_type)idx2))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   75 |             root2->upd(ll[idx2].second, 1);
      |                                 ^~~~~~
poklon.cpp:78:41: error: request for member 'first' in 'lll.std::vector<int>::operator[](((std::vector<int>::size_type)idx3))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   78 |         while (idx3 != -1 and lll[idx3].first > q[i].first) {
      |                                         ^~~~~
poklon.cpp:78:50: error: invalid types 'int[int]' for array subscript
   78 |         while (idx3 != -1 and lll[idx3].first > q[i].first) {
      |                                                  ^
poklon.cpp:79:34: error: request for member 'second' in 'lll.std::vector<int>::operator[](((std::vector<int>::size_type)idx3))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   79 |             root3->upd(lll[idx3].second, 1);
      |                                  ^~~~~~
poklon.cpp:82:27: error: invalid types 'int[int]' for array subscript
   82 |         int b=root2->qry(q[i].second.first, q[i].first);
      |                           ^
poklon.cpp:82:46: error: invalid types 'int[int]' for array subscript
   82 |         int b=root2->qry(q[i].second.first, q[i].first);
      |                                              ^
poklon.cpp:83:27: error: invalid types 'int[int]' for array subscript
   83 |         int a=root1->qry(q[i].second.first, q[i].first);
      |                           ^
poklon.cpp:83:46: error: invalid types 'int[int]' for array subscript
   83 |         int a=root1->qry(q[i].second.first, q[i].first);
      |                                              ^
poklon.cpp:84:27: error: invalid types 'int[int]' for array subscript
   84 |         int c=root3->qry(q[i].second.first, q[i].first);
      |                           ^
poklon.cpp:84:46: error: invalid types 'int[int]' for array subscript
   84 |         int c=root3->qry(q[i].second.first, q[i].first);
      |                                              ^
poklon.cpp:85:14: error: invalid types 'int[int]' for array subscript
   85 |         ans[q[i].second.second]=2*b-a-c;
      |              ^