답안 #624234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624234 2022-08-07T13:49:17 Z PoonYaPat Pilot (NOI19_pilot) C++14
100 / 100
658 ms 83600 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,qu,pre[1000001],pos[1000001],c[1000001];
ll ans[1000001],sum;
vector<int> h[1000001];

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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>qu;

    for (int i=1; i<=n; ++i) {
        cin>>c[i];
        h[c[i]].push_back(i);
    }

    for (int i=1; i<=n; ++i) {
        int idx=i-1;
        while (c[i]>c[idx] && idx>=1) idx=pre[idx];
        pre[i]=idx;
    }

    for (int i=n; i>=1; --i) {
        int idx=i+1;
        while (c[i]>=c[idx] && idx<=n) idx=pos[idx];
        pos[i]=idx;
    }

    sum=cal(n);
    for (int i=1000000; i>0; --i) {
        ans[i]=sum;
        for (auto j : h[i]) {
            int r=pos[j], l=pre[j];
            sum-=cal(r-l-1);
            sum+=cal(j-l-1);
            sum+=cal(r-j-1);
        }
    }
    for (int i=1; i<=qu; ++i) {
        int x; cin>>x;
        cout<<ans[x]<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 18 ms 31580 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31608 KB Output is correct
5 Correct 19 ms 31604 KB Output is correct
6 Correct 19 ms 31572 KB Output is correct
7 Correct 16 ms 31576 KB Output is correct
8 Correct 16 ms 31572 KB Output is correct
9 Correct 18 ms 31656 KB Output is correct
10 Correct 18 ms 31532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 18 ms 31580 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31608 KB Output is correct
5 Correct 19 ms 31604 KB Output is correct
6 Correct 19 ms 31572 KB Output is correct
7 Correct 16 ms 31576 KB Output is correct
8 Correct 16 ms 31572 KB Output is correct
9 Correct 18 ms 31656 KB Output is correct
10 Correct 18 ms 31532 KB Output is correct
11 Correct 16 ms 31572 KB Output is correct
12 Correct 18 ms 31572 KB Output is correct
13 Correct 16 ms 31560 KB Output is correct
14 Correct 16 ms 31540 KB Output is correct
15 Correct 18 ms 31644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 18 ms 31580 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31608 KB Output is correct
5 Correct 19 ms 31604 KB Output is correct
6 Correct 19 ms 31572 KB Output is correct
7 Correct 16 ms 31576 KB Output is correct
8 Correct 16 ms 31572 KB Output is correct
9 Correct 18 ms 31656 KB Output is correct
10 Correct 18 ms 31532 KB Output is correct
11 Correct 16 ms 31572 KB Output is correct
12 Correct 18 ms 31572 KB Output is correct
13 Correct 16 ms 31560 KB Output is correct
14 Correct 16 ms 31540 KB Output is correct
15 Correct 18 ms 31644 KB Output is correct
16 Correct 18 ms 31572 KB Output is correct
17 Correct 20 ms 31608 KB Output is correct
18 Correct 16 ms 31664 KB Output is correct
19 Correct 17 ms 31552 KB Output is correct
20 Correct 16 ms 31660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 18 ms 31580 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31608 KB Output is correct
5 Correct 19 ms 31604 KB Output is correct
6 Correct 19 ms 31572 KB Output is correct
7 Correct 16 ms 31576 KB Output is correct
8 Correct 16 ms 31572 KB Output is correct
9 Correct 18 ms 31656 KB Output is correct
10 Correct 18 ms 31532 KB Output is correct
11 Correct 16 ms 31572 KB Output is correct
12 Correct 18 ms 31572 KB Output is correct
13 Correct 16 ms 31560 KB Output is correct
14 Correct 16 ms 31540 KB Output is correct
15 Correct 18 ms 31644 KB Output is correct
16 Correct 18 ms 31572 KB Output is correct
17 Correct 20 ms 31608 KB Output is correct
18 Correct 16 ms 31664 KB Output is correct
19 Correct 17 ms 31552 KB Output is correct
20 Correct 16 ms 31660 KB Output is correct
21 Correct 17 ms 31692 KB Output is correct
22 Correct 17 ms 31572 KB Output is correct
23 Correct 17 ms 31680 KB Output is correct
24 Correct 18 ms 31652 KB Output is correct
25 Correct 17 ms 31624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 34592 KB Output is correct
2 Correct 46 ms 35708 KB Output is correct
3 Correct 37 ms 34596 KB Output is correct
4 Correct 43 ms 35284 KB Output is correct
5 Correct 37 ms 34448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 36556 KB Output is correct
2 Correct 62 ms 36676 KB Output is correct
3 Correct 49 ms 36492 KB Output is correct
4 Correct 48 ms 36684 KB Output is correct
5 Correct 50 ms 36556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 36600 KB Output is correct
2 Correct 52 ms 36560 KB Output is correct
3 Correct 56 ms 36528 KB Output is correct
4 Correct 54 ms 36868 KB Output is correct
5 Correct 55 ms 36676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 18 ms 31580 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31608 KB Output is correct
5 Correct 19 ms 31604 KB Output is correct
6 Correct 19 ms 31572 KB Output is correct
7 Correct 16 ms 31576 KB Output is correct
8 Correct 16 ms 31572 KB Output is correct
9 Correct 18 ms 31656 KB Output is correct
10 Correct 18 ms 31532 KB Output is correct
11 Correct 50 ms 34592 KB Output is correct
12 Correct 46 ms 35708 KB Output is correct
13 Correct 37 ms 34596 KB Output is correct
14 Correct 43 ms 35284 KB Output is correct
15 Correct 37 ms 34448 KB Output is correct
16 Correct 47 ms 34484 KB Output is correct
17 Correct 48 ms 35660 KB Output is correct
18 Correct 55 ms 35716 KB Output is correct
19 Correct 35 ms 34508 KB Output is correct
20 Correct 49 ms 35644 KB Output is correct
21 Correct 44 ms 34480 KB Output is correct
22 Correct 46 ms 35476 KB Output is correct
23 Correct 37 ms 34764 KB Output is correct
24 Correct 45 ms 35344 KB Output is correct
25 Correct 36 ms 34680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 18 ms 31580 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31608 KB Output is correct
5 Correct 19 ms 31604 KB Output is correct
6 Correct 19 ms 31572 KB Output is correct
7 Correct 16 ms 31576 KB Output is correct
8 Correct 16 ms 31572 KB Output is correct
9 Correct 18 ms 31656 KB Output is correct
10 Correct 18 ms 31532 KB Output is correct
11 Correct 16 ms 31572 KB Output is correct
12 Correct 18 ms 31572 KB Output is correct
13 Correct 16 ms 31560 KB Output is correct
14 Correct 16 ms 31540 KB Output is correct
15 Correct 18 ms 31644 KB Output is correct
16 Correct 18 ms 31572 KB Output is correct
17 Correct 20 ms 31608 KB Output is correct
18 Correct 16 ms 31664 KB Output is correct
19 Correct 17 ms 31552 KB Output is correct
20 Correct 16 ms 31660 KB Output is correct
21 Correct 17 ms 31692 KB Output is correct
22 Correct 17 ms 31572 KB Output is correct
23 Correct 17 ms 31680 KB Output is correct
24 Correct 18 ms 31652 KB Output is correct
25 Correct 17 ms 31624 KB Output is correct
26 Correct 50 ms 34592 KB Output is correct
27 Correct 46 ms 35708 KB Output is correct
28 Correct 37 ms 34596 KB Output is correct
29 Correct 43 ms 35284 KB Output is correct
30 Correct 37 ms 34448 KB Output is correct
31 Correct 47 ms 36556 KB Output is correct
32 Correct 62 ms 36676 KB Output is correct
33 Correct 49 ms 36492 KB Output is correct
34 Correct 48 ms 36684 KB Output is correct
35 Correct 50 ms 36556 KB Output is correct
36 Correct 54 ms 36600 KB Output is correct
37 Correct 52 ms 36560 KB Output is correct
38 Correct 56 ms 36528 KB Output is correct
39 Correct 54 ms 36868 KB Output is correct
40 Correct 55 ms 36676 KB Output is correct
41 Correct 47 ms 34484 KB Output is correct
42 Correct 48 ms 35660 KB Output is correct
43 Correct 55 ms 35716 KB Output is correct
44 Correct 35 ms 34508 KB Output is correct
45 Correct 49 ms 35644 KB Output is correct
46 Correct 44 ms 34480 KB Output is correct
47 Correct 46 ms 35476 KB Output is correct
48 Correct 37 ms 34764 KB Output is correct
49 Correct 45 ms 35344 KB Output is correct
50 Correct 36 ms 34680 KB Output is correct
51 Correct 64 ms 35496 KB Output is correct
52 Correct 70 ms 36160 KB Output is correct
53 Correct 71 ms 35432 KB Output is correct
54 Correct 65 ms 36180 KB Output is correct
55 Correct 63 ms 35532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 18 ms 31580 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 17 ms 31608 KB Output is correct
5 Correct 19 ms 31604 KB Output is correct
6 Correct 19 ms 31572 KB Output is correct
7 Correct 16 ms 31576 KB Output is correct
8 Correct 16 ms 31572 KB Output is correct
9 Correct 18 ms 31656 KB Output is correct
10 Correct 18 ms 31532 KB Output is correct
11 Correct 16 ms 31572 KB Output is correct
12 Correct 18 ms 31572 KB Output is correct
13 Correct 16 ms 31560 KB Output is correct
14 Correct 16 ms 31540 KB Output is correct
15 Correct 18 ms 31644 KB Output is correct
16 Correct 18 ms 31572 KB Output is correct
17 Correct 20 ms 31608 KB Output is correct
18 Correct 16 ms 31664 KB Output is correct
19 Correct 17 ms 31552 KB Output is correct
20 Correct 16 ms 31660 KB Output is correct
21 Correct 17 ms 31692 KB Output is correct
22 Correct 17 ms 31572 KB Output is correct
23 Correct 17 ms 31680 KB Output is correct
24 Correct 18 ms 31652 KB Output is correct
25 Correct 17 ms 31624 KB Output is correct
26 Correct 50 ms 34592 KB Output is correct
27 Correct 46 ms 35708 KB Output is correct
28 Correct 37 ms 34596 KB Output is correct
29 Correct 43 ms 35284 KB Output is correct
30 Correct 37 ms 34448 KB Output is correct
31 Correct 47 ms 36556 KB Output is correct
32 Correct 62 ms 36676 KB Output is correct
33 Correct 49 ms 36492 KB Output is correct
34 Correct 48 ms 36684 KB Output is correct
35 Correct 50 ms 36556 KB Output is correct
36 Correct 54 ms 36600 KB Output is correct
37 Correct 52 ms 36560 KB Output is correct
38 Correct 56 ms 36528 KB Output is correct
39 Correct 54 ms 36868 KB Output is correct
40 Correct 55 ms 36676 KB Output is correct
41 Correct 47 ms 34484 KB Output is correct
42 Correct 48 ms 35660 KB Output is correct
43 Correct 55 ms 35716 KB Output is correct
44 Correct 35 ms 34508 KB Output is correct
45 Correct 49 ms 35644 KB Output is correct
46 Correct 44 ms 34480 KB Output is correct
47 Correct 46 ms 35476 KB Output is correct
48 Correct 37 ms 34764 KB Output is correct
49 Correct 45 ms 35344 KB Output is correct
50 Correct 36 ms 34680 KB Output is correct
51 Correct 64 ms 35496 KB Output is correct
52 Correct 70 ms 36160 KB Output is correct
53 Correct 71 ms 35432 KB Output is correct
54 Correct 65 ms 36180 KB Output is correct
55 Correct 63 ms 35532 KB Output is correct
56 Correct 658 ms 68728 KB Output is correct
57 Correct 620 ms 82780 KB Output is correct
58 Correct 591 ms 79324 KB Output is correct
59 Correct 634 ms 81092 KB Output is correct
60 Correct 645 ms 83600 KB Output is correct