Submission #784263

#TimeUsernameProblemLanguageResultExecution timeMemory
784263APROHACKMeetings (IOI18_meetings)C++14
Compilation error
0 ms0 KiB
#include "meetings.h" #include <bits/stdc++.h> #define ll long long #define pb push_back #define ss second #define ff first #define izquierda 0 #define derecha 1 using namespace std; ll n, q; ll nxtGrande[100001]; ll anteriorGrande[100001]; ll dp[100001][2]; vector<int>height; struct segTree{ int dd, ht; ll maximo; ll donde; int mid; segTree *L, *R; segTree(int l, int r){ dd = l; ht = r; mid = (dd + ht)/2; maximo = -1; donde = 0; if(l!=r){ L = new segTree(l, mid); R = new segTree(mid+1, r); if(L->maximo > R->maximo){ maximo = L->maximo; donde = L->donde; }else{ maximo = R->maximo; donde = R->donde; } }else{ maximo = height[l]; donde = l; } } ll getMax(int l , int r){ if( dd == l and r == ht){ return maximo; } if( r <= mid ) return L->getMax(l, r); if( mid < l) return R->getMax(l, r); return max(L->getMax(l, mid), R->getMax(mid+1, r)); } pair<ll, ll> query(int l, int r){ if( dd == l and r == ht){ return {donde, maximo}; } if( r <= mid ) return L->query(l, r); if( mid < l) return R->query(l, r); pair<ll, ll> a = L->query(l, mid); pair<ll, ll> b = R->query(mid+1, r); if(a.ss > b.ss){ return a; }else{ return b; } } }; struct seg1{ int dd, ht; ll maximo; int mid; segTree *L, *R; segTree(int l, int r){ dd = l; ht = r; mid = (dd + ht)/2; maximo = -1; if(l!=r){ L = new segTree(l, mid); R = new segTree(mid+1, r); if(L->maximo > R->maximo){ maximo = L->maximo; }else{ maximo = R->maximo; } }else{ maximo = -1; } } void update(int pos, ll cuanto){ if(dd == ht)maximo = max(maximo, cuanto); else if(pos <= mid)L->update(pos, cuanto); else R->update(pos, cuanto); } ll query(int l, int r){ if( dd == l and r == ht){ return maximo; } if( r <= mid ) return L->query(l, r); if( mid < l) return R->query(l, r); ll a = L->query(l, mid); ll b = R->query(mid+1, r); return max(L->query(l, mid), R->query(mid+1, r)); } }; std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L, std::vector<int> R) { q = L.size(); n = H.size(); height = H; set<pair<ll, int> >alturas; // alturas y indices. for(int i = n-1 ; i >= 0 ; i --){ auto sig = alturas.upper_bound({H[i], n}); if(sig == alturas.end())nxtGrande[i] = -1; else{ nxtGrande[i] = (*sig).ss; } vector<pair<ll, int>>toE; for(auto j : alturas){ if(j.ff > H[i])break; toE.pb(j); } for(auto j : toE)alturas.erase(j); alturas.insert({H[i], i}); } alturas.clear(); for(int i = 0 ; i < n ; i ++){ auto sig = alturas.upper_bound({H[i], n}); if(sig == alturas.end())anteriorGrande[i] = -1; else anteriorGrande[i] = (*sig).ss; vector<pair<ll, int>>toE; for(auto j : alturas){ if(j.ff > H[i])break; toE.pb(j); } for(auto j : toE)alturas.erase(j); alturas.insert({H[i], i}); } //for(int i = 0 ; i < n ; i++)cout << anteriorGrande[i] << " " ; //for(int i = 0 ; i < n ; i ++)cout << nxtGrande[i] << " "; for(ll i = n-1 ; i >= 0 ; i --){ int sig = nxtGrande[i]; if(sig == -1)dp[i][derecha] = (n-i)*H[i]; else{ dp[i][derecha] = (sig-i)*H[i] + dp[sig][derecha]; } } for(ll i = 0 ; i < n ; i ++){ int sig = anteriorGrande[i]; if(sig == -1)dp[i][izquierda] = (i+1)*H[i]; else{ dp[i][izquierda] = (i-sig)*H[i] + dp[sig][izquierda]; } } bool all2 = true; for(int i = 0 ; i < n ; i ++)if(H[i] != 1 and H[i] != 2)all2 = false; if(!all2){ //for(int i = 0 ; i < n ; i ++)cout << dp[i][derecha] << " " ; //for(int i = 0 ; i < n ; i ++)cout << dp[i][izquierda] << " " ; segTree *st = new segTree(0, n-1); vector<ll>C; for(int query = 0 ; query < q; query ++){ ll minimum = LLONG_MAX; //cout << "q = " << query << endl; for(int i = L[query] ; i <= R[query] ; i ++){ ll k = st->query(i, R[query]).ff; ll der = dp[i][derecha] - dp[k][derecha] + (R[query]-k+1)*H[k]; k = st->query(L[query], i).ff; ll izq = dp[i][izquierda] - dp[k][izquierda] + (k-L[query]+1)*H[k]; minimum = min(minimum, der + izq - H[i]); //cout << i << " " << izq << " + " << der << endl; } C.pb(minimum); } }else{ seg1 *stR = new seg1(0, n-1); int lleva = 0, desde = -1; vector<pair<int, int>>conjuntitos; int pertenece[n+1]; for(int i = 0 ; i < n ; i ++){ if(H[i] == 2 and desde == -1)continue; if(H[i] == 2){ conjuntitos.pb(desde, i-1); for(int j = desde ; j <= i-1 ; j ++)pertenece[j] = conjuntitos.size()-1; desde = -1; lleva = 0; stR->update(i-1, lleva); }else{ if(desde == -1){ lleva = 1; desde = i; }else lleva ++ ; } } for(int query = 0 ; query < q ; query ++){ ll li = L[query], ls = R[query]; ll total = R[query] - L[query] + 1; ll a = 0, b = 0; if(H[li] == 1){ a = conjuntitos[pertenece[li]].ss - L[query] + 1; li = conjuntitos[pertenece[li]].ss + 1 } if(H[ls] == 1){ b = R[query]-conjuntitos[pertenece[ls]].ff + 1; ls = conjuntitos[pertenece[ls]].ff -1; } ll ans ; ans = min ( ans, (total-a)*2 + a); ans = min(ans, (total - b)*2 + b); if(li <= ls){ ll cu = st->query(li, ls); ans = min (ans, (total - cu)*2 + cu; } C.pb(ans); } } return C; }

Compilation message (stderr)

meetings.cpp:76:10: error: expected unqualified-id before 'int'
   76 |  segTree(int l, int r){
      |          ^~~
meetings.cpp:76:10: error: expected ')' before 'int'
   76 |  segTree(int l, int r){
      |         ~^~~
      |          )
meetings.cpp: In member function 'void seg1::update(int, long long int)':
meetings.cpp:97:25: error: 'struct segTree' has no member named 'update'
   97 |   else if(pos <= mid)L->update(pos, cuanto);
      |                         ^~~~~~
meetings.cpp:98:11: error: 'struct segTree' has no member named 'update'
   98 |   else R->update(pos, cuanto);
      |           ^~~~~~
meetings.cpp: In member function 'long long int seg1::query(int, int)':
meetings.cpp:105:33: error: cannot convert 'std::pair<long long int, long long int>' to 'long long int' in return
  105 |   if( r <= mid ) return L->query(l, r);
      |                         ~~~~~~~~^~~~~~
      |                                 |
      |                                 std::pair<long long int, long long int>
meetings.cpp:106:31: error: cannot convert 'std::pair<long long int, long long int>' to 'long long int' in return
  106 |   if( mid < l) return R->query(l, r);
      |                       ~~~~~~~~^~~~~~
      |                               |
      |                               std::pair<long long int, long long int>
meetings.cpp:107:18: error: cannot convert 'std::pair<long long int, long long int>' to 'long long int' in initialization
  107 |   ll a = L->query(l, mid);
      |          ~~~~~~~~^~~~~~~~
      |                  |
      |                  std::pair<long long int, long long int>
meetings.cpp:108:18: error: cannot convert 'std::pair<long long int, long long int>' to 'long long int' in initialization
  108 |   ll b = R->query(mid+1, r);
      |          ~~~~~~~~^~~~~~~~~~
      |                  |
      |                  std::pair<long long int, long long int>
meetings.cpp:109:13: error: cannot convert 'const std::pair<long long int, long long int>' to 'long long int' in return
  109 |   return max(L->query(l, mid), R->query(mid+1, r));
      |          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |             |
      |             const std::pair<long long int, long long int>
meetings.cpp:107:6: warning: unused variable 'a' [-Wunused-variable]
  107 |   ll a = L->query(l, mid);
      |      ^
meetings.cpp:108:6: warning: unused variable 'b' [-Wunused-variable]
  108 |   ll b = R->query(mid+1, r);
      |      ^
meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:190:30: error: new initializer expression list treated as compound expression [-fpermissive]
  190 |   seg1 *stR = new seg1(0, n-1);
      |                              ^
meetings.cpp:190:24: warning: left operand of comma operator has no effect [-Wunused-value]
  190 |   seg1 *stR = new seg1(0, n-1);
      |                        ^
meetings.cpp:190:30: error: no matching function for call to 'seg1::seg1(long long int)'
  190 |   seg1 *stR = new seg1(0, n-1);
      |                              ^
meetings.cpp:71:8: note: candidate: 'seg1::seg1()'
   71 | struct seg1{
      |        ^~~~
meetings.cpp:71:8: note:   candidate expects 0 arguments, 1 provided
meetings.cpp:71:8: note: candidate: 'constexpr seg1::seg1(const seg1&)'
meetings.cpp:71:8: note:   no known conversion for argument 1 from 'long long int' to 'const seg1&'
meetings.cpp:71:8: note: candidate: 'constexpr seg1::seg1(seg1&&)'
meetings.cpp:71:8: note:   no known conversion for argument 1 from 'long long int' to 'seg1&&'
meetings.cpp:197:30: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(int&, int)'
  197 |     conjuntitos.pb(desde, i-1);
      |                              ^
In file included from /usr/include/c++/10/vector:67,
                 from meetings.h:3,
                 from meetings.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note:   candidate expects 1 argument, 2 provided
meetings.cpp:215:43: error: expected ';' before '}' token
  215 |     li = conjuntitos[pertenece[li]].ss + 1
      |                                           ^
      |                                           ;
  216 |    }
      |    ~                                       
meetings.cpp:226:13: error: 'st' was not declared in this scope; did you mean 'stR'?
  226 |     ll cu = st->query(li, ls);
      |             ^~
      |             stR
meetings.cpp:227:40: error: expected ')' before ';' token
  227 |     ans = min (ans, (total - cu)*2 + cu;
      |               ~                        ^
      |                                        )
meetings.cpp:229:4: error: 'C' was not declared in this scope
  229 |    C.pb(ans);
      |    ^
meetings.cpp:235:9: error: 'C' was not declared in this scope
  235 |  return C;
      |         ^