#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<int, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using llf = long double;
const int mod = 1e6 + 3; // 1e9 + 7;//993244853;
// I don't remember the credit of modint, but it's not mine.
// I don't remember the credit of FFT, but it's probably mine.
// Polynomial library is due to adamant:
// https://github.com/cp-algorithms/cp-algorithms-aux/blob/master/src/polynomial.cpp
// To use polynomial sqrt, need to amend sqrt for modint.
struct mint {
int val;
mint() { val = 0; }
mint(const lint &v) {
val = (-mod <= v && v < mod) ? v : v % mod;
if (val < 0)
val += mod;
}
friend ostream &operator<<(ostream &os, const mint &a) { return os << a.val; }
friend bool operator==(const mint &a, const mint &b) { return a.val == b.val; }
friend bool operator!=(const mint &a, const mint &b) { return !(a == b); }
friend bool operator<(const mint &a, const mint &b) { return a.val < b.val; }
mint operator-() const { return mint(-val); }
mint &operator+=(const mint &m) {
if ((val += m.val) >= mod)
val -= mod;
return *this;
}
mint &operator-=(const mint &m) {
if ((val -= m.val) < 0)
val += mod;
return *this;
}
mint &operator*=(const mint &m) {
val = (lint)val * m.val % mod;
return *this;
}
friend mint ipow(mint a, lint p) {
mint ans = 1;
for (; p; p /= 2, a *= a)
if (p & 1)
ans *= a;
return ans;
}
mint inv() const { return ipow(*this, mod - 2); }
mint &operator/=(const mint &m) { return (*this) *= m.inv(); }
friend mint operator+(mint a, const mint &b) { return a += b; }
friend mint operator-(mint a, const mint &b) { return a -= b; }
friend mint operator*(mint a, const mint &b) { return a *= b; }
friend mint operator/(mint a, const mint &b) { return a /= b; }
operator int64_t() const { return val; }
};
mint bino(int n, int k) {
mint up = 1, dn = 1;
for (int i = 0; i < k; i++) {
up *= mint(n - i);
dn *= mint(i + 1);
}
return up / dn;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
lint tot = 0;
for (int i = 1; i < 100; i++) {
int l = 0, r = n;
while (l < n && a[l] <= i)
l++;
while (r > l && a[r - 1] <= i)
r--;
vector<int> pos;
vector<pi> mswp;
int mx = 1e9;
for (int j = l; j < r; j++) {
if (a[j] <= i) {
pos.push_back(j);
mswp.push_back({mx, 0});
} else
mx = min(mx, a[j]);
}
if (sz(pos) == 0)
continue;
int ptr = sz(pos);
mx = 1e9;
for (int j = r - 1; j >= l; j--) {
if (a[j] <= i) {
mswp[--ptr][1] = mx;
} else
mx = min(mx, a[j]);
}
vector<int> lsave(sz(pos)), rsave(sz(pos));
if (sz(pos) == 1) {
tot += mswp[0][0] + mswp[0][1] + i;
continue;
}
for (int j = 0; j < sz(pos); j++) {
if (j == 0)
tot += mswp[j][0];
else
tot += i + 1;
tot += i;
if (j == sz(pos) - 1)
tot += mswp[j][1];
else
tot += i + 1;
}
tot += min(mswp[0][1], mswp.back()[0]) - (i + 1);
// cout << tot << endl;
}
cout << tot % 1000003 << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
476 KB |
Output is correct |
12 |
Correct |
4 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
476 KB |
Output is correct |
12 |
Correct |
4 ms |
488 KB |
Output is correct |
13 |
Correct |
5 ms |
484 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
472 KB |
Output is correct |
17 |
Correct |
5 ms |
480 KB |
Output is correct |
18 |
Correct |
5 ms |
472 KB |
Output is correct |
19 |
Correct |
5 ms |
472 KB |
Output is correct |
20 |
Correct |
7 ms |
468 KB |
Output is correct |
21 |
Correct |
7 ms |
468 KB |
Output is correct |
22 |
Correct |
6 ms |
468 KB |
Output is correct |
23 |
Correct |
4 ms |
484 KB |
Output is correct |
24 |
Correct |
5 ms |
484 KB |
Output is correct |
25 |
Correct |
5 ms |
472 KB |
Output is correct |
26 |
Correct |
4 ms |
472 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
5 ms |
480 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
476 KB |
Output is correct |
12 |
Correct |
4 ms |
488 KB |
Output is correct |
13 |
Correct |
5 ms |
484 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
472 KB |
Output is correct |
17 |
Correct |
5 ms |
480 KB |
Output is correct |
18 |
Correct |
5 ms |
472 KB |
Output is correct |
19 |
Correct |
5 ms |
472 KB |
Output is correct |
20 |
Correct |
7 ms |
468 KB |
Output is correct |
21 |
Correct |
7 ms |
468 KB |
Output is correct |
22 |
Correct |
6 ms |
468 KB |
Output is correct |
23 |
Correct |
4 ms |
484 KB |
Output is correct |
24 |
Correct |
5 ms |
484 KB |
Output is correct |
25 |
Correct |
5 ms |
472 KB |
Output is correct |
26 |
Correct |
4 ms |
472 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
5 ms |
480 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
476 KB |
Output is correct |
12 |
Correct |
4 ms |
488 KB |
Output is correct |
13 |
Correct |
5 ms |
484 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
472 KB |
Output is correct |
17 |
Correct |
5 ms |
480 KB |
Output is correct |
18 |
Correct |
5 ms |
472 KB |
Output is correct |
19 |
Correct |
5 ms |
472 KB |
Output is correct |
20 |
Correct |
7 ms |
468 KB |
Output is correct |
21 |
Correct |
7 ms |
468 KB |
Output is correct |
22 |
Correct |
6 ms |
468 KB |
Output is correct |
23 |
Correct |
4 ms |
484 KB |
Output is correct |
24 |
Correct |
5 ms |
484 KB |
Output is correct |
25 |
Correct |
5 ms |
472 KB |
Output is correct |
26 |
Correct |
4 ms |
472 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
5 ms |
480 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
476 KB |
Output is correct |
12 |
Correct |
4 ms |
488 KB |
Output is correct |
13 |
Correct |
5 ms |
484 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
472 KB |
Output is correct |
17 |
Correct |
5 ms |
480 KB |
Output is correct |
18 |
Correct |
5 ms |
472 KB |
Output is correct |
19 |
Correct |
5 ms |
472 KB |
Output is correct |
20 |
Correct |
7 ms |
468 KB |
Output is correct |
21 |
Correct |
7 ms |
468 KB |
Output is correct |
22 |
Correct |
6 ms |
468 KB |
Output is correct |
23 |
Correct |
4 ms |
484 KB |
Output is correct |
24 |
Correct |
5 ms |
484 KB |
Output is correct |
25 |
Correct |
5 ms |
472 KB |
Output is correct |
26 |
Correct |
4 ms |
472 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
5 ms |
480 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1317 ms |
25440 KB |
Output is correct |
36 |
Correct |
1392 ms |
25440 KB |
Output is correct |
37 |
Correct |
1304 ms |
25456 KB |
Output is correct |
38 |
Correct |
1339 ms |
25464 KB |
Output is correct |
39 |
Correct |
1307 ms |
25448 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1718 ms |
25652 KB |
Output is correct |
43 |
Correct |
1709 ms |
25640 KB |
Output is correct |
44 |
Correct |
1569 ms |
25632 KB |
Output is correct |
45 |
Correct |
1123 ms |
25416 KB |
Output is correct |
46 |
Correct |
1098 ms |
25472 KB |
Output is correct |
47 |
Correct |
1096 ms |
25392 KB |
Output is correct |
48 |
Correct |
1159 ms |
25472 KB |
Output is correct |
49 |
Correct |
1214 ms |
25360 KB |
Output is correct |
50 |
Correct |
1146 ms |
25408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
476 KB |
Output is correct |
12 |
Correct |
4 ms |
488 KB |
Output is correct |
13 |
Correct |
5 ms |
484 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
472 KB |
Output is correct |
17 |
Correct |
5 ms |
480 KB |
Output is correct |
18 |
Correct |
5 ms |
472 KB |
Output is correct |
19 |
Correct |
5 ms |
472 KB |
Output is correct |
20 |
Correct |
7 ms |
468 KB |
Output is correct |
21 |
Correct |
7 ms |
468 KB |
Output is correct |
22 |
Correct |
6 ms |
468 KB |
Output is correct |
23 |
Correct |
4 ms |
484 KB |
Output is correct |
24 |
Correct |
5 ms |
484 KB |
Output is correct |
25 |
Correct |
5 ms |
472 KB |
Output is correct |
26 |
Correct |
4 ms |
472 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
5 ms |
480 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
476 KB |
Output is correct |
12 |
Correct |
4 ms |
488 KB |
Output is correct |
13 |
Correct |
5 ms |
484 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
472 KB |
Output is correct |
17 |
Correct |
5 ms |
480 KB |
Output is correct |
18 |
Correct |
5 ms |
472 KB |
Output is correct |
19 |
Correct |
5 ms |
472 KB |
Output is correct |
20 |
Correct |
7 ms |
468 KB |
Output is correct |
21 |
Correct |
7 ms |
468 KB |
Output is correct |
22 |
Correct |
6 ms |
468 KB |
Output is correct |
23 |
Correct |
4 ms |
484 KB |
Output is correct |
24 |
Correct |
5 ms |
484 KB |
Output is correct |
25 |
Correct |
5 ms |
472 KB |
Output is correct |
26 |
Correct |
4 ms |
472 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
5 ms |
480 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |