Submission #1072129

# Submission time Handle Problem Language Result Execution time Memory
1072129 2024-08-23T14:44:27 Z FIFI_cpp Pilot (NOI19_pilot) C++17
100 / 100
683 ms 75352 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cctype>
#include <string>
#include <cassert>
#include <set>
#include <bitset>
#include <unordered_set>
using ll = int64_t;
#define pb push_back
#define all(a) a.begin(),a.end()
#define ppb pair<pair<int,int>,bool>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int int64_t
// xcode cant include bits/stdc++.h
using namespace std;
//ifstream fin ("sleepy.in");
//ofstream fout ("sleepy.out");
/*   /\_/\
*   (= ._.)
*   / >  \>
*/
// encouraging cat
const int INF = 1844674407370955161;
const int mod = 1000000007;
int parent[1000003];
int sz[1000003];
int curr = 0;
int find(int x)
{
    if (x != parent[x])
        return parent[x] = find(parent[x]);
    return x;
}
void onion(int a,int b)
{
    a = find(a);
    b = find(b);
    if (a == b)
        return;
    if (sz[a] < sz[b])
        swap(a,b);
    curr += sz[a] * sz[b];
    sz[a] += sz[b];
    parent[b] = a;
}
int32_t main() {
    int n,q;
    cin >> n >> q;
    vector<pair<int,int>> events;
    for (int i = 1;i <= n;i++)
    {
        int h;
        cin >> h;
        events.pb({h,-i});
    }
    for (int i = 1;i <= q;i++)
    {
        int h;
        cin >> h;
        events.pb({h,i});
    }
    sort(all(events));
    vector<int> res(q + 1,0);
    for (pair<int,int> i : events)
    {
        if (i.second > 0)
        {
            res[i.second] = curr;
        }
        else
        {
            curr++;
            int x = -i.second;
            parent[x] = x;
            sz[x] = 1;
            if (parent[x + 1])
            {
                onion(x,x + 1);
            }
            if (parent[x - 1])
            {
                onion(x,x - 1);
            }
        }
    }
    for (int i = 1;i <= q;i++)
    {
        cout << res[i] << '\n';
    }
    return 0;
}

Compilation message

pilot.cpp:32:9: warning: "/*" within comment [-Wcomment]
   32 | /*   /\_/\
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 4036 KB Output is correct
2 Correct 27 ms 4060 KB Output is correct
3 Correct 26 ms 4040 KB Output is correct
4 Correct 24 ms 3788 KB Output is correct
5 Correct 24 ms 3924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 7616 KB Output is correct
2 Correct 52 ms 7860 KB Output is correct
3 Correct 50 ms 7616 KB Output is correct
4 Correct 53 ms 7604 KB Output is correct
5 Correct 51 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 7612 KB Output is correct
2 Correct 59 ms 7768 KB Output is correct
3 Correct 57 ms 7604 KB Output is correct
4 Correct 53 ms 7868 KB Output is correct
5 Correct 56 ms 7868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 28 ms 4036 KB Output is correct
12 Correct 27 ms 4060 KB Output is correct
13 Correct 26 ms 4040 KB Output is correct
14 Correct 24 ms 3788 KB Output is correct
15 Correct 24 ms 3924 KB Output is correct
16 Correct 24 ms 3784 KB Output is correct
17 Correct 27 ms 4292 KB Output is correct
18 Correct 29 ms 4300 KB Output is correct
19 Correct 25 ms 3784 KB Output is correct
20 Correct 26 ms 4008 KB Output is correct
21 Correct 26 ms 3788 KB Output is correct
22 Correct 26 ms 3960 KB Output is correct
23 Correct 26 ms 4036 KB Output is correct
24 Correct 26 ms 4040 KB Output is correct
25 Correct 26 ms 3928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 28 ms 4036 KB Output is correct
27 Correct 27 ms 4060 KB Output is correct
28 Correct 26 ms 4040 KB Output is correct
29 Correct 24 ms 3788 KB Output is correct
30 Correct 24 ms 3924 KB Output is correct
31 Correct 51 ms 7616 KB Output is correct
32 Correct 52 ms 7860 KB Output is correct
33 Correct 50 ms 7616 KB Output is correct
34 Correct 53 ms 7604 KB Output is correct
35 Correct 51 ms 7416 KB Output is correct
36 Correct 54 ms 7612 KB Output is correct
37 Correct 59 ms 7768 KB Output is correct
38 Correct 57 ms 7604 KB Output is correct
39 Correct 53 ms 7868 KB Output is correct
40 Correct 56 ms 7868 KB Output is correct
41 Correct 24 ms 3784 KB Output is correct
42 Correct 27 ms 4292 KB Output is correct
43 Correct 29 ms 4300 KB Output is correct
44 Correct 25 ms 3784 KB Output is correct
45 Correct 26 ms 4008 KB Output is correct
46 Correct 26 ms 3788 KB Output is correct
47 Correct 26 ms 3960 KB Output is correct
48 Correct 26 ms 4036 KB Output is correct
49 Correct 26 ms 4040 KB Output is correct
50 Correct 26 ms 3928 KB Output is correct
51 Correct 56 ms 7608 KB Output is correct
52 Correct 60 ms 7532 KB Output is correct
53 Correct 62 ms 7452 KB Output is correct
54 Correct 60 ms 7344 KB Output is correct
55 Correct 56 ms 7656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 28 ms 4036 KB Output is correct
27 Correct 27 ms 4060 KB Output is correct
28 Correct 26 ms 4040 KB Output is correct
29 Correct 24 ms 3788 KB Output is correct
30 Correct 24 ms 3924 KB Output is correct
31 Correct 51 ms 7616 KB Output is correct
32 Correct 52 ms 7860 KB Output is correct
33 Correct 50 ms 7616 KB Output is correct
34 Correct 53 ms 7604 KB Output is correct
35 Correct 51 ms 7416 KB Output is correct
36 Correct 54 ms 7612 KB Output is correct
37 Correct 59 ms 7768 KB Output is correct
38 Correct 57 ms 7604 KB Output is correct
39 Correct 53 ms 7868 KB Output is correct
40 Correct 56 ms 7868 KB Output is correct
41 Correct 24 ms 3784 KB Output is correct
42 Correct 27 ms 4292 KB Output is correct
43 Correct 29 ms 4300 KB Output is correct
44 Correct 25 ms 3784 KB Output is correct
45 Correct 26 ms 4008 KB Output is correct
46 Correct 26 ms 3788 KB Output is correct
47 Correct 26 ms 3960 KB Output is correct
48 Correct 26 ms 4036 KB Output is correct
49 Correct 26 ms 4040 KB Output is correct
50 Correct 26 ms 3928 KB Output is correct
51 Correct 56 ms 7608 KB Output is correct
52 Correct 60 ms 7532 KB Output is correct
53 Correct 62 ms 7452 KB Output is correct
54 Correct 60 ms 7344 KB Output is correct
55 Correct 56 ms 7656 KB Output is correct
56 Correct 637 ms 73584 KB Output is correct
57 Correct 615 ms 73072 KB Output is correct
58 Correct 598 ms 69156 KB Output is correct
59 Correct 618 ms 70916 KB Output is correct
60 Correct 683 ms 75352 KB Output is correct