Submission #572437

# Submission time Handle Problem Language Result Execution time Memory
572437 2022-06-04T11:30:10 Z PiejanVDC Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 76132 KB
#include <bits/stdc++.h>
using namespace std;

vector<int>par((int)1e6+5);
vector<long long>sz((int)1e6+5);

int UF(int u) {
  if(par[u] == u) return u;
  return par[u] = UF(par[u]);
}

signed main() {
  int n,q; cin>>n>>q;
  vector<int>v(n);
  for(int i = 0 ; i < n ; i++)
    par[i] = i, sz[i] = 1;
  vector<vector<int>>p((int)1e6+1);
  int X = 0;
  for(auto &z : v) {
    cin>>z;
    p[z].push_back(X);
    X++;
  }
  auto f = [&] (long long X) -> long long {
    return (X * (X+1))/2;
  };
  vector<long long>Q((int)1e6+5);
  long long ans = 0;
  for(int i = 1 ; i <= (int)1e6 ; i++) {
    for(auto z : p[i]) {
      if(z != 0 && UF(z-1) != UF(z) && v[z-1] <= i) {
        int A = UF(z-1), B = UF(z);
        ans -= f(sz[A]);
        ans += f(sz[A] + sz[B]);
        par[A] = B;
        sz[B] += sz[A];
        sz[A] = 0;
      } else ans++;
      if(z != n-1 && UF(z) != UF(z+1) && v[z+1] < i) {
        int A = UF(z), B = UF(z+1);
        ans -= f(sz[A]) + f(sz[B]);
        ans += f(sz[A] + sz[B]);
        par[A] = B;
        sz[B] += sz[A];
        sz[A] = 0;
      }
    }
    Q[i] = ans;
  }
  while(q--) {
    int h; cin>>h;
    cout << Q[h] << '\n';
  }
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43340 KB Output is correct
2 Correct 25 ms 43376 KB Output is correct
3 Correct 24 ms 43284 KB Output is correct
4 Correct 24 ms 43284 KB Output is correct
5 Correct 25 ms 43348 KB Output is correct
6 Correct 23 ms 43376 KB Output is correct
7 Correct 24 ms 43292 KB Output is correct
8 Correct 28 ms 43284 KB Output is correct
9 Correct 27 ms 43288 KB Output is correct
10 Correct 25 ms 43348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43340 KB Output is correct
2 Correct 25 ms 43376 KB Output is correct
3 Correct 24 ms 43284 KB Output is correct
4 Correct 24 ms 43284 KB Output is correct
5 Correct 25 ms 43348 KB Output is correct
6 Correct 23 ms 43376 KB Output is correct
7 Correct 24 ms 43292 KB Output is correct
8 Correct 28 ms 43284 KB Output is correct
9 Correct 27 ms 43288 KB Output is correct
10 Correct 25 ms 43348 KB Output is correct
11 Correct 26 ms 43288 KB Output is correct
12 Correct 24 ms 43368 KB Output is correct
13 Correct 24 ms 43340 KB Output is correct
14 Correct 23 ms 43348 KB Output is correct
15 Correct 27 ms 43340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43340 KB Output is correct
2 Correct 25 ms 43376 KB Output is correct
3 Correct 24 ms 43284 KB Output is correct
4 Correct 24 ms 43284 KB Output is correct
5 Correct 25 ms 43348 KB Output is correct
6 Correct 23 ms 43376 KB Output is correct
7 Correct 24 ms 43292 KB Output is correct
8 Correct 28 ms 43284 KB Output is correct
9 Correct 27 ms 43288 KB Output is correct
10 Correct 25 ms 43348 KB Output is correct
11 Correct 26 ms 43288 KB Output is correct
12 Correct 24 ms 43368 KB Output is correct
13 Correct 24 ms 43340 KB Output is correct
14 Correct 23 ms 43348 KB Output is correct
15 Correct 27 ms 43340 KB Output is correct
16 Correct 24 ms 43312 KB Output is correct
17 Correct 24 ms 43376 KB Output is correct
18 Correct 25 ms 43332 KB Output is correct
19 Correct 25 ms 43256 KB Output is correct
20 Correct 26 ms 43296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43340 KB Output is correct
2 Correct 25 ms 43376 KB Output is correct
3 Correct 24 ms 43284 KB Output is correct
4 Correct 24 ms 43284 KB Output is correct
5 Correct 25 ms 43348 KB Output is correct
6 Correct 23 ms 43376 KB Output is correct
7 Correct 24 ms 43292 KB Output is correct
8 Correct 28 ms 43284 KB Output is correct
9 Correct 27 ms 43288 KB Output is correct
10 Correct 25 ms 43348 KB Output is correct
11 Correct 26 ms 43288 KB Output is correct
12 Correct 24 ms 43368 KB Output is correct
13 Correct 24 ms 43340 KB Output is correct
14 Correct 23 ms 43348 KB Output is correct
15 Correct 27 ms 43340 KB Output is correct
16 Correct 24 ms 43312 KB Output is correct
17 Correct 24 ms 43376 KB Output is correct
18 Correct 25 ms 43332 KB Output is correct
19 Correct 25 ms 43256 KB Output is correct
20 Correct 26 ms 43296 KB Output is correct
21 Correct 25 ms 43388 KB Output is correct
22 Correct 27 ms 43288 KB Output is correct
23 Correct 25 ms 43384 KB Output is correct
24 Correct 27 ms 43412 KB Output is correct
25 Correct 26 ms 43300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 45756 KB Output is correct
2 Correct 108 ms 46844 KB Output is correct
3 Correct 68 ms 45684 KB Output is correct
4 Correct 79 ms 46676 KB Output is correct
5 Correct 61 ms 45704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 206 ms 47780 KB Output is correct
2 Correct 229 ms 47856 KB Output is correct
3 Correct 218 ms 47592 KB Output is correct
4 Correct 212 ms 47792 KB Output is correct
5 Correct 208 ms 47688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 224 ms 47992 KB Output is correct
2 Correct 218 ms 47692 KB Output is correct
3 Correct 215 ms 47576 KB Output is correct
4 Correct 215 ms 47928 KB Output is correct
5 Correct 230 ms 47684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43340 KB Output is correct
2 Correct 25 ms 43376 KB Output is correct
3 Correct 24 ms 43284 KB Output is correct
4 Correct 24 ms 43284 KB Output is correct
5 Correct 25 ms 43348 KB Output is correct
6 Correct 23 ms 43376 KB Output is correct
7 Correct 24 ms 43292 KB Output is correct
8 Correct 28 ms 43284 KB Output is correct
9 Correct 27 ms 43288 KB Output is correct
10 Correct 25 ms 43348 KB Output is correct
11 Correct 74 ms 45756 KB Output is correct
12 Correct 108 ms 46844 KB Output is correct
13 Correct 68 ms 45684 KB Output is correct
14 Correct 79 ms 46676 KB Output is correct
15 Correct 61 ms 45704 KB Output is correct
16 Correct 70 ms 45644 KB Output is correct
17 Correct 94 ms 46868 KB Output is correct
18 Correct 80 ms 46808 KB Output is correct
19 Correct 62 ms 45748 KB Output is correct
20 Correct 79 ms 46788 KB Output is correct
21 Correct 74 ms 45680 KB Output is correct
22 Correct 85 ms 46716 KB Output is correct
23 Correct 64 ms 45880 KB Output is correct
24 Correct 85 ms 46680 KB Output is correct
25 Correct 72 ms 45908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43340 KB Output is correct
2 Correct 25 ms 43376 KB Output is correct
3 Correct 24 ms 43284 KB Output is correct
4 Correct 24 ms 43284 KB Output is correct
5 Correct 25 ms 43348 KB Output is correct
6 Correct 23 ms 43376 KB Output is correct
7 Correct 24 ms 43292 KB Output is correct
8 Correct 28 ms 43284 KB Output is correct
9 Correct 27 ms 43288 KB Output is correct
10 Correct 25 ms 43348 KB Output is correct
11 Correct 26 ms 43288 KB Output is correct
12 Correct 24 ms 43368 KB Output is correct
13 Correct 24 ms 43340 KB Output is correct
14 Correct 23 ms 43348 KB Output is correct
15 Correct 27 ms 43340 KB Output is correct
16 Correct 24 ms 43312 KB Output is correct
17 Correct 24 ms 43376 KB Output is correct
18 Correct 25 ms 43332 KB Output is correct
19 Correct 25 ms 43256 KB Output is correct
20 Correct 26 ms 43296 KB Output is correct
21 Correct 25 ms 43388 KB Output is correct
22 Correct 27 ms 43288 KB Output is correct
23 Correct 25 ms 43384 KB Output is correct
24 Correct 27 ms 43412 KB Output is correct
25 Correct 26 ms 43300 KB Output is correct
26 Correct 74 ms 45756 KB Output is correct
27 Correct 108 ms 46844 KB Output is correct
28 Correct 68 ms 45684 KB Output is correct
29 Correct 79 ms 46676 KB Output is correct
30 Correct 61 ms 45704 KB Output is correct
31 Correct 206 ms 47780 KB Output is correct
32 Correct 229 ms 47856 KB Output is correct
33 Correct 218 ms 47592 KB Output is correct
34 Correct 212 ms 47792 KB Output is correct
35 Correct 208 ms 47688 KB Output is correct
36 Correct 224 ms 47992 KB Output is correct
37 Correct 218 ms 47692 KB Output is correct
38 Correct 215 ms 47576 KB Output is correct
39 Correct 215 ms 47928 KB Output is correct
40 Correct 230 ms 47684 KB Output is correct
41 Correct 70 ms 45644 KB Output is correct
42 Correct 94 ms 46868 KB Output is correct
43 Correct 80 ms 46808 KB Output is correct
44 Correct 62 ms 45748 KB Output is correct
45 Correct 79 ms 46788 KB Output is correct
46 Correct 74 ms 45680 KB Output is correct
47 Correct 85 ms 46716 KB Output is correct
48 Correct 64 ms 45880 KB Output is correct
49 Correct 85 ms 46680 KB Output is correct
50 Correct 72 ms 45908 KB Output is correct
51 Correct 235 ms 46956 KB Output is correct
52 Correct 230 ms 48404 KB Output is correct
53 Correct 224 ms 47692 KB Output is correct
54 Correct 246 ms 48392 KB Output is correct
55 Correct 214 ms 47552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43340 KB Output is correct
2 Correct 25 ms 43376 KB Output is correct
3 Correct 24 ms 43284 KB Output is correct
4 Correct 24 ms 43284 KB Output is correct
5 Correct 25 ms 43348 KB Output is correct
6 Correct 23 ms 43376 KB Output is correct
7 Correct 24 ms 43292 KB Output is correct
8 Correct 28 ms 43284 KB Output is correct
9 Correct 27 ms 43288 KB Output is correct
10 Correct 25 ms 43348 KB Output is correct
11 Correct 26 ms 43288 KB Output is correct
12 Correct 24 ms 43368 KB Output is correct
13 Correct 24 ms 43340 KB Output is correct
14 Correct 23 ms 43348 KB Output is correct
15 Correct 27 ms 43340 KB Output is correct
16 Correct 24 ms 43312 KB Output is correct
17 Correct 24 ms 43376 KB Output is correct
18 Correct 25 ms 43332 KB Output is correct
19 Correct 25 ms 43256 KB Output is correct
20 Correct 26 ms 43296 KB Output is correct
21 Correct 25 ms 43388 KB Output is correct
22 Correct 27 ms 43288 KB Output is correct
23 Correct 25 ms 43384 KB Output is correct
24 Correct 27 ms 43412 KB Output is correct
25 Correct 26 ms 43300 KB Output is correct
26 Correct 74 ms 45756 KB Output is correct
27 Correct 108 ms 46844 KB Output is correct
28 Correct 68 ms 45684 KB Output is correct
29 Correct 79 ms 46676 KB Output is correct
30 Correct 61 ms 45704 KB Output is correct
31 Correct 206 ms 47780 KB Output is correct
32 Correct 229 ms 47856 KB Output is correct
33 Correct 218 ms 47592 KB Output is correct
34 Correct 212 ms 47792 KB Output is correct
35 Correct 208 ms 47688 KB Output is correct
36 Correct 224 ms 47992 KB Output is correct
37 Correct 218 ms 47692 KB Output is correct
38 Correct 215 ms 47576 KB Output is correct
39 Correct 215 ms 47928 KB Output is correct
40 Correct 230 ms 47684 KB Output is correct
41 Correct 70 ms 45644 KB Output is correct
42 Correct 94 ms 46868 KB Output is correct
43 Correct 80 ms 46808 KB Output is correct
44 Correct 62 ms 45748 KB Output is correct
45 Correct 79 ms 46788 KB Output is correct
46 Correct 74 ms 45680 KB Output is correct
47 Correct 85 ms 46716 KB Output is correct
48 Correct 64 ms 45880 KB Output is correct
49 Correct 85 ms 46680 KB Output is correct
50 Correct 72 ms 45908 KB Output is correct
51 Correct 235 ms 46956 KB Output is correct
52 Correct 230 ms 48404 KB Output is correct
53 Correct 224 ms 47692 KB Output is correct
54 Correct 246 ms 48392 KB Output is correct
55 Correct 214 ms 47552 KB Output is correct
56 Execution timed out 1085 ms 76132 KB Time limit exceeded
57 Halted 0 ms 0 KB -