Untitled
#include <iostream> #include <stdio.h> #include <fstream> #include <time.h> #include <algorithm> #include <vector> #include <queue> #include <string.h> #include <assert.h> #include <map> #include <math.h> #include <functional> #include <set> #include <unordered_map> #include <numeric> #include <cstdlib> #include <iomanip> #include <bitset> #include <complex> #include <list> #include <stack> #include <deque> #include <chrono> #include <unordered_set> using namespace std; #define Chris "test" #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define FORD(i, a, b) for(int i = (a); i <= (b); ++i) #define REP(i, a, b) for(int i = (a); i > (b); --i) #define REPD(i, a, b) for(int i = (a); i >= (b); --i) #define FORE(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define MARK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define fi first #define se second #define MIN(x,y) if (x > (y)) x = (y) #define MAX(x,y) if (x < (y)) x = (y) #define mp make_pair #define mem(v, a) memset((v), (a), sizeof((v))) #define MINE(v) *min_element(All(v)) #define MAXE(v) *max_element(All(v)) #define el "\n" #define mu2(a) (1 << ((a))) #define bitcount(a) __builtin_popcountll(a) #define Chris_ signed main() #define faster ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define showTime() cerr << '\n' << "Running time: " << (1.0 * clock() / CLOCKS_PER_SEC) << "s\n"; #define file(Chris) if(fopen(Chris".inp", "r")){freopen(Chris".inp", "r", stdin);freopen(Chris".out", "w", stdout);} typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vii; typedef set<int> sii; typedef map<int, int> mii; typedef stack<int> sti; typedef deque<int> dqi; typedef queue<int> quei; typedef unordered_map<int, int> umii; typedef unordered_set<int, int> umsii; const ll mod = 1e9 + 7; const int inf = (int) 1e5 + 5; const int base = (int) 131; const ll m2 = 1LL * mod * mod; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll n, a[inf], b[inf], dp[inf], dp1[inf]; void nhap() { cin >> n; } void solve() { nhap(); FORD(i, 1, n) { cin >> a[i]; } FOR(i, 1, n) { cin >> b[i]; } dp[0] = 1; dp1[1] = a[1]; dp[1] = a[1] + b[1]; FORD(i, 2, n) { dp1[i] = (dp[i - 2] * (1LL * b[i - 1] * (b[i - 1] - 1) % mod) % mod + dp1[i - 1] * b[i - 1] % mod + dp[i - 1] * a[i] % mod) % mod; dp[i] = (dp[i - 1] * b[i] % mod + dp1[i]) % mod; } cout << dp[n]; } Chris_ { faster file(Chris) solve(); showTime(); return 0; }
Leave a Comment