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 <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e4+100,mod=1000007;
ll a[N];
ll dp[N];
ll ma[N];
int32_t main(){
sync;
ll n;
cin >> n ;
for (int i=1;i<=n;i++){
cin >> a[i];
ma[i]=max(ma[i-1],a[i]);
}
for (int i=0;i<N;i++) dp[i]=i+1;
ll ans=a[n];
for (int i=n-1;i>1;i--){
ll z=ma[i-1];
ans+=dp[z]*(a[i]-1)%mod;
ans%=mod;
for (int j=1;j<N;j++){
dp[j]=j*dp[j]%mod;
if (j!=N-1) dp[j]+=dp[j+1];
dp[j]%=mod;
}
}
cout << ans << endl;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |