답안 #334218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334218 2020-12-08T16:41:37 Z aryan12 Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 51512 KB
#include <bits/stdc++.h>
using namespace std;

const long long N = 1e6 + 10;
vector<pair<long long, long long> > a(N);
long long ans[N];
bool IsThere[N];
long long par[N], Rank[N];
long long curans = 0;

long long Find(long long x) {
    if(x != par[x]) {
        par[x] = Find(par[x]);
    }
    return par[x];
}

void Unite(long long a, long long b) {
    if(!IsThere[a] || !IsThere[b])
        return;
    long long roota = Find(a), rootb = Find(b);
    curans -= Rank[roota] * (Rank[roota] + 1) / 2;
    curans -= Rank[rootb] * (Rank[rootb] + 1) / 2;
    if(Rank[roota] > Rank[rootb]) {
        Rank[roota] += Rank[rootb];
        par[rootb] = roota;
        curans += Rank[roota] * (Rank[roota] + 1) / 2;
    }
    else {
        Rank[rootb] += Rank[roota];
        par[roota] = rootb;
        curans += Rank[rootb] * (Rank[rootb] + 1) / 2;
    }
}

void Solve() {
    long long n, q;
    cin >> n >> q;
    for(long long i = 0; i < N; i++) {
        IsThere[i] = false;
        par[i] = i;
        Rank[i] = 1;
    }
    for(long long i = 1; i <= n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin() + 1, a.begin() + 1 + n);
    long long curpos = 1;
    ans[0] = 0;
    for(long long i = 1; i < N; i++) {
        while(curpos <= n && a[curpos].first == i) {
            IsThere[a[curpos].second] = true;
            curans++;
            Unite(a[curpos].second, a[curpos].second + 1);
            Unite(a[curpos].second, a[curpos].second - 1);
            curpos++;
        }
        ans[i] = curans;
    }
    for(long long i = 1; i <= q; i++) {
        long long x;
        cin >> x;
        cout << ans[x] << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    Solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 40428 KB Output is correct
2 Correct 24 ms 40428 KB Output is correct
3 Correct 25 ms 40428 KB Output is correct
4 Correct 24 ms 40428 KB Output is correct
5 Correct 26 ms 40428 KB Output is correct
6 Correct 24 ms 40428 KB Output is correct
7 Correct 25 ms 40556 KB Output is correct
8 Correct 24 ms 40428 KB Output is correct
9 Correct 24 ms 40428 KB Output is correct
10 Correct 27 ms 40428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 40428 KB Output is correct
2 Correct 24 ms 40428 KB Output is correct
3 Correct 25 ms 40428 KB Output is correct
4 Correct 24 ms 40428 KB Output is correct
5 Correct 26 ms 40428 KB Output is correct
6 Correct 24 ms 40428 KB Output is correct
7 Correct 25 ms 40556 KB Output is correct
8 Correct 24 ms 40428 KB Output is correct
9 Correct 24 ms 40428 KB Output is correct
10 Correct 27 ms 40428 KB Output is correct
11 Correct 24 ms 40428 KB Output is correct
12 Correct 24 ms 40428 KB Output is correct
13 Correct 24 ms 40428 KB Output is correct
14 Correct 24 ms 40428 KB Output is correct
15 Correct 24 ms 40428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 40428 KB Output is correct
2 Correct 24 ms 40428 KB Output is correct
3 Correct 25 ms 40428 KB Output is correct
4 Correct 24 ms 40428 KB Output is correct
5 Correct 26 ms 40428 KB Output is correct
6 Correct 24 ms 40428 KB Output is correct
7 Correct 25 ms 40556 KB Output is correct
8 Correct 24 ms 40428 KB Output is correct
9 Correct 24 ms 40428 KB Output is correct
10 Correct 27 ms 40428 KB Output is correct
11 Correct 24 ms 40428 KB Output is correct
12 Correct 24 ms 40428 KB Output is correct
13 Correct 24 ms 40428 KB Output is correct
14 Correct 24 ms 40428 KB Output is correct
15 Correct 24 ms 40428 KB Output is correct
16 Correct 24 ms 40428 KB Output is correct
17 Correct 26 ms 40428 KB Output is correct
18 Correct 29 ms 40428 KB Output is correct
19 Correct 25 ms 40428 KB Output is correct
20 Correct 25 ms 40428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 40428 KB Output is correct
2 Correct 24 ms 40428 KB Output is correct
3 Correct 25 ms 40428 KB Output is correct
4 Correct 24 ms 40428 KB Output is correct
5 Correct 26 ms 40428 KB Output is correct
6 Correct 24 ms 40428 KB Output is correct
7 Correct 25 ms 40556 KB Output is correct
8 Correct 24 ms 40428 KB Output is correct
9 Correct 24 ms 40428 KB Output is correct
10 Correct 27 ms 40428 KB Output is correct
11 Correct 24 ms 40428 KB Output is correct
12 Correct 24 ms 40428 KB Output is correct
13 Correct 24 ms 40428 KB Output is correct
14 Correct 24 ms 40428 KB Output is correct
15 Correct 24 ms 40428 KB Output is correct
16 Correct 24 ms 40428 KB Output is correct
17 Correct 26 ms 40428 KB Output is correct
18 Correct 29 ms 40428 KB Output is correct
19 Correct 25 ms 40428 KB Output is correct
20 Correct 25 ms 40428 KB Output is correct
21 Correct 26 ms 40428 KB Output is correct
22 Correct 27 ms 40440 KB Output is correct
23 Correct 28 ms 40428 KB Output is correct
24 Correct 27 ms 40428 KB Output is correct
25 Correct 26 ms 40428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 40428 KB Output is correct
2 Correct 48 ms 40484 KB Output is correct
3 Correct 47 ms 40428 KB Output is correct
4 Correct 50 ms 40556 KB Output is correct
5 Correct 46 ms 40428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 258 ms 41452 KB Output is correct
2 Correct 279 ms 41580 KB Output is correct
3 Correct 270 ms 41708 KB Output is correct
4 Correct 267 ms 41580 KB Output is correct
5 Correct 265 ms 41452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 264 ms 41452 KB Output is correct
2 Correct 264 ms 41708 KB Output is correct
3 Correct 270 ms 41580 KB Output is correct
4 Correct 266 ms 41708 KB Output is correct
5 Correct 284 ms 41708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 40428 KB Output is correct
2 Correct 24 ms 40428 KB Output is correct
3 Correct 25 ms 40428 KB Output is correct
4 Correct 24 ms 40428 KB Output is correct
5 Correct 26 ms 40428 KB Output is correct
6 Correct 24 ms 40428 KB Output is correct
7 Correct 25 ms 40556 KB Output is correct
8 Correct 24 ms 40428 KB Output is correct
9 Correct 24 ms 40428 KB Output is correct
10 Correct 27 ms 40428 KB Output is correct
11 Correct 47 ms 40428 KB Output is correct
12 Correct 48 ms 40484 KB Output is correct
13 Correct 47 ms 40428 KB Output is correct
14 Correct 50 ms 40556 KB Output is correct
15 Correct 46 ms 40428 KB Output is correct
16 Correct 45 ms 40428 KB Output is correct
17 Correct 47 ms 40428 KB Output is correct
18 Correct 50 ms 40428 KB Output is correct
19 Correct 48 ms 40428 KB Output is correct
20 Correct 52 ms 40456 KB Output is correct
21 Correct 54 ms 40428 KB Output is correct
22 Correct 47 ms 40428 KB Output is correct
23 Correct 47 ms 40428 KB Output is correct
24 Correct 46 ms 40428 KB Output is correct
25 Correct 46 ms 40428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 40428 KB Output is correct
2 Correct 24 ms 40428 KB Output is correct
3 Correct 25 ms 40428 KB Output is correct
4 Correct 24 ms 40428 KB Output is correct
5 Correct 26 ms 40428 KB Output is correct
6 Correct 24 ms 40428 KB Output is correct
7 Correct 25 ms 40556 KB Output is correct
8 Correct 24 ms 40428 KB Output is correct
9 Correct 24 ms 40428 KB Output is correct
10 Correct 27 ms 40428 KB Output is correct
11 Correct 24 ms 40428 KB Output is correct
12 Correct 24 ms 40428 KB Output is correct
13 Correct 24 ms 40428 KB Output is correct
14 Correct 24 ms 40428 KB Output is correct
15 Correct 24 ms 40428 KB Output is correct
16 Correct 24 ms 40428 KB Output is correct
17 Correct 26 ms 40428 KB Output is correct
18 Correct 29 ms 40428 KB Output is correct
19 Correct 25 ms 40428 KB Output is correct
20 Correct 25 ms 40428 KB Output is correct
21 Correct 26 ms 40428 KB Output is correct
22 Correct 27 ms 40440 KB Output is correct
23 Correct 28 ms 40428 KB Output is correct
24 Correct 27 ms 40428 KB Output is correct
25 Correct 26 ms 40428 KB Output is correct
26 Correct 47 ms 40428 KB Output is correct
27 Correct 48 ms 40484 KB Output is correct
28 Correct 47 ms 40428 KB Output is correct
29 Correct 50 ms 40556 KB Output is correct
30 Correct 46 ms 40428 KB Output is correct
31 Correct 258 ms 41452 KB Output is correct
32 Correct 279 ms 41580 KB Output is correct
33 Correct 270 ms 41708 KB Output is correct
34 Correct 267 ms 41580 KB Output is correct
35 Correct 265 ms 41452 KB Output is correct
36 Correct 264 ms 41452 KB Output is correct
37 Correct 264 ms 41708 KB Output is correct
38 Correct 270 ms 41580 KB Output is correct
39 Correct 266 ms 41708 KB Output is correct
40 Correct 284 ms 41708 KB Output is correct
41 Correct 45 ms 40428 KB Output is correct
42 Correct 47 ms 40428 KB Output is correct
43 Correct 50 ms 40428 KB Output is correct
44 Correct 48 ms 40428 KB Output is correct
45 Correct 52 ms 40456 KB Output is correct
46 Correct 54 ms 40428 KB Output is correct
47 Correct 47 ms 40428 KB Output is correct
48 Correct 47 ms 40428 KB Output is correct
49 Correct 46 ms 40428 KB Output is correct
50 Correct 46 ms 40428 KB Output is correct
51 Correct 291 ms 42604 KB Output is correct
52 Correct 281 ms 42348 KB Output is correct
53 Correct 285 ms 42476 KB Output is correct
54 Correct 280 ms 42348 KB Output is correct
55 Correct 279 ms 42476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 40428 KB Output is correct
2 Correct 24 ms 40428 KB Output is correct
3 Correct 25 ms 40428 KB Output is correct
4 Correct 24 ms 40428 KB Output is correct
5 Correct 26 ms 40428 KB Output is correct
6 Correct 24 ms 40428 KB Output is correct
7 Correct 25 ms 40556 KB Output is correct
8 Correct 24 ms 40428 KB Output is correct
9 Correct 24 ms 40428 KB Output is correct
10 Correct 27 ms 40428 KB Output is correct
11 Correct 24 ms 40428 KB Output is correct
12 Correct 24 ms 40428 KB Output is correct
13 Correct 24 ms 40428 KB Output is correct
14 Correct 24 ms 40428 KB Output is correct
15 Correct 24 ms 40428 KB Output is correct
16 Correct 24 ms 40428 KB Output is correct
17 Correct 26 ms 40428 KB Output is correct
18 Correct 29 ms 40428 KB Output is correct
19 Correct 25 ms 40428 KB Output is correct
20 Correct 25 ms 40428 KB Output is correct
21 Correct 26 ms 40428 KB Output is correct
22 Correct 27 ms 40440 KB Output is correct
23 Correct 28 ms 40428 KB Output is correct
24 Correct 27 ms 40428 KB Output is correct
25 Correct 26 ms 40428 KB Output is correct
26 Correct 47 ms 40428 KB Output is correct
27 Correct 48 ms 40484 KB Output is correct
28 Correct 47 ms 40428 KB Output is correct
29 Correct 50 ms 40556 KB Output is correct
30 Correct 46 ms 40428 KB Output is correct
31 Correct 258 ms 41452 KB Output is correct
32 Correct 279 ms 41580 KB Output is correct
33 Correct 270 ms 41708 KB Output is correct
34 Correct 267 ms 41580 KB Output is correct
35 Correct 265 ms 41452 KB Output is correct
36 Correct 264 ms 41452 KB Output is correct
37 Correct 264 ms 41708 KB Output is correct
38 Correct 270 ms 41580 KB Output is correct
39 Correct 266 ms 41708 KB Output is correct
40 Correct 284 ms 41708 KB Output is correct
41 Correct 45 ms 40428 KB Output is correct
42 Correct 47 ms 40428 KB Output is correct
43 Correct 50 ms 40428 KB Output is correct
44 Correct 48 ms 40428 KB Output is correct
45 Correct 52 ms 40456 KB Output is correct
46 Correct 54 ms 40428 KB Output is correct
47 Correct 47 ms 40428 KB Output is correct
48 Correct 47 ms 40428 KB Output is correct
49 Correct 46 ms 40428 KB Output is correct
50 Correct 46 ms 40428 KB Output is correct
51 Correct 291 ms 42604 KB Output is correct
52 Correct 281 ms 42348 KB Output is correct
53 Correct 285 ms 42476 KB Output is correct
54 Correct 280 ms 42348 KB Output is correct
55 Correct 279 ms 42476 KB Output is correct
56 Execution timed out 1090 ms 51512 KB Time limit exceeded
57 Halted 0 ms 0 KB -