#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#define I inline void
#define S struct
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1000 + 7, mod = 1e6 + 7;
const ll inf = 2e18;
// How interesting!
int n;
int a[N];
int Max;
int c[N][N];
int bit[N];
void add(int x)
{
for (; x < N; x += x & -x)
bit[x]++;
}
int get(int x)
{
int ret = 0;
for (; x; x -= x & -x)
ret += bit[x];
return ret;
}
int mul(int x, int y) { return 1ll * x * y % mod; }
int add(int x, int y) { return (x + y) >= mod ? x + y - mod : x + y; }
void nSr()
{
c[0][0] = 1;
for (int i = 1; i < N; ++i)
{
for (int j = 0; j <= i; ++j)
{
if (i == j || !j)
c[i][j] = 1;
else
c[i][j] = add(c[i - 1][j - 1], mul(j, c[i - 1][j]));
}
}
}
int solve(int x, int y)
{
return c[x][y];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("in.in", "r", stdin);
nSr();
cin >> n;
int ans = 0;
for (int i = 0; i < n; ++i)
{
int x;
cin >> x;
if (++a[x] == 1)
add(x);
int sum = 0;
for (int j = 1; j < x; ++j)
{
ans += solve(n - i - 1, max(j, Max));
ans %= mod;
}
Max = max(Max, x);
}
cout << add(ans, 1);
return 0;
}
/*
- bounds sir (segtree = 4N, eulerTour = 2N, ...)
- a variable defined twice?
- will overflow?
- is it a good complexity?
- don't mess up indices (0-indexed vs 1-indexed)
- reset everything between testcases.
*/
Compilation message
teams.cpp: In function 'int main()':
teams.cpp:81:21: warning: unused variable 'sum' [-Wunused-variable]
81 | int sum = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4352 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4352 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4352 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4352 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4352 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
8576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
8576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
8576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |