Submission #958364

# Submission time Handle Problem Language Result Execution time Memory
958364 2024-04-05T14:29:55 Z vjudge1 Pilot (NOI19_pilot) C++17
100 / 100
454 ms 76884 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 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6744 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 6492 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 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6744 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 6492 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 2 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 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6744 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 6492 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 2 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 6488 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 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6744 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 6492 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 2 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 6488 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 2 ms 6492 KB Output is correct
25 Correct 2 ms 6620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 9308 KB Output is correct
2 Correct 17 ms 9452 KB Output is correct
3 Correct 16 ms 9308 KB Output is correct
4 Correct 16 ms 9176 KB Output is correct
5 Correct 19 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 14428 KB Output is correct
2 Correct 29 ms 14476 KB Output is correct
3 Correct 29 ms 14476 KB Output is correct
4 Correct 29 ms 14684 KB Output is correct
5 Correct 31 ms 14536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 14560 KB Output is correct
2 Correct 30 ms 14596 KB Output is correct
3 Correct 29 ms 14468 KB Output is correct
4 Correct 29 ms 14932 KB Output is correct
5 Correct 30 ms 14960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6744 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 6492 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 9308 KB Output is correct
12 Correct 17 ms 9452 KB Output is correct
13 Correct 16 ms 9308 KB Output is correct
14 Correct 16 ms 9176 KB Output is correct
15 Correct 19 ms 9308 KB Output is correct
16 Correct 18 ms 9308 KB Output is correct
17 Correct 14 ms 9308 KB Output is correct
18 Correct 14 ms 9304 KB Output is correct
19 Correct 13 ms 9052 KB Output is correct
20 Correct 15 ms 9200 KB Output is correct
21 Correct 16 ms 9052 KB Output is correct
22 Correct 14 ms 9308 KB Output is correct
23 Correct 15 ms 9308 KB Output is correct
24 Correct 14 ms 9052 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 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6744 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 6492 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 2 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 6488 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 2 ms 6492 KB Output is correct
25 Correct 2 ms 6620 KB Output is correct
26 Correct 17 ms 9308 KB Output is correct
27 Correct 17 ms 9452 KB Output is correct
28 Correct 16 ms 9308 KB Output is correct
29 Correct 16 ms 9176 KB Output is correct
30 Correct 19 ms 9308 KB Output is correct
31 Correct 28 ms 14428 KB Output is correct
32 Correct 29 ms 14476 KB Output is correct
33 Correct 29 ms 14476 KB Output is correct
34 Correct 29 ms 14684 KB Output is correct
35 Correct 31 ms 14536 KB Output is correct
36 Correct 28 ms 14560 KB Output is correct
37 Correct 30 ms 14596 KB Output is correct
38 Correct 29 ms 14468 KB Output is correct
39 Correct 29 ms 14932 KB Output is correct
40 Correct 30 ms 14960 KB Output is correct
41 Correct 18 ms 9308 KB Output is correct
42 Correct 14 ms 9308 KB Output is correct
43 Correct 14 ms 9304 KB Output is correct
44 Correct 13 ms 9052 KB Output is correct
45 Correct 15 ms 9200 KB Output is correct
46 Correct 16 ms 9052 KB Output is correct
47 Correct 14 ms 9308 KB Output is correct
48 Correct 15 ms 9308 KB Output is correct
49 Correct 14 ms 9052 KB Output is correct
50 Correct 15 ms 9308 KB Output is correct
51 Correct 36 ms 14416 KB Output is correct
52 Correct 35 ms 14480 KB Output is correct
53 Correct 36 ms 14420 KB Output is correct
54 Correct 35 ms 14168 KB Output is correct
55 Correct 38 ms 14572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6744 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 6492 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 2 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 6488 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 2 ms 6492 KB Output is correct
25 Correct 2 ms 6620 KB Output is correct
26 Correct 17 ms 9308 KB Output is correct
27 Correct 17 ms 9452 KB Output is correct
28 Correct 16 ms 9308 KB Output is correct
29 Correct 16 ms 9176 KB Output is correct
30 Correct 19 ms 9308 KB Output is correct
31 Correct 28 ms 14428 KB Output is correct
32 Correct 29 ms 14476 KB Output is correct
33 Correct 29 ms 14476 KB Output is correct
34 Correct 29 ms 14684 KB Output is correct
35 Correct 31 ms 14536 KB Output is correct
36 Correct 28 ms 14560 KB Output is correct
37 Correct 30 ms 14596 KB Output is correct
38 Correct 29 ms 14468 KB Output is correct
39 Correct 29 ms 14932 KB Output is correct
40 Correct 30 ms 14960 KB Output is correct
41 Correct 18 ms 9308 KB Output is correct
42 Correct 14 ms 9308 KB Output is correct
43 Correct 14 ms 9304 KB Output is correct
44 Correct 13 ms 9052 KB Output is correct
45 Correct 15 ms 9200 KB Output is correct
46 Correct 16 ms 9052 KB Output is correct
47 Correct 14 ms 9308 KB Output is correct
48 Correct 15 ms 9308 KB Output is correct
49 Correct 14 ms 9052 KB Output is correct
50 Correct 15 ms 9308 KB Output is correct
51 Correct 36 ms 14416 KB Output is correct
52 Correct 35 ms 14480 KB Output is correct
53 Correct 36 ms 14420 KB Output is correct
54 Correct 35 ms 14168 KB Output is correct
55 Correct 38 ms 14572 KB Output is correct
56 Correct 448 ms 75148 KB Output is correct
57 Correct 452 ms 76172 KB Output is correct
58 Correct 422 ms 73544 KB Output is correct
59 Correct 425 ms 73556 KB Output is correct
60 Correct 454 ms 76884 KB Output is correct