#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];
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 bin1[y];
}
inline void update(){
bin2.eb(1);
f0r(i, sz(bin1) - 1){
ll ret = bin1[i] + bin1[i+1];
if(ret>= MOD) ret-=MOD;
//ret%= MOD;
bin2.eb(ret);
}
bin2.eb(1);
bin1.clear();
for(auto x: bin2) bin1.eb(x);
bin2.clear();
}
ll fin = 0;
void compute(){
f1r(i, 1, n+1){
ll ret = 0;
ll mx = val[i].f;
ll differ = val[i].s;
ll prod = 1;
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;
if(sum[i]>= MOD) sum[i] -= MOD;
ll toAdd = res*(differ-1);
toAdd %= MOD;
toAdd *= prod;
toAdd %= MOD;
// ret += toAdd;
fin += toAdd;
if(fin>= MOD) fin -= MOD;
prod *= mx;
prod %= MOD;
}
//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;
if(sum[i] >= MOD) sum[i] -= MOD;
ll toAdd = res*(differ-1);
toAdd %= MOD;
toAdd *= prod;
toAdd %= MOD;
// ret += toAdd;
fin += toAdd;
if(fin>= MOD) fin -= MOD;
prod *= mx;
prod %= MOD;
}
}
///cout << cur << endl;
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:101:12: warning: unused variable 'ret' [-Wunused-variable]
ll ret = 0;
^~~
teams.cpp: In function 'int main()':
teams.cpp:168: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:155:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
teams.cpp:159: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 |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
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 |
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 |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
376 KB |
Output is correct |
2 |
Correct |
17 ms |
376 KB |
Output is correct |
3 |
Correct |
17 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1012 ms |
976 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
369 ms |
772 KB |
Output is correct |
2 |
Correct |
369 ms |
760 KB |
Output is correct |
3 |
Correct |
374 ms |
728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1054 ms |
1116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |