#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const double PI = 4 * atan(1);
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void io(string taskname){
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
fast_io();
}
const int MAX = 1e4 + 5;
const ll MOD = 1e6 + 7;
ll fact[MAX];
ll inv[MAX];
vi a;
map<pii, int> need;
pair<ll, ll> val[MAX];
ll ans[MAX];
ll sum[MAX];
vector<ll> bin1;
vector<ll> bin2;
int n;
long long modInverse(long long b){
long long ex = MOD - 2;
if (b==1){
return 1;
}
long long r = 1;
while (ex ){
if (ex&1){
r=(r * b)%MOD;
}
ex = ex >> 1;
b = (b * b)%MOD;
}
return r;
}
ll choose(ll x, ll y){
return bin1[y];
}
void update(){
bin2.eb(1);
f0r(i, sz(bin1) - 1){
ll ret = bin1[i] + bin1[i+1];
ret%= MOD;
bin2.eb(ret);
}
bin2.eb(1);
bin1.clear();
for(auto x: bin2) bin1.eb(x);
bin2.clear();
}
void compute(){
f1r(i, 1, n+1){
vi cur;
cur.eb(0);
if(i == 1) bin1.eb(1);
if(i == 1){
f1r(j, 1, i+1){
ll res = 0;
if(i == 1){
res = 1;
}
if(i == j) res = 1;
sum[i] += res;
sum[i] %= MOD;
cur.eb(res);
}
//continue;
}
else{
f1r(j, 1, i+1){
ll res = choose(i-1, j-1);
res *= sum[i-j];
res %= MOD;
if(i == j) res = 1;
sum[i] += res;
sum[i] %= MOD;
cur.eb(res);
}
}
ll ret = 0;
ll mx = val[i].f;
ll differ = val[i].s;
ll prod = 1;
f1r(it, 1, sz(cur)){
ll toAdd = cur[it]*(differ-1);
toAdd %= MOD;
toAdd *= prod;
toAdd %= MOD;
ret += toAdd;
ret %= MOD;
prod *= mx;
prod %= MOD;
}
ans[i] = ret;
///cout << cur << endl;
update();
}
}
int main(){
fast_io();
cin >> n;
f0r(i, n){
int ai;
cin >> ai;
a.eb(ai);
}
f0r(i, n){
if(i == 0) fact[i] = 1;
else{
fact[i] = fact[i-1]*i;
fact[i] %= MOD;
}
}
f0r(i, n){
inv[i] = modInverse(fact[i]);
}
int mx = 1;
f0r(i, n){
val[n-i] = mp(mx, a[i]);
// cout << n -i << " " << mx << " " << a[i] << endl;
mx = max(mx, a[i]);
}
compute();
ll fin = 0;
f1r(i, 1, n+1){
fin += ans[i];
//cout << i << " answers " << ans[i] << endl;
fin %= MOD;
}
cout << fin +1<< endl;
return 0;
}
Compilation message
teams.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
teams.cpp: In function 'void io(std::__cxx11::string)':
teams.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FIN, "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~
teams.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FOUT, "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
420 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
504 KB |
Output is correct |
2 |
Correct |
14 ms |
376 KB |
Output is correct |
3 |
Correct |
15 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1032 ms |
1588 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
282 ms |
924 KB |
Output is correct |
2 |
Correct |
283 ms |
908 KB |
Output is correct |
3 |
Correct |
281 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1047 ms |
1296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |