Submission #958363

# Submission time Handle Problem Language Result Execution time Memory
958363 2024-04-05T14:29:17 Z Whisper Pilot (NOI19_pilot) C++17
100 / 100
477 ms 83276 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void setupIO(){
    #define name "Whisper"
    //Phu Trong from Nguyen Tat Thanh High School for gifted student
    srand(time(NULL));
    cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    cout << fixed << setprecision(10);
}

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
const int MAX = 1e6 + 5;
int N, M;
pair<int, int> h[MAX], a[MAX];
struct Dsu{
    int n;
    vector<int> par, sz;
    Dsu(int _n = 0){
        this -> n = _n;
        par.resize(n + 5);
        sz.resize(n + 5);
        for (int i = 1; i <= n; ++i) sz[i] = 1;
        iota(par.begin(), par.end(), 0ll);
    }
    int find(int u){
        return u == par[u] ? u : par[u] = find(par[u]);
    }
    bool unite(int u, int v){
        u = find(u), v = find(v);
        if (u == v) return 0;
        if (sz[u] < sz[v]) swap(u, v);
        sz[u] += sz[v];
        par[v] = u;
        sz[v] = 0;
        return 1;
    }
};

int ans[MAX];
int vis[MAX];
void Whisper(){
    cin >> N >> M;
    for (int i = 1; i <= N; ++i) cin >> h[i].first, h[i].second = i;
    for (int i = 1; i <= M; ++i) cin >> a[i].first, a[i].second = i;
    sort(h + 1, h + N + 1);
    sort(a + 1, a + M + 1);
    Dsu dsu(N);
    int j = 1;

    int res = 0;
    for (int i = 1; i <= M; ++i){
        while (j <= N && h[j].first <= a[i].first){
            int pos = h[j].second;
            int lf = 0, rg = 0;
            if (vis[pos - 1])
                lf = dsu.sz[dsu.find(pos - 1)];
            if (vis[pos + 1])
                rg = dsu.sz[dsu.find(pos + 1)];
            res += (lf + 1) * (rg + 1);
            if (vis[pos - 1]) dsu.unite(pos, pos - 1);
            if (vis[pos + 1]) dsu.unite(pos, pos + 1);
            vis[pos] = 1;
            ++j;
        }
        ans[a[i].second] = res;
    }
    for (int i = 1; i <= M; ++i){
        cout << ans[i] << "\n";
    }
}


signed main(){
    setupIO();
    int Test = 1;
//    cin >> Test;
    for ( int i = 1 ; i <= Test ; i++ ){
        Whisper();
        if (i < Test) cout << '\n';
    }
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6616 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6612 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6616 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6612 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6616 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6612 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6616 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6612 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 9296 KB Output is correct
2 Correct 17 ms 9564 KB Output is correct
3 Correct 16 ms 9120 KB Output is correct
4 Correct 16 ms 9304 KB Output is correct
5 Correct 16 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 14896 KB Output is correct
2 Correct 29 ms 14940 KB Output is correct
3 Correct 28 ms 14872 KB Output is correct
4 Correct 30 ms 14936 KB Output is correct
5 Correct 28 ms 14928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 15196 KB Output is correct
2 Correct 28 ms 14928 KB Output is correct
3 Correct 30 ms 15184 KB Output is correct
4 Correct 28 ms 15184 KB Output is correct
5 Correct 30 ms 15184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6616 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6612 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 17 ms 9296 KB Output is correct
12 Correct 17 ms 9564 KB Output is correct
13 Correct 16 ms 9120 KB Output is correct
14 Correct 16 ms 9304 KB Output is correct
15 Correct 16 ms 9308 KB Output is correct
16 Correct 16 ms 9308 KB Output is correct
17 Correct 15 ms 9564 KB Output is correct
18 Correct 15 ms 9564 KB Output is correct
19 Correct 14 ms 9288 KB Output is correct
20 Correct 15 ms 9304 KB Output is correct
21 Correct 16 ms 9292 KB Output is correct
22 Correct 14 ms 9308 KB Output is correct
23 Correct 15 ms 9500 KB Output is correct
24 Correct 14 ms 9284 KB Output is correct
25 Correct 15 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6616 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6612 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 17 ms 9296 KB Output is correct
27 Correct 17 ms 9564 KB Output is correct
28 Correct 16 ms 9120 KB Output is correct
29 Correct 16 ms 9304 KB Output is correct
30 Correct 16 ms 9308 KB Output is correct
31 Correct 30 ms 14896 KB Output is correct
32 Correct 29 ms 14940 KB Output is correct
33 Correct 28 ms 14872 KB Output is correct
34 Correct 30 ms 14936 KB Output is correct
35 Correct 28 ms 14928 KB Output is correct
36 Correct 27 ms 15196 KB Output is correct
37 Correct 28 ms 14928 KB Output is correct
38 Correct 30 ms 15184 KB Output is correct
39 Correct 28 ms 15184 KB Output is correct
40 Correct 30 ms 15184 KB Output is correct
41 Correct 16 ms 9308 KB Output is correct
42 Correct 15 ms 9564 KB Output is correct
43 Correct 15 ms 9564 KB Output is correct
44 Correct 14 ms 9288 KB Output is correct
45 Correct 15 ms 9304 KB Output is correct
46 Correct 16 ms 9292 KB Output is correct
47 Correct 14 ms 9308 KB Output is correct
48 Correct 15 ms 9500 KB Output is correct
49 Correct 14 ms 9284 KB Output is correct
50 Correct 15 ms 9308 KB Output is correct
51 Correct 36 ms 14928 KB Output is correct
52 Correct 36 ms 14676 KB Output is correct
53 Correct 36 ms 14932 KB Output is correct
54 Correct 35 ms 14620 KB Output is correct
55 Correct 36 ms 14936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6616 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6612 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 17 ms 9296 KB Output is correct
27 Correct 17 ms 9564 KB Output is correct
28 Correct 16 ms 9120 KB Output is correct
29 Correct 16 ms 9304 KB Output is correct
30 Correct 16 ms 9308 KB Output is correct
31 Correct 30 ms 14896 KB Output is correct
32 Correct 29 ms 14940 KB Output is correct
33 Correct 28 ms 14872 KB Output is correct
34 Correct 30 ms 14936 KB Output is correct
35 Correct 28 ms 14928 KB Output is correct
36 Correct 27 ms 15196 KB Output is correct
37 Correct 28 ms 14928 KB Output is correct
38 Correct 30 ms 15184 KB Output is correct
39 Correct 28 ms 15184 KB Output is correct
40 Correct 30 ms 15184 KB Output is correct
41 Correct 16 ms 9308 KB Output is correct
42 Correct 15 ms 9564 KB Output is correct
43 Correct 15 ms 9564 KB Output is correct
44 Correct 14 ms 9288 KB Output is correct
45 Correct 15 ms 9304 KB Output is correct
46 Correct 16 ms 9292 KB Output is correct
47 Correct 14 ms 9308 KB Output is correct
48 Correct 15 ms 9500 KB Output is correct
49 Correct 14 ms 9284 KB Output is correct
50 Correct 15 ms 9308 KB Output is correct
51 Correct 36 ms 14928 KB Output is correct
52 Correct 36 ms 14676 KB Output is correct
53 Correct 36 ms 14932 KB Output is correct
54 Correct 35 ms 14620 KB Output is correct
55 Correct 36 ms 14936 KB Output is correct
56 Correct 468 ms 81752 KB Output is correct
57 Correct 454 ms 82516 KB Output is correct
58 Correct 454 ms 79144 KB Output is correct
59 Correct 432 ms 79760 KB Output is correct
60 Correct 477 ms 83276 KB Output is correct