# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
692431 |
2023-02-01T12:38:42 Z |
ghostwriter |
Pilot (NOI19_pilot) |
C++17 |
|
516 ms |
52268 KB |
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define bg begin
#define ed end
#define ft front
#define bk back
#define sz(x) (int)(x).size()
#define all(x) (x).bg(), (x).ed()
#define mtp make_tuple
#define ins insert
#define ers erase
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define str string
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FOS(i, r, l) for (int i = (r); i >= (l); --i)
#define FRN(i, n) for (int i = 0; i < (n); ++i)
#define FSN(i, n) for (int i = (n) - 1; i >= 0; --i)
#define EACH(i, x) for (auto &i : (x))
#define WHILE while
template<typename T> T gcd(T a, T b) { WHILE(b) { a %= b; swap(a, b); } return b; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
const int N = 1e6 + 5;
int n, q, h[N], p[N], lm[N], rm[N];
vpi h1;
ll ans[N];
int getp(int x) { return p[x] == x? x : p[x] = getp(p[x]); }
void join(int x, int y) {
x = getp(x);
y = getp(y);
if (x == y) return;
p[y] = x;
rm[x] = rm[y];
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
cin >> n >> q;
FOR(i, 1, n) {
cin >> h[i];
h1.pb({h[i], i});
}
sort(all(h1));
FOR(i, 1, n) p[i] = lm[i] = rm[i] = i;
FRN(j, n) {
int i = h1[j].nd;
if (i > 1 && h[i - 1] <= h[i]) join(i - 1, i);
if (i < n && h[i + 1] < h[i]) join(i, i + 1);
int l = lm[getp(i)], r = rm[getp(i)];
ans[h[i]] += 1LL * (i - l + 1) * (r - i + 1);
}
FOR(i, 1, 1e6) ans[i] += ans[i - 1];
WHILE(q--) {
int y;
cin >> y;
cout << ans[y] << '\n';
}
// cerr << "\nTime: " << setprecision(5) << fixed << (ldb)clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
6 ms |
8148 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8184 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
6 ms |
8152 KB |
Output is correct |
7 |
Correct |
6 ms |
8088 KB |
Output is correct |
8 |
Correct |
6 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8156 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
6 ms |
8148 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8184 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
6 ms |
8152 KB |
Output is correct |
7 |
Correct |
6 ms |
8088 KB |
Output is correct |
8 |
Correct |
6 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8156 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
5 ms |
8148 KB |
Output is correct |
12 |
Correct |
6 ms |
8148 KB |
Output is correct |
13 |
Correct |
5 ms |
8148 KB |
Output is correct |
14 |
Correct |
6 ms |
8120 KB |
Output is correct |
15 |
Correct |
6 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
6 ms |
8148 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8184 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
6 ms |
8152 KB |
Output is correct |
7 |
Correct |
6 ms |
8088 KB |
Output is correct |
8 |
Correct |
6 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8156 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
5 ms |
8148 KB |
Output is correct |
12 |
Correct |
6 ms |
8148 KB |
Output is correct |
13 |
Correct |
5 ms |
8148 KB |
Output is correct |
14 |
Correct |
6 ms |
8120 KB |
Output is correct |
15 |
Correct |
6 ms |
8148 KB |
Output is correct |
16 |
Correct |
6 ms |
8152 KB |
Output is correct |
17 |
Correct |
6 ms |
8152 KB |
Output is correct |
18 |
Correct |
5 ms |
8148 KB |
Output is correct |
19 |
Correct |
6 ms |
8148 KB |
Output is correct |
20 |
Correct |
6 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
6 ms |
8148 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8184 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
6 ms |
8152 KB |
Output is correct |
7 |
Correct |
6 ms |
8088 KB |
Output is correct |
8 |
Correct |
6 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8156 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
5 ms |
8148 KB |
Output is correct |
12 |
Correct |
6 ms |
8148 KB |
Output is correct |
13 |
Correct |
5 ms |
8148 KB |
Output is correct |
14 |
Correct |
6 ms |
8120 KB |
Output is correct |
15 |
Correct |
6 ms |
8148 KB |
Output is correct |
16 |
Correct |
6 ms |
8152 KB |
Output is correct |
17 |
Correct |
6 ms |
8152 KB |
Output is correct |
18 |
Correct |
5 ms |
8148 KB |
Output is correct |
19 |
Correct |
6 ms |
8148 KB |
Output is correct |
20 |
Correct |
6 ms |
8148 KB |
Output is correct |
21 |
Correct |
6 ms |
8148 KB |
Output is correct |
22 |
Correct |
6 ms |
8120 KB |
Output is correct |
23 |
Correct |
6 ms |
8160 KB |
Output is correct |
24 |
Correct |
7 ms |
8164 KB |
Output is correct |
25 |
Correct |
7 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
11048 KB |
Output is correct |
2 |
Correct |
28 ms |
11208 KB |
Output is correct |
3 |
Correct |
25 ms |
10948 KB |
Output is correct |
4 |
Correct |
25 ms |
10944 KB |
Output is correct |
5 |
Correct |
24 ms |
10968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
12484 KB |
Output is correct |
2 |
Correct |
42 ms |
12596 KB |
Output is correct |
3 |
Correct |
45 ms |
12512 KB |
Output is correct |
4 |
Correct |
37 ms |
12728 KB |
Output is correct |
5 |
Correct |
34 ms |
12484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
12672 KB |
Output is correct |
2 |
Correct |
46 ms |
12668 KB |
Output is correct |
3 |
Correct |
37 ms |
12612 KB |
Output is correct |
4 |
Correct |
38 ms |
12824 KB |
Output is correct |
5 |
Correct |
38 ms |
12760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
6 ms |
8148 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8184 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
6 ms |
8152 KB |
Output is correct |
7 |
Correct |
6 ms |
8088 KB |
Output is correct |
8 |
Correct |
6 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8156 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
26 ms |
11048 KB |
Output is correct |
12 |
Correct |
28 ms |
11208 KB |
Output is correct |
13 |
Correct |
25 ms |
10948 KB |
Output is correct |
14 |
Correct |
25 ms |
10944 KB |
Output is correct |
15 |
Correct |
24 ms |
10968 KB |
Output is correct |
16 |
Correct |
25 ms |
11096 KB |
Output is correct |
17 |
Correct |
24 ms |
11260 KB |
Output is correct |
18 |
Correct |
25 ms |
11188 KB |
Output is correct |
19 |
Correct |
23 ms |
10960 KB |
Output is correct |
20 |
Correct |
25 ms |
11132 KB |
Output is correct |
21 |
Correct |
23 ms |
10952 KB |
Output is correct |
22 |
Correct |
26 ms |
11080 KB |
Output is correct |
23 |
Correct |
26 ms |
11184 KB |
Output is correct |
24 |
Correct |
27 ms |
10940 KB |
Output is correct |
25 |
Correct |
25 ms |
11048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
6 ms |
8148 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8184 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
6 ms |
8152 KB |
Output is correct |
7 |
Correct |
6 ms |
8088 KB |
Output is correct |
8 |
Correct |
6 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8156 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
5 ms |
8148 KB |
Output is correct |
12 |
Correct |
6 ms |
8148 KB |
Output is correct |
13 |
Correct |
5 ms |
8148 KB |
Output is correct |
14 |
Correct |
6 ms |
8120 KB |
Output is correct |
15 |
Correct |
6 ms |
8148 KB |
Output is correct |
16 |
Correct |
6 ms |
8152 KB |
Output is correct |
17 |
Correct |
6 ms |
8152 KB |
Output is correct |
18 |
Correct |
5 ms |
8148 KB |
Output is correct |
19 |
Correct |
6 ms |
8148 KB |
Output is correct |
20 |
Correct |
6 ms |
8148 KB |
Output is correct |
21 |
Correct |
6 ms |
8148 KB |
Output is correct |
22 |
Correct |
6 ms |
8120 KB |
Output is correct |
23 |
Correct |
6 ms |
8160 KB |
Output is correct |
24 |
Correct |
7 ms |
8164 KB |
Output is correct |
25 |
Correct |
7 ms |
8148 KB |
Output is correct |
26 |
Correct |
26 ms |
11048 KB |
Output is correct |
27 |
Correct |
28 ms |
11208 KB |
Output is correct |
28 |
Correct |
25 ms |
10948 KB |
Output is correct |
29 |
Correct |
25 ms |
10944 KB |
Output is correct |
30 |
Correct |
24 ms |
10968 KB |
Output is correct |
31 |
Correct |
34 ms |
12484 KB |
Output is correct |
32 |
Correct |
42 ms |
12596 KB |
Output is correct |
33 |
Correct |
45 ms |
12512 KB |
Output is correct |
34 |
Correct |
37 ms |
12728 KB |
Output is correct |
35 |
Correct |
34 ms |
12484 KB |
Output is correct |
36 |
Correct |
34 ms |
12672 KB |
Output is correct |
37 |
Correct |
46 ms |
12668 KB |
Output is correct |
38 |
Correct |
37 ms |
12612 KB |
Output is correct |
39 |
Correct |
38 ms |
12824 KB |
Output is correct |
40 |
Correct |
38 ms |
12760 KB |
Output is correct |
41 |
Correct |
25 ms |
11096 KB |
Output is correct |
42 |
Correct |
24 ms |
11260 KB |
Output is correct |
43 |
Correct |
25 ms |
11188 KB |
Output is correct |
44 |
Correct |
23 ms |
10960 KB |
Output is correct |
45 |
Correct |
25 ms |
11132 KB |
Output is correct |
46 |
Correct |
23 ms |
10952 KB |
Output is correct |
47 |
Correct |
26 ms |
11080 KB |
Output is correct |
48 |
Correct |
26 ms |
11184 KB |
Output is correct |
49 |
Correct |
27 ms |
10940 KB |
Output is correct |
50 |
Correct |
25 ms |
11048 KB |
Output is correct |
51 |
Correct |
46 ms |
12616 KB |
Output is correct |
52 |
Correct |
43 ms |
12356 KB |
Output is correct |
53 |
Correct |
45 ms |
12500 KB |
Output is correct |
54 |
Correct |
50 ms |
12424 KB |
Output is correct |
55 |
Correct |
44 ms |
12528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
6 ms |
8148 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8184 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
6 ms |
8152 KB |
Output is correct |
7 |
Correct |
6 ms |
8088 KB |
Output is correct |
8 |
Correct |
6 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8156 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
5 ms |
8148 KB |
Output is correct |
12 |
Correct |
6 ms |
8148 KB |
Output is correct |
13 |
Correct |
5 ms |
8148 KB |
Output is correct |
14 |
Correct |
6 ms |
8120 KB |
Output is correct |
15 |
Correct |
6 ms |
8148 KB |
Output is correct |
16 |
Correct |
6 ms |
8152 KB |
Output is correct |
17 |
Correct |
6 ms |
8152 KB |
Output is correct |
18 |
Correct |
5 ms |
8148 KB |
Output is correct |
19 |
Correct |
6 ms |
8148 KB |
Output is correct |
20 |
Correct |
6 ms |
8148 KB |
Output is correct |
21 |
Correct |
6 ms |
8148 KB |
Output is correct |
22 |
Correct |
6 ms |
8120 KB |
Output is correct |
23 |
Correct |
6 ms |
8160 KB |
Output is correct |
24 |
Correct |
7 ms |
8164 KB |
Output is correct |
25 |
Correct |
7 ms |
8148 KB |
Output is correct |
26 |
Correct |
26 ms |
11048 KB |
Output is correct |
27 |
Correct |
28 ms |
11208 KB |
Output is correct |
28 |
Correct |
25 ms |
10948 KB |
Output is correct |
29 |
Correct |
25 ms |
10944 KB |
Output is correct |
30 |
Correct |
24 ms |
10968 KB |
Output is correct |
31 |
Correct |
34 ms |
12484 KB |
Output is correct |
32 |
Correct |
42 ms |
12596 KB |
Output is correct |
33 |
Correct |
45 ms |
12512 KB |
Output is correct |
34 |
Correct |
37 ms |
12728 KB |
Output is correct |
35 |
Correct |
34 ms |
12484 KB |
Output is correct |
36 |
Correct |
34 ms |
12672 KB |
Output is correct |
37 |
Correct |
46 ms |
12668 KB |
Output is correct |
38 |
Correct |
37 ms |
12612 KB |
Output is correct |
39 |
Correct |
38 ms |
12824 KB |
Output is correct |
40 |
Correct |
38 ms |
12760 KB |
Output is correct |
41 |
Correct |
25 ms |
11096 KB |
Output is correct |
42 |
Correct |
24 ms |
11260 KB |
Output is correct |
43 |
Correct |
25 ms |
11188 KB |
Output is correct |
44 |
Correct |
23 ms |
10960 KB |
Output is correct |
45 |
Correct |
25 ms |
11132 KB |
Output is correct |
46 |
Correct |
23 ms |
10952 KB |
Output is correct |
47 |
Correct |
26 ms |
11080 KB |
Output is correct |
48 |
Correct |
26 ms |
11184 KB |
Output is correct |
49 |
Correct |
27 ms |
10940 KB |
Output is correct |
50 |
Correct |
25 ms |
11048 KB |
Output is correct |
51 |
Correct |
46 ms |
12616 KB |
Output is correct |
52 |
Correct |
43 ms |
12356 KB |
Output is correct |
53 |
Correct |
45 ms |
12500 KB |
Output is correct |
54 |
Correct |
50 ms |
12424 KB |
Output is correct |
55 |
Correct |
44 ms |
12528 KB |
Output is correct |
56 |
Correct |
499 ms |
50940 KB |
Output is correct |
57 |
Correct |
476 ms |
51500 KB |
Output is correct |
58 |
Correct |
450 ms |
48656 KB |
Output is correct |
59 |
Correct |
503 ms |
49664 KB |
Output is correct |
60 |
Correct |
516 ms |
52268 KB |
Output is correct |