# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
895891 |
2023-12-31T03:19:56 Z |
kh0i |
Pilot (NOI19_pilot) |
C++17 |
|
472 ms |
88628 KB |
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 1e6 + 3;
int n, q, h[N], y[N];
namespace Sub12348{
bool valid_input() { return n * q <= 1e7; }
void solve(){
for(int t = 1; t <= q; ++t){
ll cur = 0, res = 0;
for(int i = 1; i <= n; ++i){
if(h[i] <= y[t])
++cur;
else{
res += cur * (cur + 1) / 2;
cur = 0;
}
}
res += cur * (cur + 1) / 2;
cout << res << '\n';
}
}
}
namespace Sub5{
bool valid_input(){ return q == 1 and y[1] == 1e6; }
void solve() { cout << 1ll * n * (n + 1) / 2; }
}
namespace Sub67{
bool valid_input(){
bool ok = 1;
for(int i = 2; i <= n; ++i)
ok &= (h[i] > h[i - 1]);
return ok;
}
void solve(){
for(int t = 1; t <= q; ++t){
ll x = upper_bound(h + 1, h + n + 1, y[t]) - h;
cout << x * (x + 1) / 2 << '\n';
}
}
}
struct DSU{
vector<ll> p;
ll cur;
void init(int n){
p.resize(n + 2, 0);
cur = 0;
}
ll calc(ll x) { return x * (x + 1) / 2; }
void make_set(int u){
++cur;
p[u] = -1;
}
int find_set(int u) { return p[u] < 0 ? u : p[u] = find_set(p[u]); }
void join_sets(int u, int v){
u = find_set(u);
v = find_set(v);
if(u == v)
return;
cur -= calc(-p[u]);
cur -= calc(-p[v]);
if(p[u] > p[v])
swap(u, v);
p[u] += p[v];
p[v] = u;
cur += calc(-p[u]);
}
} dsu;
bool ok[N];
vector<int> to_add[N];
ll res[N];
namespace SubFull{
void solve(){
dsu.init(N);
for(int i = 1; i <= n; ++i)
to_add[h[i]].push_back(i);
for(int i = 1; i < N; ++i){
for(int j = 0; j < (int)to_add[i].size(); ++j){
int x = to_add[i][j];
dsu.make_set(x);
if(ok[x - 1])
dsu.join_sets(x - 1, x);
if(ok[x + 1])
dsu.join_sets(x, x + 1);
ok[x] = 1;
}
res[i] = dsu.cur;
}
for(int i = 1; i <= q; ++i)
cout << res[y[i]] << '\n';
}
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> q;
for(int i = 1; i <= n; ++i)
cin >> h[i];
for(int i = 1; i <= q; ++i)
cin >> y[i];
SubFull::solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
43352 KB |
Output is correct |
2 |
Correct |
11 ms |
43356 KB |
Output is correct |
3 |
Correct |
11 ms |
43356 KB |
Output is correct |
4 |
Correct |
10 ms |
43356 KB |
Output is correct |
5 |
Correct |
10 ms |
43608 KB |
Output is correct |
6 |
Correct |
10 ms |
43336 KB |
Output is correct |
7 |
Correct |
10 ms |
43100 KB |
Output is correct |
8 |
Correct |
10 ms |
43356 KB |
Output is correct |
9 |
Correct |
10 ms |
43356 KB |
Output is correct |
10 |
Correct |
10 ms |
43100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
43352 KB |
Output is correct |
2 |
Correct |
11 ms |
43356 KB |
Output is correct |
3 |
Correct |
11 ms |
43356 KB |
Output is correct |
4 |
Correct |
10 ms |
43356 KB |
Output is correct |
5 |
Correct |
10 ms |
43608 KB |
Output is correct |
6 |
Correct |
10 ms |
43336 KB |
Output is correct |
7 |
Correct |
10 ms |
43100 KB |
Output is correct |
8 |
Correct |
10 ms |
43356 KB |
Output is correct |
9 |
Correct |
10 ms |
43356 KB |
Output is correct |
10 |
Correct |
10 ms |
43100 KB |
Output is correct |
11 |
Correct |
11 ms |
43356 KB |
Output is correct |
12 |
Correct |
10 ms |
43356 KB |
Output is correct |
13 |
Correct |
11 ms |
43100 KB |
Output is correct |
14 |
Correct |
12 ms |
43100 KB |
Output is correct |
15 |
Correct |
10 ms |
43100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
43352 KB |
Output is correct |
2 |
Correct |
11 ms |
43356 KB |
Output is correct |
3 |
Correct |
11 ms |
43356 KB |
Output is correct |
4 |
Correct |
10 ms |
43356 KB |
Output is correct |
5 |
Correct |
10 ms |
43608 KB |
Output is correct |
6 |
Correct |
10 ms |
43336 KB |
Output is correct |
7 |
Correct |
10 ms |
43100 KB |
Output is correct |
8 |
Correct |
10 ms |
43356 KB |
Output is correct |
9 |
Correct |
10 ms |
43356 KB |
Output is correct |
10 |
Correct |
10 ms |
43100 KB |
Output is correct |
11 |
Correct |
11 ms |
43356 KB |
Output is correct |
12 |
Correct |
10 ms |
43356 KB |
Output is correct |
13 |
Correct |
11 ms |
43100 KB |
Output is correct |
14 |
Correct |
12 ms |
43100 KB |
Output is correct |
15 |
Correct |
10 ms |
43100 KB |
Output is correct |
16 |
Correct |
11 ms |
43352 KB |
Output is correct |
17 |
Correct |
10 ms |
43356 KB |
Output is correct |
18 |
Correct |
10 ms |
43196 KB |
Output is correct |
19 |
Correct |
11 ms |
43304 KB |
Output is correct |
20 |
Correct |
11 ms |
43100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
43352 KB |
Output is correct |
2 |
Correct |
11 ms |
43356 KB |
Output is correct |
3 |
Correct |
11 ms |
43356 KB |
Output is correct |
4 |
Correct |
10 ms |
43356 KB |
Output is correct |
5 |
Correct |
10 ms |
43608 KB |
Output is correct |
6 |
Correct |
10 ms |
43336 KB |
Output is correct |
7 |
Correct |
10 ms |
43100 KB |
Output is correct |
8 |
Correct |
10 ms |
43356 KB |
Output is correct |
9 |
Correct |
10 ms |
43356 KB |
Output is correct |
10 |
Correct |
10 ms |
43100 KB |
Output is correct |
11 |
Correct |
11 ms |
43356 KB |
Output is correct |
12 |
Correct |
10 ms |
43356 KB |
Output is correct |
13 |
Correct |
11 ms |
43100 KB |
Output is correct |
14 |
Correct |
12 ms |
43100 KB |
Output is correct |
15 |
Correct |
10 ms |
43100 KB |
Output is correct |
16 |
Correct |
11 ms |
43352 KB |
Output is correct |
17 |
Correct |
10 ms |
43356 KB |
Output is correct |
18 |
Correct |
10 ms |
43196 KB |
Output is correct |
19 |
Correct |
11 ms |
43304 KB |
Output is correct |
20 |
Correct |
11 ms |
43100 KB |
Output is correct |
21 |
Correct |
11 ms |
43356 KB |
Output is correct |
22 |
Correct |
10 ms |
43352 KB |
Output is correct |
23 |
Correct |
12 ms |
43404 KB |
Output is correct |
24 |
Correct |
10 ms |
43356 KB |
Output is correct |
25 |
Correct |
11 ms |
43356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
45148 KB |
Output is correct |
2 |
Correct |
44 ms |
46064 KB |
Output is correct |
3 |
Correct |
27 ms |
45188 KB |
Output is correct |
4 |
Correct |
37 ms |
45828 KB |
Output is correct |
5 |
Correct |
26 ms |
45148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
47196 KB |
Output is correct |
2 |
Correct |
35 ms |
48212 KB |
Output is correct |
3 |
Correct |
35 ms |
48208 KB |
Output is correct |
4 |
Correct |
41 ms |
48468 KB |
Output is correct |
5 |
Correct |
41 ms |
48212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
47188 KB |
Output is correct |
2 |
Correct |
41 ms |
48348 KB |
Output is correct |
3 |
Correct |
40 ms |
48212 KB |
Output is correct |
4 |
Correct |
39 ms |
48520 KB |
Output is correct |
5 |
Correct |
50 ms |
48496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
43352 KB |
Output is correct |
2 |
Correct |
11 ms |
43356 KB |
Output is correct |
3 |
Correct |
11 ms |
43356 KB |
Output is correct |
4 |
Correct |
10 ms |
43356 KB |
Output is correct |
5 |
Correct |
10 ms |
43608 KB |
Output is correct |
6 |
Correct |
10 ms |
43336 KB |
Output is correct |
7 |
Correct |
10 ms |
43100 KB |
Output is correct |
8 |
Correct |
10 ms |
43356 KB |
Output is correct |
9 |
Correct |
10 ms |
43356 KB |
Output is correct |
10 |
Correct |
10 ms |
43100 KB |
Output is correct |
11 |
Correct |
26 ms |
45148 KB |
Output is correct |
12 |
Correct |
44 ms |
46064 KB |
Output is correct |
13 |
Correct |
27 ms |
45188 KB |
Output is correct |
14 |
Correct |
37 ms |
45828 KB |
Output is correct |
15 |
Correct |
26 ms |
45148 KB |
Output is correct |
16 |
Correct |
25 ms |
45148 KB |
Output is correct |
17 |
Correct |
39 ms |
46036 KB |
Output is correct |
18 |
Correct |
43 ms |
46160 KB |
Output is correct |
19 |
Correct |
25 ms |
45148 KB |
Output is correct |
20 |
Correct |
36 ms |
46072 KB |
Output is correct |
21 |
Correct |
24 ms |
45148 KB |
Output is correct |
22 |
Correct |
36 ms |
45904 KB |
Output is correct |
23 |
Correct |
32 ms |
45140 KB |
Output is correct |
24 |
Correct |
43 ms |
45916 KB |
Output is correct |
25 |
Correct |
26 ms |
45136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
43352 KB |
Output is correct |
2 |
Correct |
11 ms |
43356 KB |
Output is correct |
3 |
Correct |
11 ms |
43356 KB |
Output is correct |
4 |
Correct |
10 ms |
43356 KB |
Output is correct |
5 |
Correct |
10 ms |
43608 KB |
Output is correct |
6 |
Correct |
10 ms |
43336 KB |
Output is correct |
7 |
Correct |
10 ms |
43100 KB |
Output is correct |
8 |
Correct |
10 ms |
43356 KB |
Output is correct |
9 |
Correct |
10 ms |
43356 KB |
Output is correct |
10 |
Correct |
10 ms |
43100 KB |
Output is correct |
11 |
Correct |
11 ms |
43356 KB |
Output is correct |
12 |
Correct |
10 ms |
43356 KB |
Output is correct |
13 |
Correct |
11 ms |
43100 KB |
Output is correct |
14 |
Correct |
12 ms |
43100 KB |
Output is correct |
15 |
Correct |
10 ms |
43100 KB |
Output is correct |
16 |
Correct |
11 ms |
43352 KB |
Output is correct |
17 |
Correct |
10 ms |
43356 KB |
Output is correct |
18 |
Correct |
10 ms |
43196 KB |
Output is correct |
19 |
Correct |
11 ms |
43304 KB |
Output is correct |
20 |
Correct |
11 ms |
43100 KB |
Output is correct |
21 |
Correct |
11 ms |
43356 KB |
Output is correct |
22 |
Correct |
10 ms |
43352 KB |
Output is correct |
23 |
Correct |
12 ms |
43404 KB |
Output is correct |
24 |
Correct |
10 ms |
43356 KB |
Output is correct |
25 |
Correct |
11 ms |
43356 KB |
Output is correct |
26 |
Correct |
26 ms |
45148 KB |
Output is correct |
27 |
Correct |
44 ms |
46064 KB |
Output is correct |
28 |
Correct |
27 ms |
45188 KB |
Output is correct |
29 |
Correct |
37 ms |
45828 KB |
Output is correct |
30 |
Correct |
26 ms |
45148 KB |
Output is correct |
31 |
Correct |
36 ms |
47196 KB |
Output is correct |
32 |
Correct |
35 ms |
48212 KB |
Output is correct |
33 |
Correct |
35 ms |
48208 KB |
Output is correct |
34 |
Correct |
41 ms |
48468 KB |
Output is correct |
35 |
Correct |
41 ms |
48212 KB |
Output is correct |
36 |
Correct |
39 ms |
47188 KB |
Output is correct |
37 |
Correct |
41 ms |
48348 KB |
Output is correct |
38 |
Correct |
40 ms |
48212 KB |
Output is correct |
39 |
Correct |
39 ms |
48520 KB |
Output is correct |
40 |
Correct |
50 ms |
48496 KB |
Output is correct |
41 |
Correct |
25 ms |
45148 KB |
Output is correct |
42 |
Correct |
39 ms |
46036 KB |
Output is correct |
43 |
Correct |
43 ms |
46160 KB |
Output is correct |
44 |
Correct |
25 ms |
45148 KB |
Output is correct |
45 |
Correct |
36 ms |
46072 KB |
Output is correct |
46 |
Correct |
24 ms |
45148 KB |
Output is correct |
47 |
Correct |
36 ms |
45904 KB |
Output is correct |
48 |
Correct |
32 ms |
45140 KB |
Output is correct |
49 |
Correct |
43 ms |
45916 KB |
Output is correct |
50 |
Correct |
26 ms |
45136 KB |
Output is correct |
51 |
Correct |
40 ms |
47220 KB |
Output is correct |
52 |
Correct |
53 ms |
47952 KB |
Output is correct |
53 |
Correct |
40 ms |
47188 KB |
Output is correct |
54 |
Correct |
62 ms |
47944 KB |
Output is correct |
55 |
Correct |
40 ms |
47184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
43352 KB |
Output is correct |
2 |
Correct |
11 ms |
43356 KB |
Output is correct |
3 |
Correct |
11 ms |
43356 KB |
Output is correct |
4 |
Correct |
10 ms |
43356 KB |
Output is correct |
5 |
Correct |
10 ms |
43608 KB |
Output is correct |
6 |
Correct |
10 ms |
43336 KB |
Output is correct |
7 |
Correct |
10 ms |
43100 KB |
Output is correct |
8 |
Correct |
10 ms |
43356 KB |
Output is correct |
9 |
Correct |
10 ms |
43356 KB |
Output is correct |
10 |
Correct |
10 ms |
43100 KB |
Output is correct |
11 |
Correct |
11 ms |
43356 KB |
Output is correct |
12 |
Correct |
10 ms |
43356 KB |
Output is correct |
13 |
Correct |
11 ms |
43100 KB |
Output is correct |
14 |
Correct |
12 ms |
43100 KB |
Output is correct |
15 |
Correct |
10 ms |
43100 KB |
Output is correct |
16 |
Correct |
11 ms |
43352 KB |
Output is correct |
17 |
Correct |
10 ms |
43356 KB |
Output is correct |
18 |
Correct |
10 ms |
43196 KB |
Output is correct |
19 |
Correct |
11 ms |
43304 KB |
Output is correct |
20 |
Correct |
11 ms |
43100 KB |
Output is correct |
21 |
Correct |
11 ms |
43356 KB |
Output is correct |
22 |
Correct |
10 ms |
43352 KB |
Output is correct |
23 |
Correct |
12 ms |
43404 KB |
Output is correct |
24 |
Correct |
10 ms |
43356 KB |
Output is correct |
25 |
Correct |
11 ms |
43356 KB |
Output is correct |
26 |
Correct |
26 ms |
45148 KB |
Output is correct |
27 |
Correct |
44 ms |
46064 KB |
Output is correct |
28 |
Correct |
27 ms |
45188 KB |
Output is correct |
29 |
Correct |
37 ms |
45828 KB |
Output is correct |
30 |
Correct |
26 ms |
45148 KB |
Output is correct |
31 |
Correct |
36 ms |
47196 KB |
Output is correct |
32 |
Correct |
35 ms |
48212 KB |
Output is correct |
33 |
Correct |
35 ms |
48208 KB |
Output is correct |
34 |
Correct |
41 ms |
48468 KB |
Output is correct |
35 |
Correct |
41 ms |
48212 KB |
Output is correct |
36 |
Correct |
39 ms |
47188 KB |
Output is correct |
37 |
Correct |
41 ms |
48348 KB |
Output is correct |
38 |
Correct |
40 ms |
48212 KB |
Output is correct |
39 |
Correct |
39 ms |
48520 KB |
Output is correct |
40 |
Correct |
50 ms |
48496 KB |
Output is correct |
41 |
Correct |
25 ms |
45148 KB |
Output is correct |
42 |
Correct |
39 ms |
46036 KB |
Output is correct |
43 |
Correct |
43 ms |
46160 KB |
Output is correct |
44 |
Correct |
25 ms |
45148 KB |
Output is correct |
45 |
Correct |
36 ms |
46072 KB |
Output is correct |
46 |
Correct |
24 ms |
45148 KB |
Output is correct |
47 |
Correct |
36 ms |
45904 KB |
Output is correct |
48 |
Correct |
32 ms |
45140 KB |
Output is correct |
49 |
Correct |
43 ms |
45916 KB |
Output is correct |
50 |
Correct |
26 ms |
45136 KB |
Output is correct |
51 |
Correct |
40 ms |
47220 KB |
Output is correct |
52 |
Correct |
53 ms |
47952 KB |
Output is correct |
53 |
Correct |
40 ms |
47188 KB |
Output is correct |
54 |
Correct |
62 ms |
47944 KB |
Output is correct |
55 |
Correct |
40 ms |
47184 KB |
Output is correct |
56 |
Correct |
472 ms |
87164 KB |
Output is correct |
57 |
Correct |
436 ms |
87944 KB |
Output is correct |
58 |
Correct |
405 ms |
85224 KB |
Output is correct |
59 |
Correct |
440 ms |
86756 KB |
Output is correct |
60 |
Correct |
446 ms |
88628 KB |
Output is correct |