Submission #572448

# Submission time Handle Problem Language Result Execution time Memory
572448 2022-06-04T11:50:56 Z PiejanVDC Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 68904 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[B] = A;
        sz[A] += sz[B];
        sz[B] = 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]);
        if(sz[A] < sz[B]) {
          par[A] = B;
          sz[B] += sz[A];
          sz[A] = 0;
        } else {
          par[B] = A;
          sz[A] += sz[B];
          sz[B] = 0;
        }
      }
    }
    Q[i] = ans;
  }
  while(q--) {
    int h; cin>>h;
    cout << Q[h] << '\n';
  }
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43348 KB Output is correct
2 Correct 22 ms 43268 KB Output is correct
3 Correct 21 ms 43356 KB Output is correct
4 Correct 24 ms 43476 KB Output is correct
5 Correct 22 ms 43340 KB Output is correct
6 Correct 23 ms 43348 KB Output is correct
7 Correct 22 ms 43348 KB Output is correct
8 Correct 22 ms 43348 KB Output is correct
9 Correct 22 ms 43288 KB Output is correct
10 Correct 23 ms 43324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43348 KB Output is correct
2 Correct 22 ms 43268 KB Output is correct
3 Correct 21 ms 43356 KB Output is correct
4 Correct 24 ms 43476 KB Output is correct
5 Correct 22 ms 43340 KB Output is correct
6 Correct 23 ms 43348 KB Output is correct
7 Correct 22 ms 43348 KB Output is correct
8 Correct 22 ms 43348 KB Output is correct
9 Correct 22 ms 43288 KB Output is correct
10 Correct 23 ms 43324 KB Output is correct
11 Correct 22 ms 43316 KB Output is correct
12 Correct 22 ms 43356 KB Output is correct
13 Correct 24 ms 43348 KB Output is correct
14 Correct 23 ms 43348 KB Output is correct
15 Correct 23 ms 43320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43348 KB Output is correct
2 Correct 22 ms 43268 KB Output is correct
3 Correct 21 ms 43356 KB Output is correct
4 Correct 24 ms 43476 KB Output is correct
5 Correct 22 ms 43340 KB Output is correct
6 Correct 23 ms 43348 KB Output is correct
7 Correct 22 ms 43348 KB Output is correct
8 Correct 22 ms 43348 KB Output is correct
9 Correct 22 ms 43288 KB Output is correct
10 Correct 23 ms 43324 KB Output is correct
11 Correct 22 ms 43316 KB Output is correct
12 Correct 22 ms 43356 KB Output is correct
13 Correct 24 ms 43348 KB Output is correct
14 Correct 23 ms 43348 KB Output is correct
15 Correct 23 ms 43320 KB Output is correct
16 Correct 24 ms 43336 KB Output is correct
17 Correct 22 ms 43384 KB Output is correct
18 Correct 25 ms 43348 KB Output is correct
19 Correct 23 ms 43340 KB Output is correct
20 Correct 23 ms 43288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43348 KB Output is correct
2 Correct 22 ms 43268 KB Output is correct
3 Correct 21 ms 43356 KB Output is correct
4 Correct 24 ms 43476 KB Output is correct
5 Correct 22 ms 43340 KB Output is correct
6 Correct 23 ms 43348 KB Output is correct
7 Correct 22 ms 43348 KB Output is correct
8 Correct 22 ms 43348 KB Output is correct
9 Correct 22 ms 43288 KB Output is correct
10 Correct 23 ms 43324 KB Output is correct
11 Correct 22 ms 43316 KB Output is correct
12 Correct 22 ms 43356 KB Output is correct
13 Correct 24 ms 43348 KB Output is correct
14 Correct 23 ms 43348 KB Output is correct
15 Correct 23 ms 43320 KB Output is correct
16 Correct 24 ms 43336 KB Output is correct
17 Correct 22 ms 43384 KB Output is correct
18 Correct 25 ms 43348 KB Output is correct
19 Correct 23 ms 43340 KB Output is correct
20 Correct 23 ms 43288 KB Output is correct
21 Correct 31 ms 43348 KB Output is correct
22 Correct 25 ms 43428 KB Output is correct
23 Correct 26 ms 43300 KB Output is correct
24 Correct 25 ms 43300 KB Output is correct
25 Correct 26 ms 43392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 46316 KB Output is correct
2 Correct 86 ms 47332 KB Output is correct
3 Correct 64 ms 46016 KB Output is correct
4 Correct 81 ms 46924 KB Output is correct
5 Correct 58 ms 46076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 48692 KB Output is correct
2 Correct 220 ms 48336 KB Output is correct
3 Correct 196 ms 48308 KB Output is correct
4 Correct 204 ms 48424 KB Output is correct
5 Correct 194 ms 48256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 48792 KB Output is correct
2 Correct 204 ms 48224 KB Output is correct
3 Correct 220 ms 48132 KB Output is correct
4 Correct 207 ms 48416 KB Output is correct
5 Correct 212 ms 48364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43348 KB Output is correct
2 Correct 22 ms 43268 KB Output is correct
3 Correct 21 ms 43356 KB Output is correct
4 Correct 24 ms 43476 KB Output is correct
5 Correct 22 ms 43340 KB Output is correct
6 Correct 23 ms 43348 KB Output is correct
7 Correct 22 ms 43348 KB Output is correct
8 Correct 22 ms 43348 KB Output is correct
9 Correct 22 ms 43288 KB Output is correct
10 Correct 23 ms 43324 KB Output is correct
11 Correct 61 ms 46316 KB Output is correct
12 Correct 86 ms 47332 KB Output is correct
13 Correct 64 ms 46016 KB Output is correct
14 Correct 81 ms 46924 KB Output is correct
15 Correct 58 ms 46076 KB Output is correct
16 Correct 58 ms 46084 KB Output is correct
17 Correct 91 ms 47316 KB Output is correct
18 Correct 81 ms 47284 KB Output is correct
19 Correct 63 ms 45940 KB Output is correct
20 Correct 82 ms 47212 KB Output is correct
21 Correct 59 ms 45976 KB Output is correct
22 Correct 76 ms 47088 KB Output is correct
23 Correct 64 ms 46216 KB Output is correct
24 Correct 75 ms 47000 KB Output is correct
25 Correct 61 ms 46200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43348 KB Output is correct
2 Correct 22 ms 43268 KB Output is correct
3 Correct 21 ms 43356 KB Output is correct
4 Correct 24 ms 43476 KB Output is correct
5 Correct 22 ms 43340 KB Output is correct
6 Correct 23 ms 43348 KB Output is correct
7 Correct 22 ms 43348 KB Output is correct
8 Correct 22 ms 43348 KB Output is correct
9 Correct 22 ms 43288 KB Output is correct
10 Correct 23 ms 43324 KB Output is correct
11 Correct 22 ms 43316 KB Output is correct
12 Correct 22 ms 43356 KB Output is correct
13 Correct 24 ms 43348 KB Output is correct
14 Correct 23 ms 43348 KB Output is correct
15 Correct 23 ms 43320 KB Output is correct
16 Correct 24 ms 43336 KB Output is correct
17 Correct 22 ms 43384 KB Output is correct
18 Correct 25 ms 43348 KB Output is correct
19 Correct 23 ms 43340 KB Output is correct
20 Correct 23 ms 43288 KB Output is correct
21 Correct 31 ms 43348 KB Output is correct
22 Correct 25 ms 43428 KB Output is correct
23 Correct 26 ms 43300 KB Output is correct
24 Correct 25 ms 43300 KB Output is correct
25 Correct 26 ms 43392 KB Output is correct
26 Correct 61 ms 46316 KB Output is correct
27 Correct 86 ms 47332 KB Output is correct
28 Correct 64 ms 46016 KB Output is correct
29 Correct 81 ms 46924 KB Output is correct
30 Correct 58 ms 46076 KB Output is correct
31 Correct 215 ms 48692 KB Output is correct
32 Correct 220 ms 48336 KB Output is correct
33 Correct 196 ms 48308 KB Output is correct
34 Correct 204 ms 48424 KB Output is correct
35 Correct 194 ms 48256 KB Output is correct
36 Correct 203 ms 48792 KB Output is correct
37 Correct 204 ms 48224 KB Output is correct
38 Correct 220 ms 48132 KB Output is correct
39 Correct 207 ms 48416 KB Output is correct
40 Correct 212 ms 48364 KB Output is correct
41 Correct 58 ms 46084 KB Output is correct
42 Correct 91 ms 47316 KB Output is correct
43 Correct 81 ms 47284 KB Output is correct
44 Correct 63 ms 45940 KB Output is correct
45 Correct 82 ms 47212 KB Output is correct
46 Correct 59 ms 45976 KB Output is correct
47 Correct 76 ms 47088 KB Output is correct
48 Correct 64 ms 46216 KB Output is correct
49 Correct 75 ms 47000 KB Output is correct
50 Correct 61 ms 46200 KB Output is correct
51 Correct 210 ms 47512 KB Output is correct
52 Correct 233 ms 47712 KB Output is correct
53 Correct 216 ms 47028 KB Output is correct
54 Correct 221 ms 47656 KB Output is correct
55 Correct 202 ms 47040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 43348 KB Output is correct
2 Correct 22 ms 43268 KB Output is correct
3 Correct 21 ms 43356 KB Output is correct
4 Correct 24 ms 43476 KB Output is correct
5 Correct 22 ms 43340 KB Output is correct
6 Correct 23 ms 43348 KB Output is correct
7 Correct 22 ms 43348 KB Output is correct
8 Correct 22 ms 43348 KB Output is correct
9 Correct 22 ms 43288 KB Output is correct
10 Correct 23 ms 43324 KB Output is correct
11 Correct 22 ms 43316 KB Output is correct
12 Correct 22 ms 43356 KB Output is correct
13 Correct 24 ms 43348 KB Output is correct
14 Correct 23 ms 43348 KB Output is correct
15 Correct 23 ms 43320 KB Output is correct
16 Correct 24 ms 43336 KB Output is correct
17 Correct 22 ms 43384 KB Output is correct
18 Correct 25 ms 43348 KB Output is correct
19 Correct 23 ms 43340 KB Output is correct
20 Correct 23 ms 43288 KB Output is correct
21 Correct 31 ms 43348 KB Output is correct
22 Correct 25 ms 43428 KB Output is correct
23 Correct 26 ms 43300 KB Output is correct
24 Correct 25 ms 43300 KB Output is correct
25 Correct 26 ms 43392 KB Output is correct
26 Correct 61 ms 46316 KB Output is correct
27 Correct 86 ms 47332 KB Output is correct
28 Correct 64 ms 46016 KB Output is correct
29 Correct 81 ms 46924 KB Output is correct
30 Correct 58 ms 46076 KB Output is correct
31 Correct 215 ms 48692 KB Output is correct
32 Correct 220 ms 48336 KB Output is correct
33 Correct 196 ms 48308 KB Output is correct
34 Correct 204 ms 48424 KB Output is correct
35 Correct 194 ms 48256 KB Output is correct
36 Correct 203 ms 48792 KB Output is correct
37 Correct 204 ms 48224 KB Output is correct
38 Correct 220 ms 48132 KB Output is correct
39 Correct 207 ms 48416 KB Output is correct
40 Correct 212 ms 48364 KB Output is correct
41 Correct 58 ms 46084 KB Output is correct
42 Correct 91 ms 47316 KB Output is correct
43 Correct 81 ms 47284 KB Output is correct
44 Correct 63 ms 45940 KB Output is correct
45 Correct 82 ms 47212 KB Output is correct
46 Correct 59 ms 45976 KB Output is correct
47 Correct 76 ms 47088 KB Output is correct
48 Correct 64 ms 46216 KB Output is correct
49 Correct 75 ms 47000 KB Output is correct
50 Correct 61 ms 46200 KB Output is correct
51 Correct 210 ms 47512 KB Output is correct
52 Correct 233 ms 47712 KB Output is correct
53 Correct 216 ms 47028 KB Output is correct
54 Correct 221 ms 47656 KB Output is correct
55 Correct 202 ms 47040 KB Output is correct
56 Execution timed out 1049 ms 68904 KB Time limit exceeded
57 Halted 0 ms 0 KB -