# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
919913 | CyberCow | Fancy Fence (CEOI20_fancyfence) | C++17 | 28 ms | 5584 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((x).size())
typedef long long ll;
using namespace std;
mt19937 rnd(348502);
const ll N = 2010;
ll mod = 1e9 + 7;
void solve()
{
ll x, y, a, b;
int i, n;
cin >> n;
vector<pair<ll, ll>> v;
for ( i = 0; i < n; i++)
{
cin >> x;
v.push_back({ x, 0 });
}
for ( i = 0; i < n; i++)
{
cin >> x;
v[i].second = x;
}
ll qan = 0, ans = 0;
stack<pair<ll, ll>> s;
for ( i = 0; i < n; i++)
{
ll ne = 0;
ans = (ans + (v[i].first * (v[i].first - 1) / 2 + v[i].first) % mod * ((v[i].second * (v[i].second - 1) / 2 + v[i].second) % mod) % mod) % mod;
while (!s.empty() && s.top().first > v[i].first)
{
qan = (mod + (qan - (s.top().first * (s.top().first - 1) / 2+ s.top().first) % mod * s.top().second % mod) % mod) % mod;
qan = (qan + (v[i].first * (v[i].first - 1) / 2 + v[i].first) % mod * s.top().second) % mod;
ne = (ne + s.top().second) % mod;
s.pop();
}
ans = (ans + qan * v[i].second) % mod;
qan = (qan + (v[i].first * (v[i].first - 1) / 2 + v[i].first) % mod * v[i].second % mod) % mod;
s.push({ v[i].first, (ne + v[i].second) % mod });
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll tt = 1;
//cout << (mod + -10000010 % mod) % mod;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |