# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
478052 |
2021-10-05T12:06:18 Z |
chungdinh |
Pilot (NOI19_pilot) |
C++14 |
|
1000 ms |
38984 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]);
if (sz[u] > sz[v]) {
sz[u] += sz[v];
p[v] = u;
subres += f(sz[u]);
} else {
sz[v] += sz[u];
p[u] = v;
subres += f(sz[v]);
}
}
int main() {
ios_base::sync_with_stdio();
#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 |
1228 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 |
1228 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 |
1 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 |
1228 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 |
1 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 |
2 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
2788 KB |
Output is correct |
2 |
Correct |
45 ms |
2848 KB |
Output is correct |
3 |
Correct |
44 ms |
2744 KB |
Output is correct |
4 |
Correct |
42 ms |
2732 KB |
Output is correct |
5 |
Correct |
40 ms |
2720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
5144 KB |
Output is correct |
2 |
Correct |
82 ms |
5264 KB |
Output is correct |
3 |
Correct |
86 ms |
5184 KB |
Output is correct |
4 |
Correct |
79 ms |
5220 KB |
Output is correct |
5 |
Correct |
76 ms |
5164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
5052 KB |
Output is correct |
2 |
Correct |
93 ms |
5220 KB |
Output is correct |
3 |
Correct |
83 ms |
5120 KB |
Output is correct |
4 |
Correct |
84 ms |
5160 KB |
Output is correct |
5 |
Correct |
84 ms |
5284 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 |
45 ms |
2788 KB |
Output is correct |
12 |
Correct |
45 ms |
2848 KB |
Output is correct |
13 |
Correct |
44 ms |
2744 KB |
Output is correct |
14 |
Correct |
42 ms |
2732 KB |
Output is correct |
15 |
Correct |
40 ms |
2720 KB |
Output is correct |
16 |
Correct |
38 ms |
2640 KB |
Output is correct |
17 |
Correct |
43 ms |
2848 KB |
Output is correct |
18 |
Correct |
42 ms |
2756 KB |
Output is correct |
19 |
Correct |
37 ms |
2628 KB |
Output is correct |
20 |
Correct |
43 ms |
2740 KB |
Output is correct |
21 |
Correct |
40 ms |
2640 KB |
Output is correct |
22 |
Correct |
41 ms |
2748 KB |
Output is correct |
23 |
Correct |
46 ms |
2796 KB |
Output is correct |
24 |
Correct |
39 ms |
2628 KB |
Output is correct |
25 |
Correct |
40 ms |
2764 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 |
1228 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 |
1 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 |
2 ms |
1356 KB |
Output is correct |
26 |
Correct |
45 ms |
2788 KB |
Output is correct |
27 |
Correct |
45 ms |
2848 KB |
Output is correct |
28 |
Correct |
44 ms |
2744 KB |
Output is correct |
29 |
Correct |
42 ms |
2732 KB |
Output is correct |
30 |
Correct |
40 ms |
2720 KB |
Output is correct |
31 |
Correct |
79 ms |
5144 KB |
Output is correct |
32 |
Correct |
82 ms |
5264 KB |
Output is correct |
33 |
Correct |
86 ms |
5184 KB |
Output is correct |
34 |
Correct |
79 ms |
5220 KB |
Output is correct |
35 |
Correct |
76 ms |
5164 KB |
Output is correct |
36 |
Correct |
83 ms |
5052 KB |
Output is correct |
37 |
Correct |
93 ms |
5220 KB |
Output is correct |
38 |
Correct |
83 ms |
5120 KB |
Output is correct |
39 |
Correct |
84 ms |
5160 KB |
Output is correct |
40 |
Correct |
84 ms |
5284 KB |
Output is correct |
41 |
Correct |
38 ms |
2640 KB |
Output is correct |
42 |
Correct |
43 ms |
2848 KB |
Output is correct |
43 |
Correct |
42 ms |
2756 KB |
Output is correct |
44 |
Correct |
37 ms |
2628 KB |
Output is correct |
45 |
Correct |
43 ms |
2740 KB |
Output is correct |
46 |
Correct |
40 ms |
2640 KB |
Output is correct |
47 |
Correct |
41 ms |
2748 KB |
Output is correct |
48 |
Correct |
46 ms |
2796 KB |
Output is correct |
49 |
Correct |
39 ms |
2628 KB |
Output is correct |
50 |
Correct |
40 ms |
2764 KB |
Output is correct |
51 |
Correct |
91 ms |
5060 KB |
Output is correct |
52 |
Correct |
98 ms |
4828 KB |
Output is correct |
53 |
Correct |
95 ms |
5060 KB |
Output is correct |
54 |
Correct |
94 ms |
4808 KB |
Output is correct |
55 |
Correct |
88 ms |
5020 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 |
1228 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 |
1 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 |
2 ms |
1356 KB |
Output is correct |
26 |
Correct |
45 ms |
2788 KB |
Output is correct |
27 |
Correct |
45 ms |
2848 KB |
Output is correct |
28 |
Correct |
44 ms |
2744 KB |
Output is correct |
29 |
Correct |
42 ms |
2732 KB |
Output is correct |
30 |
Correct |
40 ms |
2720 KB |
Output is correct |
31 |
Correct |
79 ms |
5144 KB |
Output is correct |
32 |
Correct |
82 ms |
5264 KB |
Output is correct |
33 |
Correct |
86 ms |
5184 KB |
Output is correct |
34 |
Correct |
79 ms |
5220 KB |
Output is correct |
35 |
Correct |
76 ms |
5164 KB |
Output is correct |
36 |
Correct |
83 ms |
5052 KB |
Output is correct |
37 |
Correct |
93 ms |
5220 KB |
Output is correct |
38 |
Correct |
83 ms |
5120 KB |
Output is correct |
39 |
Correct |
84 ms |
5160 KB |
Output is correct |
40 |
Correct |
84 ms |
5284 KB |
Output is correct |
41 |
Correct |
38 ms |
2640 KB |
Output is correct |
42 |
Correct |
43 ms |
2848 KB |
Output is correct |
43 |
Correct |
42 ms |
2756 KB |
Output is correct |
44 |
Correct |
37 ms |
2628 KB |
Output is correct |
45 |
Correct |
43 ms |
2740 KB |
Output is correct |
46 |
Correct |
40 ms |
2640 KB |
Output is correct |
47 |
Correct |
41 ms |
2748 KB |
Output is correct |
48 |
Correct |
46 ms |
2796 KB |
Output is correct |
49 |
Correct |
39 ms |
2628 KB |
Output is correct |
50 |
Correct |
40 ms |
2764 KB |
Output is correct |
51 |
Correct |
91 ms |
5060 KB |
Output is correct |
52 |
Correct |
98 ms |
4828 KB |
Output is correct |
53 |
Correct |
95 ms |
5060 KB |
Output is correct |
54 |
Correct |
94 ms |
4808 KB |
Output is correct |
55 |
Correct |
88 ms |
5020 KB |
Output is correct |
56 |
Execution timed out |
1031 ms |
38984 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |