Submission #1126592

#TimeUsernameProblemLanguageResultExecution timeMemory
1126592VinhLuuDistributing Candies (IOI21_candies)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> //#define ll long long #define ll long long #define all(lpv) lpv.begin(), lpv.end() #define pot(x, y) lower_bound(x.begin(), x.end(), y) - x.begin() + 1 using namespace std; //#define lpv #ifndef lpv #include "candies.h" #endif // lpv typedef pair<ll,ll> pii; const ll N = 2e5 + 5; ll n, q, h[N], a[N], L[N], R[N], C[N], mi[N << 2], mx[N << 2], lz[N << 2], st[N << 2]; vector<ll> open[N], close[N]; void update(ll i,ll l,ll r,ll u,ll x) { if(l > r || r < u || u < l) return; if(l == r) { st[i] = x; mx[i] = max(0ll, x); mi[i] = min(0ll, x); return; } ll mid = (l + r) / 2; update(i << 1, l, mid, u, x); update(i << 1|1, mid + 1, r, u, x); mi[i] = min(mi[i << 1], st[i << 1] + mi[i << 1|1]); mx[i] = max(mx[i << 1], st[i << 1] + mx[i << 1|1]); st[i] = st[i << 1] + st[i << 1|1]; } ll query(ll i,ll l,ll r,ll c) { if(l == r) return min(max(0ll, st[i]), c); ll mid = (l + r) / 2; if(mx[i << 1|1] - mi[i << 1|1] > c) return query(i << 1|1, mid + 1, r, c); ll ret = query(i << 1, l, mid, c); if(ret + mx[i << 1|1] > c) return c - (mx[i << 1|1] - st[i << 1|1]); if(ret + mi[i << 1|1] < 0) return st[i << 1|1] - mi[i << 1|1]; return ret + st[i << 1|1]; } std::vector<ll> distribute_candies(std::vector<ll> _c, std::vector<ll> _l, std::vector<ll> _r, std::vector<ll> _v) { n = _c.size(); for(ll i = 1; i <= n; i ++) a[i] = _c[i - 1]; q = (ll)_l.size(); for(ll i = 1; i <= q; i ++) L[i] = _l[i - 1] + 1, R[i] = _r[i - 1] + 1, C[i] = _v[i - 1]; vector<ll> kq; for(ll i = 1; i <= q; i ++) { open[L[i]].push_back(i); close[R[i] + 1].push_back(i); } for(ll i = 1; i <= n; i ++) { for(auto j : open[i]) { update(1, 1, q, j, C[j]); } for(auto j : close[i]) { update(1, 1, q, j, 0); } kq.push_back({query(1, 1, q, a[i])}); } return kq; } #ifdef lpv signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")) { freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } ll _n; cin >> _n; std::vector<ll> _c(_n); for(ll i = 0; i < _n; ++i) { cin >> _c[i]; } ll _q; cin >> _q; std::vector<ll> _l(_q), _r(_q), _v(_q); for(ll i = 0; i < _q; i ++) { cin >> _l[i] >> _r[i] >> _v[i]; } std::vector<ll> _ans = distribute_candies(_c, _l, _r, _v); for(auto j : _ans) cout << j << " "; } #endif // lpv

Compilation message (stderr)

candies.cpp:18:28: error: 'std::vector<long long int> close [200005]' redeclared as different kind of entity
   18 | vector<ll> open[N], close[N];
      |                            ^
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/11/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:43,
                 from candies.cpp:1:
/usr/include/unistd.h:358:12: note: previous declaration 'int close(int)'
  358 | extern int close (int __fd);
      |            ^~~~~
candies.cpp: In function 'std::vector<long long int> distribute_candies(std::vector<long long int>, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)':
candies.cpp:61:19: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |     close[R[i] + 1].push_back(i);
      |                   ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
candies.cpp:61:21: error: request for member 'push_back' in '*(close + (((sizetype)R[i]) + 1))', which is of non-class type 'int(int)'
   61 |     close[R[i] + 1].push_back(i);
      |                     ^~~~~~~~~
candies.cpp:68:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   68 |     for(auto j : close[i]) {
      |                         ^
candies.cpp:68:25: error: 'begin' was not declared in this scope
candies.cpp:68:25: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95,
                 from candies.cpp:1:
/usr/include/c++/11/valarray:1228:5: note:   'std::begin'
 1228 |     begin(const valarray<_Tp>& __va) noexcept
      |     ^~~~~
In file included from /usr/include/c++/11/string_view:48,
                 from /usr/include/c++/11/bits/basic_string.h:48,
                 from /usr/include/c++/11/string:55,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from candies.cpp:1:
/usr/include/c++/11/bits/ranges_base.h:561:44: note:   'std::ranges::__cust::begin'
  561 |     inline constexpr __cust_access::_Begin begin{};
      |                                            ^~~~~
In file included from /usr/include/c++/11/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:129,
                 from candies.cpp:1:
/usr/include/c++/11/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
In file included from /usr/include/c++/11/bits/stl_iterator_base_types.h:71,
                 from /usr/include/c++/11/bits/stl_algobase.h:65,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from candies.cpp:1:
/usr/include/c++/11/bits/iterator_concepts.h:949:10: note:   'std::ranges::__cust_access::begin'
  949 |     void begin(const auto&) = delete;
      |          ^~~~~
candies.cpp:68:25: error: 'end' was not declared in this scope
   68 |     for(auto j : close[i]) {
      |                         ^
candies.cpp:68:25: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95,
                 from candies.cpp:1:
/usr/include/c++/11/valarray:1255:5: note:   'std::end'
 1255 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
In file included from /usr/include/c++/11/string_view:48,
                 from /usr/include/c++/11/bits/basic_string.h:48,
                 from /usr/include/c++/11/string:55,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from candies.cpp:1:
/usr/include/c++/11/bits/ranges_base.h:562:42: note:   'std::ranges::__cust::end'
  562 |     inline constexpr __cust_access::_End end{};
      |                                          ^~~
In file included from /usr/include/c++/11/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:129,
                 from candies.cpp:1:
/usr/include/c++/11/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
In file included from /usr/include/c++/11/string_view:48,
                 from /usr/include/c++/11/bits/basic_string.h:48,
                 from /usr/include/c++/11/string:55,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from candies.cpp:1:
/usr/include/c++/11/bits/ranges_base.h:136:10: note:   'std::ranges::__cust_access::end'
  136 |     void end(const auto&) = delete;
      |          ^~~