Submission #1119794

#TimeUsernameProblemLanguageResultExecution timeMemory
1119794dbenceAliens (IOI16_aliens)C++14
Compilation error
0 ms0 KiB
#include "aliens.h" #include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #define xx first #define yy second #define l(x) (x << 1) + 1 #define r(x) (x << 1) + 2 using namespace std; typedef long long ll; const ll N = 1e5 + 1 const ll M = 1e6 + 1; const ll inf = 1ll << 60; int n, m, k, lef[M], xs[N]; ll ans[M]; struct Node { int l, r; int a; ll b; } node[N << 2]; struct Change { int id; int a; ll b; }; vector <Change> changes[N]; ll eval(ll a, ll b, int x) { return 1ll * a * xs[x] + b; } void update(int id, int a, ll b, vector <Change> &changes) { int q = node[id].l + node[id].r >> 1; int l = node[id].l; if (eval(node[id].a, node[id].b, q) > eval(a, b, q)) { swap(node[id].a, a); swap(node[id].b, b); changes.push_back({id, a, b}); } if (node[id].l == node[id].r) { return; } if (eval(node[id].a, node[id].b, l) > eval(a, b, l)) { update(l(id), a, b, changes); } else { update(r(id), a, b, changes); } } ll query(int id, ll x) { ll f = eval(node[id].a, node[id].b, x); if (node[id].l == node[id].r) { return f; } int q = node[id].l + node[id].r >> 1; if (x <= q) { return min(f, query(l(id), x)); } else { return min(f, query(r(id), x)); } } void build(int id, ll l, ll r) { node[id].l = l; node[id].r = r; node[id].a = 0; node[id].b = inf; if (l == r) { return; } int q = node[id].l + node[id].r >> 1; build(l(id), l, q); build(r(id), q + 1, r); } ll calc(ll lambda) { stack <pair <ll, ll>> st; for (int i = 0; i < n; ++i) { changes[i].clear(); } fill(ans, ans + M, 0); build(0, 0, n - 1); auto rollback = [&](ll i) { for (auto [id, a, b]: changes[i]) { node[id].a = a; node[id].b = b; } }; ll res = 0; for (int j = 0; j < n; ++j) { int i = xs[j]; if (j && i == xs[j - 1]) { continue; } while (!st.empty() && st.top().yy > lef[i]) { rollback(st.top().xx); st.pop(); } int p = st.empty()? 0: xs[st.top().xx]; int l = lef[i]; update(0, -2 * (l - 1), 1ll * (l - 1) * (l - 1) + ans[p] - 1ll * max(0, p - l + 1) * max(0, p - l + 1), changes[j]); st.push({j, lef[i]}); res = ans[i] = lambda + 1ll * i * i + query(0, j); } return res - k * lambda; } ll ternary_search(ll l, ll r) { if (l == r) { return calc(l); } ll d = (r - l) / 3; ll a = l + d; ll b = r - d; if (calc(a) > calc(b)) { return ternary_search(l, b - 1); } else { return ternary_search(a + 1, r); } } ll take_photos(int n_, int m_, int k_, std::vector<int> r, std::vector<int> c) { n = n_, m = m_, k = k_; for (int i = 1; i <= m; ++i) { lef[i] = i + 1; } for (int i = 0; i < n; ++i) { r[i]++, c[i]++; int x = max(r[i], c[i]); int y = min(r[i], c[i]); lef[x] = min(lef[x], y); xs[i] = x; } sort(xs, xs + n); ll res = ternary_search(0, 1ll * m * m); return res; }

Compilation message (stderr)

aliens.cpp:14:5: error: expected ',' or ';' before 'const'
   14 |     const ll M = 1e6 + 1;
      |     ^~~~~
aliens.cpp:17:22: error: 'M' was not declared in this scope
   17 |     int n, m, k, lef[M], xs[N];
      |                      ^
aliens.cpp:19:12: error: 'M' was not declared in this scope
   19 |     ll ans[M];
      |            ^
aliens.cpp: In function 'void update(int, int, ll, std::vector<Change>&)':
aliens.cpp:39:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |         int q = node[id].l + node[id].r >> 1;
      |                 ~~~~~~~~~~~^~~~~~~~~~~~
aliens.cpp: In function 'll query(int, ll)':
aliens.cpp:61:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |         int q = node[id].l + node[id].r >> 1;
      |                 ~~~~~~~~~~~^~~~~~~~~~~~
aliens.cpp: In function 'void build(int, ll, ll)':
aliens.cpp:77:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   77 |         int q = node[id].l + node[id].r >> 1;
      |                 ~~~~~~~~~~~^~~~~~~~~~~~
aliens.cpp: In function 'll calc(ll)':
aliens.cpp:87:14: error: 'ans' was not declared in this scope; did you mean 'abs'?
   87 |         fill(ans, ans + M, 0);
      |              ^~~
      |              abs
aliens.cpp:87:25: error: 'M' was not declared in this scope
   87 |         fill(ans, ans + M, 0);
      |                         ^
aliens.cpp: In lambda function:
aliens.cpp:91:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   91 |             for (auto [id, a, b]: changes[i]) {
      |                       ^
aliens.cpp: In function 'll calc(ll)':
aliens.cpp:102:49: error: 'lef' was not declared in this scope
  102 |             while (!st.empty() && st.top().yy > lef[i]) {
      |                                                 ^~~
aliens.cpp:107:21: error: 'lef' was not declared in this scope
  107 |             int l = lef[i];
      |                     ^~~
aliens.cpp:110:32: error: no matching function for call to 'std::stack<std::pair<long long int, long long int> >::push(<brace-enclosed initializer list>)'
  110 |             st.push({j, lef[i]});
      |                                ^
In file included from /usr/include/c++/10/stack:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:89,
                 from aliens.cpp:2:
/usr/include/c++/10/bits/stl_stack.h:239:7: note: candidate: 'void std::stack<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::deque<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; std::stack<_Tp, _Sequence>::value_type = std::pair<long long int, long long int>]'
  239 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_stack.h:239:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, long long int>&'}
  239 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_stack.h:244:7: note: candidate: 'void std::stack<_Tp, _Sequence>::push(std::stack<_Tp, _Sequence>::value_type&&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::deque<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; std::stack<_Tp, _Sequence>::value_type = std::pair<long long int, long long int>]'
  244 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_stack.h:244:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::stack<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
  244 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:134:13: error: 'lef' was not declared in this scope
  134 |             lef[i] = i + 1;
      |             ^~~
aliens.cpp:141:13: error: 'lef' was not declared in this scope
  141 |             lef[x] = min(lef[x], y);
      |             ^~~