Submission #919913

#TimeUsernameProblemLanguageResultExecution timeMemory
919913CyberCowFancy Fence (CEOI20_fancyfence)C++17
100 / 100
28 ms5584 KiB
#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)

fancyfence.cpp: In function 'void solve()':
fancyfence.cpp:31:11: warning: unused variable 'y' [-Wunused-variable]
   31 |     ll x, y, a, b;
      |           ^
fancyfence.cpp:31:14: warning: unused variable 'a' [-Wunused-variable]
   31 |     ll x, y, a, b;
      |              ^
fancyfence.cpp:31:17: warning: unused variable 'b' [-Wunused-variable]
   31 |     ll x, y, a, b;
      |                 ^
#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...