#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;
vi a;
map<pii, int> need;
pair<ll, ll> val[MAX];
ll ans[MAX];
ll sum[MAX];
ll binom[2][MAX];
int use = 0;
int bef = 1;
int c = 0;
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;
}
inline ll choose(ll x, ll y){
return binom[use][y];
}
inline void update(){
c++;
use = 1-use;
bef = 1-bef;
f0r(i, c+1){
if(i == 0) binom[use][i] = 1;
else if(i == c) binom[use][i] = 1;
else {
binom[use][i] = binom[bef][i] + binom[bef][i-1];
if(binom[use][i]>= MOD) binom[use][i] -= MOD;
}
}
}
ll fin = 0;
void compute(){
binom[use][0] = 1;
f1r(i, 1, n+1){
ll ret = 0;
ll mx = val[i].f;
ll differ = val[i].s;
ll prod = 1;
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;
if(sum[i] >= MOD) sum[i] -= MOD;
ll toAdd = res*(differ-1);
toAdd %= MOD;
toAdd *= prod;
toAdd %= MOD;
fin += toAdd;
if(fin>= MOD) fin -= MOD;
prod *= mx;
prod %= MOD;
}
update();
}
}
int main(){
fast_io();
// cin >> n;
scanf("%d", &n);
f0r(i, n){
int ai;
//cin >> ai;
scanf("%d", &ai);
a.eb(ai);
}
int mx = 1;
f0r(i, n){
val[n-i] = mp(mx, a[i]);
mx = max(mx, a[i]);
}
compute();
printf("%d\n", fin+1);
//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 compute()':
teams.cpp:106:12: warning: unused variable 'ret' [-Wunused-variable]
ll ret = 0;
^~~
teams.cpp: In function 'int main()':
teams.cpp:146:25: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
printf("%d\n", fin+1);
~~~~~^
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);
~~~~~~~^~~~~~~~~~~~~~~~~~~
teams.cpp: In function 'int main()':
teams.cpp:133:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
teams.cpp:137:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &ai);
~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
380 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
380 KB |
Output is correct |
2 |
Correct |
8 ms |
376 KB |
Output is correct |
3 |
Correct |
8 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
586 ms |
956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
732 KB |
Output is correct |
2 |
Correct |
153 ms |
760 KB |
Output is correct |
3 |
Correct |
153 ms |
644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
606 ms |
1200 KB |
Output is correct |
2 |
Correct |
606 ms |
1004 KB |
Output is correct |
3 |
Correct |
607 ms |
1004 KB |
Output is correct |