답안 #478051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478051 2021-10-05T12:02:59 Z chungdinh Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 39048 KB
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <cassert>
#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define ll long long
#define ii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define r first
#define c second

#define all(x) x.begin(), x.end()

ostream& operator << (ostream& os, pair<int, int> a) {
    return os << a.first << " : " << a.second;
}

#define endl '\n'
#define db(val) "["#val" = "<<(val)<<"] "
#define cntbit(x) __builtin_popcount(x)

const int N = 1e6 + 5;
const int iINF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

int n, q;
int h[N];

ii a[N];
int id[N];

ll res[N];
bool below[N];

ll f(int x) {return (ll)x*(x + 1)/2;}

int p[N];
int sz[N];
int find(int u) {
    if (u == p[u]) return u;
    return p[u] = find(p[u]);
}
void sss(int u, int v, ll &subres) {
    u = find(u); v = find(v);
    subres -= f(sz[u]) + f(sz[v]);

    p[u] = v;
    sz[v] += sz[u];
    subres += f(sz[v]);
}


int main() {
    ios_base::sync_with_stdio();
    #ifdef CHUNGDINH
    freopen("main.inp","r",stdin);
    //freopen("main.out","w",stdout);
    #endif
    memset(below, false, sizeof below);

    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        id[i] = i;
        cin >> h[i];
        p[i] = i; sz[i] = 1;
    }
    sort(id + 1, id + n + 1, [](int x, int y){return h[x] < h[y];});

    for (int i = 1; i <= q; i++) {
        cin >> a[i].first; a[i].second = i;
    }
    sort(a + 1, a + q + 1);

    // case n == 1;

    ll subres = 0;
    int ss = 1;
    for (int i = 1; i <= q; i++) {
        while (ss <= n && h[id[ss]] <= a[i].first) {

            subres++;
            int pl = id[ss];

            below[pl] = true;
            if (pl <= n - 1 && below[pl + 1]) {
                sss(pl, pl + 1, subres);
            }
            if (pl >= 2 && below[pl - 1]) sss(pl, pl - 1, subres);

            ss++;
        }

        res[a[i].second] = subres;
    }
    //for (int i = 1; i <= n; i++) cout << id[i] << " ";

    for (int i = 1; i <= q; i++) cout << res[i] << endl;
}

/*
Array bounds *
long long vs int
Garbage value
Sometimes, VNOI views "arrays out of bounds" as "wrong answer"
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1348 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1348 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 1 ms 1228 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 1 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1348 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 1 ms 1228 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 1 ms 1228 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
17 Correct 1 ms 1228 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 1 ms 1228 KB Output is correct
20 Correct 1 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1348 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 1 ms 1228 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 1 ms 1228 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
17 Correct 1 ms 1228 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 1 ms 1228 KB Output is correct
20 Correct 1 ms 1228 KB Output is correct
21 Correct 1 ms 1356 KB Output is correct
22 Correct 2 ms 1356 KB Output is correct
23 Correct 2 ms 1356 KB Output is correct
24 Correct 2 ms 1356 KB Output is correct
25 Correct 1 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 2768 KB Output is correct
2 Correct 45 ms 2856 KB Output is correct
3 Correct 39 ms 2736 KB Output is correct
4 Correct 42 ms 2644 KB Output is correct
5 Correct 41 ms 2708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 5060 KB Output is correct
2 Correct 79 ms 5200 KB Output is correct
3 Correct 79 ms 5168 KB Output is correct
4 Correct 78 ms 5188 KB Output is correct
5 Correct 79 ms 5100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 5184 KB Output is correct
2 Correct 98 ms 5156 KB Output is correct
3 Correct 82 ms 5120 KB Output is correct
4 Correct 86 ms 5124 KB Output is correct
5 Correct 84 ms 5316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1348 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 45 ms 2768 KB Output is correct
12 Correct 45 ms 2856 KB Output is correct
13 Correct 39 ms 2736 KB Output is correct
14 Correct 42 ms 2644 KB Output is correct
15 Correct 41 ms 2708 KB Output is correct
16 Correct 41 ms 2628 KB Output is correct
17 Correct 51 ms 2736 KB Output is correct
18 Correct 42 ms 2848 KB Output is correct
19 Correct 37 ms 2628 KB Output is correct
20 Correct 45 ms 2756 KB Output is correct
21 Correct 39 ms 2708 KB Output is correct
22 Correct 40 ms 2688 KB Output is correct
23 Correct 40 ms 2776 KB Output is correct
24 Correct 41 ms 2648 KB Output is correct
25 Correct 40 ms 2756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1348 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 1 ms 1228 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 1 ms 1228 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
17 Correct 1 ms 1228 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 1 ms 1228 KB Output is correct
20 Correct 1 ms 1228 KB Output is correct
21 Correct 1 ms 1356 KB Output is correct
22 Correct 2 ms 1356 KB Output is correct
23 Correct 2 ms 1356 KB Output is correct
24 Correct 2 ms 1356 KB Output is correct
25 Correct 1 ms 1228 KB Output is correct
26 Correct 45 ms 2768 KB Output is correct
27 Correct 45 ms 2856 KB Output is correct
28 Correct 39 ms 2736 KB Output is correct
29 Correct 42 ms 2644 KB Output is correct
30 Correct 41 ms 2708 KB Output is correct
31 Correct 75 ms 5060 KB Output is correct
32 Correct 79 ms 5200 KB Output is correct
33 Correct 79 ms 5168 KB Output is correct
34 Correct 78 ms 5188 KB Output is correct
35 Correct 79 ms 5100 KB Output is correct
36 Correct 82 ms 5184 KB Output is correct
37 Correct 98 ms 5156 KB Output is correct
38 Correct 82 ms 5120 KB Output is correct
39 Correct 86 ms 5124 KB Output is correct
40 Correct 84 ms 5316 KB Output is correct
41 Correct 41 ms 2628 KB Output is correct
42 Correct 51 ms 2736 KB Output is correct
43 Correct 42 ms 2848 KB Output is correct
44 Correct 37 ms 2628 KB Output is correct
45 Correct 45 ms 2756 KB Output is correct
46 Correct 39 ms 2708 KB Output is correct
47 Correct 40 ms 2688 KB Output is correct
48 Correct 40 ms 2776 KB Output is correct
49 Correct 41 ms 2648 KB Output is correct
50 Correct 40 ms 2756 KB Output is correct
51 Correct 88 ms 5060 KB Output is correct
52 Correct 95 ms 5056 KB Output is correct
53 Correct 87 ms 5072 KB Output is correct
54 Correct 99 ms 4788 KB Output is correct
55 Correct 88 ms 5088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1348 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 1 ms 1228 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 1 ms 1228 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
17 Correct 1 ms 1228 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 1 ms 1228 KB Output is correct
20 Correct 1 ms 1228 KB Output is correct
21 Correct 1 ms 1356 KB Output is correct
22 Correct 2 ms 1356 KB Output is correct
23 Correct 2 ms 1356 KB Output is correct
24 Correct 2 ms 1356 KB Output is correct
25 Correct 1 ms 1228 KB Output is correct
26 Correct 45 ms 2768 KB Output is correct
27 Correct 45 ms 2856 KB Output is correct
28 Correct 39 ms 2736 KB Output is correct
29 Correct 42 ms 2644 KB Output is correct
30 Correct 41 ms 2708 KB Output is correct
31 Correct 75 ms 5060 KB Output is correct
32 Correct 79 ms 5200 KB Output is correct
33 Correct 79 ms 5168 KB Output is correct
34 Correct 78 ms 5188 KB Output is correct
35 Correct 79 ms 5100 KB Output is correct
36 Correct 82 ms 5184 KB Output is correct
37 Correct 98 ms 5156 KB Output is correct
38 Correct 82 ms 5120 KB Output is correct
39 Correct 86 ms 5124 KB Output is correct
40 Correct 84 ms 5316 KB Output is correct
41 Correct 41 ms 2628 KB Output is correct
42 Correct 51 ms 2736 KB Output is correct
43 Correct 42 ms 2848 KB Output is correct
44 Correct 37 ms 2628 KB Output is correct
45 Correct 45 ms 2756 KB Output is correct
46 Correct 39 ms 2708 KB Output is correct
47 Correct 40 ms 2688 KB Output is correct
48 Correct 40 ms 2776 KB Output is correct
49 Correct 41 ms 2648 KB Output is correct
50 Correct 40 ms 2756 KB Output is correct
51 Correct 88 ms 5060 KB Output is correct
52 Correct 95 ms 5056 KB Output is correct
53 Correct 87 ms 5072 KB Output is correct
54 Correct 99 ms 4788 KB Output is correct
55 Correct 88 ms 5088 KB Output is correct
56 Execution timed out 1050 ms 39048 KB Time limit exceeded
57 Halted 0 ms 0 KB -