Submission #515051

#TimeUsernameProblemLanguageResultExecution timeMemory
515051Killer2501Fancy Fence (CEOI20_fancyfence)C++14
100 / 100
47 ms6724 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second using namespace std; const int N = 2e5+5; const int M = 26; const ll inf = 1e15; const ll mod = 1e9+7; const ld ex = 1e-9; int n, t, k, m, d[N], lab[N]; ll ans, tong, a[N], b[N], c[N], l[N], r[N], cnt; string s; struct node { int x, y, val; int vx, vy; node(){} node(int _x, int _vx, int _y, int _vy) { x = _x; vx = _vx; y = _y; vy = _vy; } }; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n&1)total = total * k % mod; k = k * k % mod; } return total; } ll C(ll u, ll v) { if(u > v)return 0; return a[v] * b[u] % mod * b[v-u] % mod; } void add(ll& x, ll y) { x += y; if(x >= mod)x -= mod; } vector<int> vi; void sol() { cin >> n; for(int i = 1; i <= n; i ++)cin >> a[i]; for(int i = 1; i <= n; i ++) { cin >> c[i]; b[i] = b[i-1] + c[i]; } for(int i = 1; i <= n; i ++) { while(!vi.empty() && a[vi.back()] > a[i])vi.pop_back(); l[i] = vi.empty() ? 0 : vi.back(); vi.pb(i); } vi.clear(); for(int i = n; i > 0; i --) { while(!vi.empty() && a[vi.back()] >= a[i])vi.pop_back(); r[i] = vi.empty() ? n+1 : vi.back(); vi.pb(i); } for(int i = 1; i <= n; i ++) { tong = ((b[r[i]-1]-b[i])%mod*((b[i]-b[l[i]])%mod)%mod+c[i]*(c[i]+1)/2%mod+(b[i-1]-b[l[i]])%mod*c[i]%mod) % mod; cnt = a[i] * (a[i]+1) % mod * pw(2, mod-2) % mod; //cout << cnt <<" "; ans = (ans + cnt * tong % mod) % mod; //cout << cnt <<" "<<tong << '\n'; } cout << ans; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* */

Compilation message (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:93:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:94:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...