Submission #49802680
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
template <typename T> inline void O(const T &x) { cout << x << '\n'; }
template <typename T, typename... W> inline void O(const T &x, const W &...b) {
cout << x << ' ';
O(b...);
}
template <typename T> inline void rd(T &x) { cin >> x; }
template <typename T, typename... W> inline void rd(T &x, W &...b) {
cin >> x;
rd(b...);
}
#ifndef MISAKA
#define err(...)
#else
#define err(...) fprintf(stderr, __VA_ARGS__)
#endif
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef long double dbl;
typedef pair<int, int> pii;
typedef uniform_int_distribution<int> r32;
typedef uniform_int_distribution<i64> r64;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define shuf(L, R) shuffle((L), (R), rng)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define FOR(i, j, k) for (int i = (j); i <= (k); ++i)
#define ROF(i, j, k) for (int i = (k); i >= (j); --i)
template <typename T> inline void ckmin(T &a, const T &b) { a = min(a, b); }
template <typename T> inline void ckmax(T &a, const T &b) { a = max(a, b); }
//#define IOFILE "filename"
//#define MULTI
const int N = 1e5+5;
int a[N];
int p[N][11], q[N][11];
int r[N];
inline void sol() {
int n;
rd(n);
for (int i = 1; i <= n; ++i) r[i] = n+1;
for (int j = 1; j <= n; ++j) for (int i = 1; i < 11; ++i) q[j][i] = n+1;
for (int i = 1; i <= n; ++i) {
rd(a[i]);
p[i][a[i]] = q[i][a[i]] = i;
}
for (int i = 2; i <= n; ++i) for (int j = 1; j < 11; ++j) ckmax(p[i][j], p[i-1][j]);
for (int i = n-1; i > 0; --i) for (int j = 1; j < 11; ++j) ckmin(q[i][j], q[i+1][j]);
for (int i = 2; i < n; ++i) for (int j = 1; j < 11; ++j) {
int k = 2*a[i]-j;
if (k < 1 || k > 10) continue;
ckmin(r[p[i-1][j]], q[i+1][k]);
}
for (int i = n-1; i > 0; --i) ckmin(r[i], r[i+1]);
i64 ans = 0;
for (int i = 1; i <= n; ++i) ans += n+1-r[i];
O(ans);
}
int main() {
#ifndef MISAKA
#ifdef IOFILE
freopen(IOFILE ".in", "r", stdin);
freopen(IOFILE ".out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
#endif
#ifdef MULTI
int T;
cin >> T;
while (T--)
#endif
sol();
return 0;
}
Submission Info
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All |
00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_01.txt |
AC |
1 ms |
3500 KiB |
| 00_sample_02.txt |
AC |
1 ms |
3532 KiB |
| 00_sample_03.txt |
AC |
1 ms |
3660 KiB |
| 01_test_01.txt |
AC |
1 ms |
3536 KiB |
| 01_test_02.txt |
AC |
1 ms |
3556 KiB |
| 01_test_03.txt |
AC |
8 ms |
10844 KiB |
| 01_test_04.txt |
AC |
8 ms |
12148 KiB |
| 01_test_05.txt |
AC |
5 ms |
8836 KiB |
| 01_test_06.txt |
AC |
9 ms |
12644 KiB |
| 01_test_07.txt |
AC |
9 ms |
12856 KiB |
| 01_test_08.txt |
AC |
9 ms |
12920 KiB |
| 01_test_09.txt |
AC |
8 ms |
12904 KiB |
| 01_test_10.txt |
AC |
9 ms |
12912 KiB |
| 01_test_11.txt |
AC |
9 ms |
12988 KiB |
| 01_test_12.txt |
AC |
9 ms |
12924 KiB |
| 01_test_13.txt |
AC |
9 ms |
13028 KiB |
| 01_test_14.txt |
AC |
9 ms |
12876 KiB |
| 01_test_15.txt |
AC |
9 ms |
12916 KiB |
| 02_handmade_01.txt |
AC |
8 ms |
12912 KiB |
| 02_handmade_02.txt |
AC |
8 ms |
12860 KiB |
| 02_handmade_03.txt |
AC |
8 ms |
12880 KiB |
| 02_handmade_04.txt |
AC |
8 ms |
12896 KiB |
| 02_handmade_05.txt |
AC |
8 ms |
12876 KiB |
| 02_handmade_06.txt |
AC |
8 ms |
12896 KiB |
| 02_handmade_07.txt |
AC |
8 ms |
12904 KiB |
| 02_handmade_08.txt |
AC |
8 ms |
12872 KiB |