# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
667555 | 2022-12-01T17:17:47 Z | mychecksedad | Fancy Fence (CEOI20_fancyfence) | C++17 | 3 ms | 340 KB |
/* Author : Mychecksdead */ #include<bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef long double ld; #define MOD (1000000000+7) #define MOD1 (998244353) #define PI 3.1415926535 #define pb push_back #define setp() cout << setprecision(15) #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " is " << x << '\n'; const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20; int n, ls[N], rs[N]; ll w[N], h[N], pref[N]; ll comb2(ll x){ return (x*(x+1)/2) % MOD; } ll p(int l, int r){ if(l > 0) return pref[r] - pref[l - 1]; return pref[r]; } void solve(){ cin >> n; for(int i = 0; i < n; ++i) cin >> h[i]; for(int i = 0; i < n; ++i) cin >> w[i]; pref[0] = w[0]; for(int i = 1; i < n; ++i) pref[i] = (pref[i - 1] + w[i]) % MOD; deque<pair<int, int>> q; ls[0] = -1; q.pb({h[0], 0}); for(int i = 1; i < n; ++i){ while(!q.empty() && q.back().first >= h[i]) q.pop_back(); if(!q.empty()) ls[i] = q.back().second; else ls[i] = -1; q.pb({h[i], i}); } q.clear(); rs[n - 1] = n; q.pb({h[n - 1], n - 1}); for(int i = n - 2; i >= 0; --i){ while(!q.empty() && q.back().first > h[i]) q.pop_back(); if(!q.empty()) rs[i] = q.back().second; else rs[i] = n; q.pb({h[i], i}); } ll ans = 0; for(int i = 0; i < n; ++i){ ll a = (p(ls[i] + 1, i) * p(i, rs[i] - 1) % MOD); (ans += (a - comb2(w[i] - 1)) * comb2(h[i])) %= MOD; } cout << (ans + MOD) % MOD; } int main(){ cin.tie(0); ios::sync_with_stdio(0); freopen("in.txt", "r", stdin); int T = 1, aa; // cin >> T;aa=T; while(T--){ // cout << "Case #" << aa-T << ": "; solve(); cout << '\n'; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |