# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
478050 |
2021-10-05T12:01:14 Z |
chungdinh |
Pilot (NOI19_pilot) |
C++14 |
|
1000 ms |
39044 KB |
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define r first
#define c second
#define all(x) x.begin(), x.end()
ostream& operator << (ostream& os, pair<int, int> a) {
return os << a.first << " : " << a.second;
}
#define endl '\n'
#define db(val) "["#val" = "<<(val)<<"] "
#define cntbit(x) __builtin_popcount(x)
const int N = 1e6 + 5;
const int iINF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1e18;
int n, q;
int h[N];
ii a[N];
int id[N];
ll res[N];
bool below[N];
ll f(int x) {return (ll)x*(x + 1)/2;}
int p[N];
int sz[N];
int find(int u) {
if (u == p[u]) return u;
return p[u] = find(p[u]);
}
void sss(int u, int v, ll &subres) {
u = find(u); v = find(v);
subres -= f(sz[u]) + f(sz[v]);
p[u] = v;
sz[v] += sz[u];
subres += f(sz[v]);
}
int main() {
#ifdef CHUNGDINH
freopen("main.inp","r",stdin);
//freopen("main.out","w",stdout);
#endif
memset(below, false, sizeof below);
cin >> n >> q;
for (int i = 1; i <= n; i++) {
id[i] = i;
cin >> h[i];
p[i] = i; sz[i] = 1;
}
sort(id + 1, id + n + 1, [](int x, int y){return h[x] < h[y];});
for (int i = 1; i <= q; i++) {
cin >> a[i].first; a[i].second = i;
}
sort(a + 1, a + q + 1);
// case n == 1;
ll subres = 0;
int ss = 1;
for (int i = 1; i <= q; i++) {
while (ss <= n && h[id[ss]] <= a[i].first) {
subres++;
int pl = id[ss];
below[pl] = true;
if (pl <= n - 1 && below[pl + 1]) {
sss(pl, pl + 1, subres);
}
if (pl >= 2 && below[pl - 1]) sss(pl, pl - 1, subres);
ss++;
}
res[a[i].second] = subres;
}
//for (int i = 1; i <= n; i++) cout << id[i] << " ";
for (int i = 1; i <= q; i++) cout << res[i] << endl;
}
/*
Array bounds *
long long vs int
Garbage value
Sometimes, VNOI views "arrays out of bounds" as "wrong answer"
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Correct |
1 ms |
1228 KB |
Output is correct |
6 |
Correct |
1 ms |
1228 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
1 ms |
1228 KB |
Output is correct |
9 |
Correct |
1 ms |
1228 KB |
Output is correct |
10 |
Correct |
1 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Correct |
1 ms |
1228 KB |
Output is correct |
6 |
Correct |
1 ms |
1228 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
1 ms |
1228 KB |
Output is correct |
9 |
Correct |
1 ms |
1228 KB |
Output is correct |
10 |
Correct |
1 ms |
1228 KB |
Output is correct |
11 |
Correct |
1 ms |
1228 KB |
Output is correct |
12 |
Correct |
1 ms |
1276 KB |
Output is correct |
13 |
Correct |
1 ms |
1228 KB |
Output is correct |
14 |
Correct |
1 ms |
1228 KB |
Output is correct |
15 |
Correct |
1 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Correct |
1 ms |
1228 KB |
Output is correct |
6 |
Correct |
1 ms |
1228 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
1 ms |
1228 KB |
Output is correct |
9 |
Correct |
1 ms |
1228 KB |
Output is correct |
10 |
Correct |
1 ms |
1228 KB |
Output is correct |
11 |
Correct |
1 ms |
1228 KB |
Output is correct |
12 |
Correct |
1 ms |
1276 KB |
Output is correct |
13 |
Correct |
1 ms |
1228 KB |
Output is correct |
14 |
Correct |
1 ms |
1228 KB |
Output is correct |
15 |
Correct |
1 ms |
1228 KB |
Output is correct |
16 |
Correct |
1 ms |
1228 KB |
Output is correct |
17 |
Correct |
2 ms |
1228 KB |
Output is correct |
18 |
Correct |
1 ms |
1228 KB |
Output is correct |
19 |
Correct |
1 ms |
1228 KB |
Output is correct |
20 |
Correct |
1 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Correct |
1 ms |
1228 KB |
Output is correct |
6 |
Correct |
1 ms |
1228 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
1 ms |
1228 KB |
Output is correct |
9 |
Correct |
1 ms |
1228 KB |
Output is correct |
10 |
Correct |
1 ms |
1228 KB |
Output is correct |
11 |
Correct |
1 ms |
1228 KB |
Output is correct |
12 |
Correct |
1 ms |
1276 KB |
Output is correct |
13 |
Correct |
1 ms |
1228 KB |
Output is correct |
14 |
Correct |
1 ms |
1228 KB |
Output is correct |
15 |
Correct |
1 ms |
1228 KB |
Output is correct |
16 |
Correct |
1 ms |
1228 KB |
Output is correct |
17 |
Correct |
2 ms |
1228 KB |
Output is correct |
18 |
Correct |
1 ms |
1228 KB |
Output is correct |
19 |
Correct |
1 ms |
1228 KB |
Output is correct |
20 |
Correct |
1 ms |
1228 KB |
Output is correct |
21 |
Correct |
2 ms |
1356 KB |
Output is correct |
22 |
Correct |
2 ms |
1356 KB |
Output is correct |
23 |
Correct |
2 ms |
1356 KB |
Output is correct |
24 |
Correct |
2 ms |
1356 KB |
Output is correct |
25 |
Correct |
1 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
2820 KB |
Output is correct |
2 |
Correct |
46 ms |
2756 KB |
Output is correct |
3 |
Correct |
45 ms |
2816 KB |
Output is correct |
4 |
Correct |
41 ms |
2604 KB |
Output is correct |
5 |
Correct |
40 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
5188 KB |
Output is correct |
2 |
Correct |
79 ms |
5204 KB |
Output is correct |
3 |
Correct |
80 ms |
5188 KB |
Output is correct |
4 |
Correct |
78 ms |
5320 KB |
Output is correct |
5 |
Correct |
78 ms |
5124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
5108 KB |
Output is correct |
2 |
Correct |
81 ms |
5148 KB |
Output is correct |
3 |
Correct |
82 ms |
5188 KB |
Output is correct |
4 |
Correct |
81 ms |
5116 KB |
Output is correct |
5 |
Correct |
85 ms |
5316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Correct |
1 ms |
1228 KB |
Output is correct |
6 |
Correct |
1 ms |
1228 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
1 ms |
1228 KB |
Output is correct |
9 |
Correct |
1 ms |
1228 KB |
Output is correct |
10 |
Correct |
1 ms |
1228 KB |
Output is correct |
11 |
Correct |
42 ms |
2820 KB |
Output is correct |
12 |
Correct |
46 ms |
2756 KB |
Output is correct |
13 |
Correct |
45 ms |
2816 KB |
Output is correct |
14 |
Correct |
41 ms |
2604 KB |
Output is correct |
15 |
Correct |
40 ms |
2644 KB |
Output is correct |
16 |
Correct |
39 ms |
2636 KB |
Output is correct |
17 |
Correct |
43 ms |
2916 KB |
Output is correct |
18 |
Correct |
44 ms |
2756 KB |
Output is correct |
19 |
Correct |
35 ms |
2628 KB |
Output is correct |
20 |
Correct |
41 ms |
2800 KB |
Output is correct |
21 |
Correct |
39 ms |
2628 KB |
Output is correct |
22 |
Correct |
44 ms |
2636 KB |
Output is correct |
23 |
Correct |
40 ms |
2788 KB |
Output is correct |
24 |
Correct |
39 ms |
2616 KB |
Output is correct |
25 |
Correct |
41 ms |
2776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Correct |
1 ms |
1228 KB |
Output is correct |
6 |
Correct |
1 ms |
1228 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
1 ms |
1228 KB |
Output is correct |
9 |
Correct |
1 ms |
1228 KB |
Output is correct |
10 |
Correct |
1 ms |
1228 KB |
Output is correct |
11 |
Correct |
1 ms |
1228 KB |
Output is correct |
12 |
Correct |
1 ms |
1276 KB |
Output is correct |
13 |
Correct |
1 ms |
1228 KB |
Output is correct |
14 |
Correct |
1 ms |
1228 KB |
Output is correct |
15 |
Correct |
1 ms |
1228 KB |
Output is correct |
16 |
Correct |
1 ms |
1228 KB |
Output is correct |
17 |
Correct |
2 ms |
1228 KB |
Output is correct |
18 |
Correct |
1 ms |
1228 KB |
Output is correct |
19 |
Correct |
1 ms |
1228 KB |
Output is correct |
20 |
Correct |
1 ms |
1228 KB |
Output is correct |
21 |
Correct |
2 ms |
1356 KB |
Output is correct |
22 |
Correct |
2 ms |
1356 KB |
Output is correct |
23 |
Correct |
2 ms |
1356 KB |
Output is correct |
24 |
Correct |
2 ms |
1356 KB |
Output is correct |
25 |
Correct |
1 ms |
1356 KB |
Output is correct |
26 |
Correct |
42 ms |
2820 KB |
Output is correct |
27 |
Correct |
46 ms |
2756 KB |
Output is correct |
28 |
Correct |
45 ms |
2816 KB |
Output is correct |
29 |
Correct |
41 ms |
2604 KB |
Output is correct |
30 |
Correct |
40 ms |
2644 KB |
Output is correct |
31 |
Correct |
77 ms |
5188 KB |
Output is correct |
32 |
Correct |
79 ms |
5204 KB |
Output is correct |
33 |
Correct |
80 ms |
5188 KB |
Output is correct |
34 |
Correct |
78 ms |
5320 KB |
Output is correct |
35 |
Correct |
78 ms |
5124 KB |
Output is correct |
36 |
Correct |
84 ms |
5108 KB |
Output is correct |
37 |
Correct |
81 ms |
5148 KB |
Output is correct |
38 |
Correct |
82 ms |
5188 KB |
Output is correct |
39 |
Correct |
81 ms |
5116 KB |
Output is correct |
40 |
Correct |
85 ms |
5316 KB |
Output is correct |
41 |
Correct |
39 ms |
2636 KB |
Output is correct |
42 |
Correct |
43 ms |
2916 KB |
Output is correct |
43 |
Correct |
44 ms |
2756 KB |
Output is correct |
44 |
Correct |
35 ms |
2628 KB |
Output is correct |
45 |
Correct |
41 ms |
2800 KB |
Output is correct |
46 |
Correct |
39 ms |
2628 KB |
Output is correct |
47 |
Correct |
44 ms |
2636 KB |
Output is correct |
48 |
Correct |
40 ms |
2788 KB |
Output is correct |
49 |
Correct |
39 ms |
2616 KB |
Output is correct |
50 |
Correct |
41 ms |
2776 KB |
Output is correct |
51 |
Correct |
93 ms |
5076 KB |
Output is correct |
52 |
Correct |
99 ms |
4936 KB |
Output is correct |
53 |
Correct |
95 ms |
5188 KB |
Output is correct |
54 |
Correct |
94 ms |
4868 KB |
Output is correct |
55 |
Correct |
88 ms |
5140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Correct |
1 ms |
1228 KB |
Output is correct |
6 |
Correct |
1 ms |
1228 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
1 ms |
1228 KB |
Output is correct |
9 |
Correct |
1 ms |
1228 KB |
Output is correct |
10 |
Correct |
1 ms |
1228 KB |
Output is correct |
11 |
Correct |
1 ms |
1228 KB |
Output is correct |
12 |
Correct |
1 ms |
1276 KB |
Output is correct |
13 |
Correct |
1 ms |
1228 KB |
Output is correct |
14 |
Correct |
1 ms |
1228 KB |
Output is correct |
15 |
Correct |
1 ms |
1228 KB |
Output is correct |
16 |
Correct |
1 ms |
1228 KB |
Output is correct |
17 |
Correct |
2 ms |
1228 KB |
Output is correct |
18 |
Correct |
1 ms |
1228 KB |
Output is correct |
19 |
Correct |
1 ms |
1228 KB |
Output is correct |
20 |
Correct |
1 ms |
1228 KB |
Output is correct |
21 |
Correct |
2 ms |
1356 KB |
Output is correct |
22 |
Correct |
2 ms |
1356 KB |
Output is correct |
23 |
Correct |
2 ms |
1356 KB |
Output is correct |
24 |
Correct |
2 ms |
1356 KB |
Output is correct |
25 |
Correct |
1 ms |
1356 KB |
Output is correct |
26 |
Correct |
42 ms |
2820 KB |
Output is correct |
27 |
Correct |
46 ms |
2756 KB |
Output is correct |
28 |
Correct |
45 ms |
2816 KB |
Output is correct |
29 |
Correct |
41 ms |
2604 KB |
Output is correct |
30 |
Correct |
40 ms |
2644 KB |
Output is correct |
31 |
Correct |
77 ms |
5188 KB |
Output is correct |
32 |
Correct |
79 ms |
5204 KB |
Output is correct |
33 |
Correct |
80 ms |
5188 KB |
Output is correct |
34 |
Correct |
78 ms |
5320 KB |
Output is correct |
35 |
Correct |
78 ms |
5124 KB |
Output is correct |
36 |
Correct |
84 ms |
5108 KB |
Output is correct |
37 |
Correct |
81 ms |
5148 KB |
Output is correct |
38 |
Correct |
82 ms |
5188 KB |
Output is correct |
39 |
Correct |
81 ms |
5116 KB |
Output is correct |
40 |
Correct |
85 ms |
5316 KB |
Output is correct |
41 |
Correct |
39 ms |
2636 KB |
Output is correct |
42 |
Correct |
43 ms |
2916 KB |
Output is correct |
43 |
Correct |
44 ms |
2756 KB |
Output is correct |
44 |
Correct |
35 ms |
2628 KB |
Output is correct |
45 |
Correct |
41 ms |
2800 KB |
Output is correct |
46 |
Correct |
39 ms |
2628 KB |
Output is correct |
47 |
Correct |
44 ms |
2636 KB |
Output is correct |
48 |
Correct |
40 ms |
2788 KB |
Output is correct |
49 |
Correct |
39 ms |
2616 KB |
Output is correct |
50 |
Correct |
41 ms |
2776 KB |
Output is correct |
51 |
Correct |
93 ms |
5076 KB |
Output is correct |
52 |
Correct |
99 ms |
4936 KB |
Output is correct |
53 |
Correct |
95 ms |
5188 KB |
Output is correct |
54 |
Correct |
94 ms |
4868 KB |
Output is correct |
55 |
Correct |
88 ms |
5140 KB |
Output is correct |
56 |
Execution timed out |
1056 ms |
39044 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |