Submission #45797216


Source Code Expand

// LUOGU_RID: 125601756
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 2010, MOD = 1e9 + 7;
int n, a[N], f[N][N];
inline void add(int &x, ll y) { x = (x + y) % MOD; }
struct BIT {
	int t[N];
	void Add(int x, int y) {
		x++;
		for (; x <= n + 2; x += x & -x) add(t[x], y);
	}
	int query(int x) {
		x++;
		int s = 0;
		for (; x; x -= x & -x) add(s, t[x]);
		return s;
	}
	int query(int l, int r) {
		return (query(r) - query(l - 1) + MOD) % MOD;
	}
} A[N], b[N], c[N];
int inv[N];
inline void binom(int x) {
	inv[1] = 1;
	F(i, 2, x) inv[i] = (ll) (MOD - MOD / i) * inv[MOD % i] % MOD;
}
signed main() {
	read(n);
	binom(n);
	F(i, 1, n) read(a[i]);
	F(i, 0, n + 1)
		F(j, 0, i)
			A[j].Add(a[i], 1);
	a[n + 1] = n + 1;
	F(len, 3, n + 2)
		for (int i = 0, j = len - 1; j <= n + 1; i++, j++) {
			if (a[i] > a[j]) continue;
			int g = A[i + 1].query(a[i], a[j]) - A[j].query(a[i], a[j]);
			if (g) f[i][j] = ((ll) (b[i].query(a[i], a[j]) + c[j].query(a[i], a[j])) * inv[g] + 1) % MOD;
			// debug << i << " " << j << " " << f[i][j] << " " << g << endl;
			b[i].Add(a[j], f[i][j]);
			c[j].Add(a[i], f[i][j]);
		}
	cout << f[0][n + 1];
	return 0;
}

Submission Info

Submission Time
Task E - Random IS
User ast123
Language C++ 17 (gcc 12.2)
Score 700
Code Size 1835 Byte
Status AC
Exec Time 575 ms
Memory 62592 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 42
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
random_01.txt AC 575 ms 62504 KiB
random_02.txt AC 61 ms 42964 KiB
random_03.txt AC 1 ms 3720 KiB
random_04.txt AC 570 ms 62592 KiB
random_05.txt AC 380 ms 62404 KiB
random_06.txt AC 383 ms 62448 KiB
random_07.txt AC 390 ms 62584 KiB
random_08.txt AC 360 ms 62540 KiB
random_09.txt AC 379 ms 62428 KiB
random_10.txt AC 360 ms 62352 KiB
random_11.txt AC 285 ms 55788 KiB
random_12.txt AC 331 ms 61224 KiB
random_13.txt AC 306 ms 57140 KiB
random_14.txt AC 46 ms 23436 KiB
random_15.txt AC 32 ms 19448 KiB
random_16.txt AC 42 ms 21876 KiB
random_17.txt AC 145 ms 41724 KiB
random_18.txt AC 218 ms 50176 KiB
random_19.txt AC 57 ms 26024 KiB
random_20.txt AC 10 ms 10716 KiB
random_21.txt AC 1 ms 3600 KiB
random_22.txt AC 1 ms 3536 KiB
random_23.txt AC 1 ms 3672 KiB
random_24.txt AC 1 ms 3536 KiB
random_25.txt AC 1 ms 3528 KiB
random_26.txt AC 1 ms 3636 KiB
random_27.txt AC 1 ms 3664 KiB
random_28.txt AC 1 ms 3536 KiB
random_29.txt AC 1 ms 3596 KiB
random_30.txt AC 1 ms 3520 KiB
random_31.txt AC 1 ms 3612 KiB
random_32.txt AC 1 ms 3680 KiB
random_33.txt AC 1 ms 3656 KiB
random_34.txt AC 1 ms 3584 KiB
random_35.txt AC 1 ms 3668 KiB
random_36.txt AC 1 ms 3556 KiB
random_37.txt AC 1 ms 3696 KiB
random_38.txt AC 1 ms 3588 KiB
random_39.txt AC 1 ms 3624 KiB
random_40.txt AC 1 ms 3488 KiB
sample_01.txt AC 1 ms 3680 KiB
sample_02.txt AC 1 ms 4168 KiB