# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
237751 |
2020-06-08T15:42:01 Z |
Haunted_Cpp |
Pilot (NOI19_pilot) |
C++17 |
|
727 ms |
67632 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
long long ans [N];
vector<int> arr, esq, dir;
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
arr.resize(n); esq.resize(n); dir.resize(n);
vector< tuple<int, int, int> > sweep;
for (int i = 0; i < n; i++) {
cin >> arr[i];
sweep.emplace_back(arr[i], 0, i);
}
for (int i = 0; i < q; i++) {
int where;
cin >> where;
sweep.emplace_back(where, 1, i);
}
sort (sweep.rbegin(), sweep.rend());
auto calc = [&] (vector<int> elem, vector<int> &where, bool flip) {
stack< pair<int, int> > stk;
stk.push({(!flip ? -1 : n), numeric_limits<int>::max()});
for (int i = (!flip ? 0 : n - 1); (!flip ? i < n : i >= 0) ; (!flip ? i++ : i--) ) {
if (!flip) while (stk.top().second < elem[i]) stk.pop();
else while (stk.top().second <= elem[i]) stk.pop();
where[i] = stk.top().first;
stk.push({i, elem[i]});
}
};
calc (arr, esq, false);
calc (arr, dir, true);
long long res = n * (1LL + n) / 2;
for (auto to : sweep) {
int tipo = get<1> (to);
if (tipo == 0) {
// Place
int where = get<2>(to);
int na_esquerda = max (0, where - esq[where] - 1);
int na_direita = max (0, dir[where] - where - 1);
res -= 1LL * (na_esquerda + 1) * (na_direita + 1);
} else {
// Reply
ans[get<2>(to)] = res;
}
}
for (int i = 0; i < q; i++) cout << ans[i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
432 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
432 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
432 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
432 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
3704 KB |
Output is correct |
2 |
Correct |
33 ms |
3784 KB |
Output is correct |
3 |
Correct |
32 ms |
3704 KB |
Output is correct |
4 |
Correct |
31 ms |
3704 KB |
Output is correct |
5 |
Correct |
32 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
7652 KB |
Output is correct |
2 |
Correct |
65 ms |
7880 KB |
Output is correct |
3 |
Correct |
63 ms |
7668 KB |
Output is correct |
4 |
Correct |
63 ms |
7780 KB |
Output is correct |
5 |
Correct |
62 ms |
7528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
7784 KB |
Output is correct |
2 |
Correct |
64 ms |
7784 KB |
Output is correct |
3 |
Correct |
65 ms |
7780 KB |
Output is correct |
4 |
Correct |
65 ms |
7908 KB |
Output is correct |
5 |
Correct |
66 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
432 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
37 ms |
3704 KB |
Output is correct |
12 |
Correct |
33 ms |
3784 KB |
Output is correct |
13 |
Correct |
32 ms |
3704 KB |
Output is correct |
14 |
Correct |
31 ms |
3704 KB |
Output is correct |
15 |
Correct |
32 ms |
3704 KB |
Output is correct |
16 |
Correct |
32 ms |
3704 KB |
Output is correct |
17 |
Correct |
33 ms |
3820 KB |
Output is correct |
18 |
Correct |
34 ms |
3832 KB |
Output is correct |
19 |
Correct |
31 ms |
3576 KB |
Output is correct |
20 |
Correct |
33 ms |
3832 KB |
Output is correct |
21 |
Correct |
30 ms |
3576 KB |
Output is correct |
22 |
Correct |
35 ms |
3960 KB |
Output is correct |
23 |
Correct |
33 ms |
3704 KB |
Output is correct |
24 |
Correct |
31 ms |
3704 KB |
Output is correct |
25 |
Correct |
33 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
432 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
37 ms |
3704 KB |
Output is correct |
27 |
Correct |
33 ms |
3784 KB |
Output is correct |
28 |
Correct |
32 ms |
3704 KB |
Output is correct |
29 |
Correct |
31 ms |
3704 KB |
Output is correct |
30 |
Correct |
32 ms |
3704 KB |
Output is correct |
31 |
Correct |
61 ms |
7652 KB |
Output is correct |
32 |
Correct |
65 ms |
7880 KB |
Output is correct |
33 |
Correct |
63 ms |
7668 KB |
Output is correct |
34 |
Correct |
63 ms |
7780 KB |
Output is correct |
35 |
Correct |
62 ms |
7528 KB |
Output is correct |
36 |
Correct |
63 ms |
7784 KB |
Output is correct |
37 |
Correct |
64 ms |
7784 KB |
Output is correct |
38 |
Correct |
65 ms |
7780 KB |
Output is correct |
39 |
Correct |
65 ms |
7908 KB |
Output is correct |
40 |
Correct |
66 ms |
8192 KB |
Output is correct |
41 |
Correct |
32 ms |
3704 KB |
Output is correct |
42 |
Correct |
33 ms |
3820 KB |
Output is correct |
43 |
Correct |
34 ms |
3832 KB |
Output is correct |
44 |
Correct |
31 ms |
3576 KB |
Output is correct |
45 |
Correct |
33 ms |
3832 KB |
Output is correct |
46 |
Correct |
30 ms |
3576 KB |
Output is correct |
47 |
Correct |
35 ms |
3960 KB |
Output is correct |
48 |
Correct |
33 ms |
3704 KB |
Output is correct |
49 |
Correct |
31 ms |
3704 KB |
Output is correct |
50 |
Correct |
33 ms |
3704 KB |
Output is correct |
51 |
Correct |
67 ms |
6884 KB |
Output is correct |
52 |
Correct |
67 ms |
6768 KB |
Output is correct |
53 |
Correct |
75 ms |
6888 KB |
Output is correct |
54 |
Correct |
66 ms |
6760 KB |
Output is correct |
55 |
Correct |
66 ms |
6884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
432 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
37 ms |
3704 KB |
Output is correct |
27 |
Correct |
33 ms |
3784 KB |
Output is correct |
28 |
Correct |
32 ms |
3704 KB |
Output is correct |
29 |
Correct |
31 ms |
3704 KB |
Output is correct |
30 |
Correct |
32 ms |
3704 KB |
Output is correct |
31 |
Correct |
61 ms |
7652 KB |
Output is correct |
32 |
Correct |
65 ms |
7880 KB |
Output is correct |
33 |
Correct |
63 ms |
7668 KB |
Output is correct |
34 |
Correct |
63 ms |
7780 KB |
Output is correct |
35 |
Correct |
62 ms |
7528 KB |
Output is correct |
36 |
Correct |
63 ms |
7784 KB |
Output is correct |
37 |
Correct |
64 ms |
7784 KB |
Output is correct |
38 |
Correct |
65 ms |
7780 KB |
Output is correct |
39 |
Correct |
65 ms |
7908 KB |
Output is correct |
40 |
Correct |
66 ms |
8192 KB |
Output is correct |
41 |
Correct |
32 ms |
3704 KB |
Output is correct |
42 |
Correct |
33 ms |
3820 KB |
Output is correct |
43 |
Correct |
34 ms |
3832 KB |
Output is correct |
44 |
Correct |
31 ms |
3576 KB |
Output is correct |
45 |
Correct |
33 ms |
3832 KB |
Output is correct |
46 |
Correct |
30 ms |
3576 KB |
Output is correct |
47 |
Correct |
35 ms |
3960 KB |
Output is correct |
48 |
Correct |
33 ms |
3704 KB |
Output is correct |
49 |
Correct |
31 ms |
3704 KB |
Output is correct |
50 |
Correct |
33 ms |
3704 KB |
Output is correct |
51 |
Correct |
67 ms |
6884 KB |
Output is correct |
52 |
Correct |
67 ms |
6768 KB |
Output is correct |
53 |
Correct |
75 ms |
6888 KB |
Output is correct |
54 |
Correct |
66 ms |
6760 KB |
Output is correct |
55 |
Correct |
66 ms |
6884 KB |
Output is correct |
56 |
Correct |
706 ms |
62896 KB |
Output is correct |
57 |
Correct |
694 ms |
65700 KB |
Output is correct |
58 |
Correct |
674 ms |
62148 KB |
Output is correct |
59 |
Correct |
677 ms |
63512 KB |
Output is correct |
60 |
Correct |
727 ms |
67632 KB |
Output is correct |