Submission #710110

#TimeUsernameProblemLanguageResultExecution timeMemory
710110Spade1Fancy Fence (CEOI20_fancyfence)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> //#include "grader.h" #define pii pair<int, int> #define pll pair<long long, long long> #define ll long long #define ld long double #define st first #define nd second #define pb push_back #define INF INT_MAX using namespace std; const int N = 1e5 + 10; const int M = 1e9+7; ll h[N], w[N]; stack<pii> s; ll ans; ll add(ll a, ll b) {return ((((a%M)+(b%M))%M)+M)%M;} ll mul(ll a, ll b) {return (a%M*b%M)%M;} ll power(ll a, ll b) { if (b==0) return 1; ll ret = power(a, b/2); if (b&1) return mul(ret, mul(ret, a)); else return mul(ret, ret); } void solve() { int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> h[i]; for (int i = 1; i <= n; ++i) cin >> w[i]; s.push({0, 0}); ll inv = power(2, M-2); for (int i = 1; i <= n; ++i) { while (s.top().st > h[i]) { auto [H, W] = s.top(); s.pop(); if (s.top().st > h[i]) { H -= s.top().st; auto [HH, WW] = s.top(); s.pop(); s.push({HH, add(WW, W)}); ans = add(ans, mul(mul(H, s.top().st), mul(mul(W, W+1), inv))); } else { H -= h[i]; s.push({h[i], W}); ans = add(ans, mul(mul(H, h[i]), mul(mul(W, W+1), inv))); } ans = add(ans, mul(mul(mul(H, H+1), inv), mul(mul(W, W+1), inv))); } if (s.top().st == h[i]) { auto [HH, WW] = s.top(); s.pop(); s.push({HH, add(WW, w[i])}); } else s.push({h[i], w[i]}); } while (s.size() > 1) { auto [H, W] = s.top(); s.pop(); H -= s.top().st; auto [HH, WW] = s.top(); s.pop(); s.push({HH, add(WW + W)}); ans = add(ans, mul(mul(H, s.top().st), mul(mul(W, W+1), inv))); ans = add(ans, mul(mul(mul(H, H+1), inv), mul(mul(W, W+1), inv))); } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }

Compilation message (stderr)

fancyfence.cpp: In function 'void solve()':
fancyfence.cpp:40:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |             auto [H, W] = s.top(); s.pop();
      |                  ^
fancyfence.cpp:43:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |                 auto [HH, WW] = s.top(); s.pop();
      |                      ^
fancyfence.cpp:55:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   55 |             auto [HH, WW] = s.top(); s.pop();
      |                  ^
fancyfence.cpp:62:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   62 |         auto [H, W] = s.top(); s.pop();
      |              ^
fancyfence.cpp:64:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   64 |         auto [HH, WW] = s.top(); s.pop();
      |              ^
fancyfence.cpp:65:31: error: too few arguments to function 'long long int add(long long int, long long int)'
   65 |         s.push({HH, add(WW + W)});
      |                               ^
fancyfence.cpp:21:4: note: declared here
   21 | ll add(ll a, ll b) {return ((((a%M)+(b%M))%M)+M)%M;}
      |    ^~~
fancyfence.cpp:65:33: error: no matching function for call to 'std::stack<std::pair<int, int> >::push(<brace-enclosed initializer list>)'
   65 |         s.push({HH, add(WW + W)});
      |                                 ^
In file included from /usr/include/c++/10/stack:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:89,
                 from fancyfence.cpp:1:
/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<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::stack<_Tp, _Sequence>::value_type = std::pair<int, 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<int, 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<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::stack<_Tp, _Sequence>::value_type = std::pair<int, 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<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  244 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~