답안 #1086780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086780 2024-09-11T13:13:27 Z Muhammad_Aneeq Pilot (NOI19_pilot) C++17
78 / 100
168 ms 19660 KB
/*
بسم الله الرحمن الرحيم
Author:
                          (:Muhammad Aneeq:)
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int const N=1e6+10,LG=22;
int h[N];
int n,q;
long long ANS[N]={};
int pa[N]={};
int sz[N]={};
int root(int n)
{
    if (pa[n]==n)
        return n;
    return (pa[n]=root(pa[n]));
}
long long ans=0;
void merge(int u,int v)
{
    u=root(u);
    v=root(v);
    if (u==v)
        return;
    ans+=(sz[u]*sz[v]);
    sz[u]+=sz[v];
    pa[v]=u;
}
inline void solve()
{
    cin>>n>>q;
    for (int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    for (int i=0;i<N;i++)
        pa[i]=i,sz[i]=1;
    vector<pair<int,int>>d;
    for (int i=0;i<n;i++)
        d.push_back({h[i],i});
    sort(begin(d),end(d));
    int i=0;
    for (int mx=1;mx<N;mx++)
    {
        while (i<n&&d[i].first==mx)
        {
            if (d[i].second>0&&h[d[i].second-1]<=mx)
                merge(d[i].second,d[i].second-1);
            if (d[i].second+1<n&&h[d[i].second+1]<=mx)
                merge(d[i].second,d[i].second+1);
            i++;
            ans++;
        }
        ANS[mx]=ans;
    }
    while (q--)
    {
        int x;
        cin>>x;
        cout<<ANS[x]<<endl;
    }
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15964 KB Output is correct
2 Correct 7 ms 15964 KB Output is correct
3 Correct 7 ms 15964 KB Output is correct
4 Correct 7 ms 15972 KB Output is correct
5 Correct 7 ms 15924 KB Output is correct
6 Correct 7 ms 16072 KB Output is correct
7 Correct 7 ms 16084 KB Output is correct
8 Correct 7 ms 16088 KB Output is correct
9 Correct 9 ms 15964 KB Output is correct
10 Correct 7 ms 15960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15964 KB Output is correct
2 Correct 7 ms 15964 KB Output is correct
3 Correct 7 ms 15964 KB Output is correct
4 Correct 7 ms 15972 KB Output is correct
5 Correct 7 ms 15924 KB Output is correct
6 Correct 7 ms 16072 KB Output is correct
7 Correct 7 ms 16084 KB Output is correct
8 Correct 7 ms 16088 KB Output is correct
9 Correct 9 ms 15964 KB Output is correct
10 Correct 7 ms 15960 KB Output is correct
11 Correct 8 ms 15960 KB Output is correct
12 Correct 7 ms 15964 KB Output is correct
13 Correct 7 ms 16024 KB Output is correct
14 Correct 7 ms 15964 KB Output is correct
15 Correct 7 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15964 KB Output is correct
2 Correct 7 ms 15964 KB Output is correct
3 Correct 7 ms 15964 KB Output is correct
4 Correct 7 ms 15972 KB Output is correct
5 Correct 7 ms 15924 KB Output is correct
6 Correct 7 ms 16072 KB Output is correct
7 Correct 7 ms 16084 KB Output is correct
8 Correct 7 ms 16088 KB Output is correct
9 Correct 9 ms 15964 KB Output is correct
10 Correct 7 ms 15960 KB Output is correct
11 Correct 8 ms 15960 KB Output is correct
12 Correct 7 ms 15964 KB Output is correct
13 Correct 7 ms 16024 KB Output is correct
14 Correct 7 ms 15964 KB Output is correct
15 Correct 7 ms 15964 KB Output is correct
16 Correct 7 ms 15964 KB Output is correct
17 Correct 8 ms 15964 KB Output is correct
18 Correct 8 ms 16024 KB Output is correct
19 Correct 8 ms 15964 KB Output is correct
20 Correct 7 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15964 KB Output is correct
2 Correct 7 ms 15964 KB Output is correct
3 Correct 7 ms 15964 KB Output is correct
4 Correct 7 ms 15972 KB Output is correct
5 Correct 7 ms 15924 KB Output is correct
6 Correct 7 ms 16072 KB Output is correct
7 Correct 7 ms 16084 KB Output is correct
8 Correct 7 ms 16088 KB Output is correct
9 Correct 9 ms 15964 KB Output is correct
10 Correct 7 ms 15960 KB Output is correct
11 Correct 8 ms 15960 KB Output is correct
12 Correct 7 ms 15964 KB Output is correct
13 Correct 7 ms 16024 KB Output is correct
14 Correct 7 ms 15964 KB Output is correct
15 Correct 7 ms 15964 KB Output is correct
16 Correct 7 ms 15964 KB Output is correct
17 Correct 8 ms 15964 KB Output is correct
18 Correct 8 ms 16024 KB Output is correct
19 Correct 8 ms 15964 KB Output is correct
20 Correct 7 ms 15964 KB Output is correct
21 Correct 8 ms 15960 KB Output is correct
22 Correct 8 ms 15964 KB Output is correct
23 Correct 9 ms 15964 KB Output is correct
24 Correct 9 ms 15964 KB Output is correct
25 Correct 10 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 17876 KB Output is correct
2 Correct 27 ms 17980 KB Output is correct
3 Correct 22 ms 17872 KB Output is correct
4 Correct 23 ms 17852 KB Output is correct
5 Correct 23 ms 17612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 19324 KB Output is correct
2 Correct 133 ms 19284 KB Output is correct
3 Correct 125 ms 19204 KB Output is correct
4 Correct 121 ms 19400 KB Output is correct
5 Correct 118 ms 19384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 19404 KB Output is correct
2 Correct 124 ms 19404 KB Output is correct
3 Correct 127 ms 19400 KB Output is correct
4 Correct 119 ms 19392 KB Output is correct
5 Correct 130 ms 19660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15964 KB Output is correct
2 Correct 7 ms 15964 KB Output is correct
3 Correct 7 ms 15964 KB Output is correct
4 Correct 7 ms 15972 KB Output is correct
5 Correct 7 ms 15924 KB Output is correct
6 Correct 7 ms 16072 KB Output is correct
7 Correct 7 ms 16084 KB Output is correct
8 Correct 7 ms 16088 KB Output is correct
9 Correct 9 ms 15964 KB Output is correct
10 Correct 7 ms 15960 KB Output is correct
11 Correct 24 ms 17876 KB Output is correct
12 Correct 27 ms 17980 KB Output is correct
13 Correct 22 ms 17872 KB Output is correct
14 Correct 23 ms 17852 KB Output is correct
15 Correct 23 ms 17612 KB Output is correct
16 Correct 23 ms 17616 KB Output is correct
17 Correct 25 ms 17928 KB Output is correct
18 Correct 25 ms 18064 KB Output is correct
19 Correct 22 ms 17616 KB Output is correct
20 Correct 25 ms 17868 KB Output is correct
21 Correct 22 ms 17616 KB Output is correct
22 Correct 24 ms 17868 KB Output is correct
23 Correct 24 ms 17876 KB Output is correct
24 Correct 24 ms 17804 KB Output is correct
25 Correct 23 ms 17880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15964 KB Output is correct
2 Correct 7 ms 15964 KB Output is correct
3 Correct 7 ms 15964 KB Output is correct
4 Correct 7 ms 15972 KB Output is correct
5 Correct 7 ms 15924 KB Output is correct
6 Correct 7 ms 16072 KB Output is correct
7 Correct 7 ms 16084 KB Output is correct
8 Correct 7 ms 16088 KB Output is correct
9 Correct 9 ms 15964 KB Output is correct
10 Correct 7 ms 15960 KB Output is correct
11 Correct 8 ms 15960 KB Output is correct
12 Correct 7 ms 15964 KB Output is correct
13 Correct 7 ms 16024 KB Output is correct
14 Correct 7 ms 15964 KB Output is correct
15 Correct 7 ms 15964 KB Output is correct
16 Correct 7 ms 15964 KB Output is correct
17 Correct 8 ms 15964 KB Output is correct
18 Correct 8 ms 16024 KB Output is correct
19 Correct 8 ms 15964 KB Output is correct
20 Correct 7 ms 15964 KB Output is correct
21 Correct 8 ms 15960 KB Output is correct
22 Correct 8 ms 15964 KB Output is correct
23 Correct 9 ms 15964 KB Output is correct
24 Correct 9 ms 15964 KB Output is correct
25 Correct 10 ms 15964 KB Output is correct
26 Correct 24 ms 17876 KB Output is correct
27 Correct 27 ms 17980 KB Output is correct
28 Correct 22 ms 17872 KB Output is correct
29 Correct 23 ms 17852 KB Output is correct
30 Correct 23 ms 17612 KB Output is correct
31 Correct 137 ms 19324 KB Output is correct
32 Correct 133 ms 19284 KB Output is correct
33 Correct 125 ms 19204 KB Output is correct
34 Correct 121 ms 19400 KB Output is correct
35 Correct 118 ms 19384 KB Output is correct
36 Correct 115 ms 19404 KB Output is correct
37 Correct 124 ms 19404 KB Output is correct
38 Correct 127 ms 19400 KB Output is correct
39 Correct 119 ms 19392 KB Output is correct
40 Correct 130 ms 19660 KB Output is correct
41 Correct 23 ms 17616 KB Output is correct
42 Correct 25 ms 17928 KB Output is correct
43 Correct 25 ms 18064 KB Output is correct
44 Correct 22 ms 17616 KB Output is correct
45 Correct 25 ms 17868 KB Output is correct
46 Correct 22 ms 17616 KB Output is correct
47 Correct 24 ms 17868 KB Output is correct
48 Correct 24 ms 17876 KB Output is correct
49 Correct 24 ms 17804 KB Output is correct
50 Correct 23 ms 17880 KB Output is correct
51 Correct 128 ms 19304 KB Output is correct
52 Correct 168 ms 19148 KB Output is correct
53 Correct 127 ms 19152 KB Output is correct
54 Correct 126 ms 19152 KB Output is correct
55 Incorrect 123 ms 19148 KB Output isn't correct
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15964 KB Output is correct
2 Correct 7 ms 15964 KB Output is correct
3 Correct 7 ms 15964 KB Output is correct
4 Correct 7 ms 15972 KB Output is correct
5 Correct 7 ms 15924 KB Output is correct
6 Correct 7 ms 16072 KB Output is correct
7 Correct 7 ms 16084 KB Output is correct
8 Correct 7 ms 16088 KB Output is correct
9 Correct 9 ms 15964 KB Output is correct
10 Correct 7 ms 15960 KB Output is correct
11 Correct 8 ms 15960 KB Output is correct
12 Correct 7 ms 15964 KB Output is correct
13 Correct 7 ms 16024 KB Output is correct
14 Correct 7 ms 15964 KB Output is correct
15 Correct 7 ms 15964 KB Output is correct
16 Correct 7 ms 15964 KB Output is correct
17 Correct 8 ms 15964 KB Output is correct
18 Correct 8 ms 16024 KB Output is correct
19 Correct 8 ms 15964 KB Output is correct
20 Correct 7 ms 15964 KB Output is correct
21 Correct 8 ms 15960 KB Output is correct
22 Correct 8 ms 15964 KB Output is correct
23 Correct 9 ms 15964 KB Output is correct
24 Correct 9 ms 15964 KB Output is correct
25 Correct 10 ms 15964 KB Output is correct
26 Correct 24 ms 17876 KB Output is correct
27 Correct 27 ms 17980 KB Output is correct
28 Correct 22 ms 17872 KB Output is correct
29 Correct 23 ms 17852 KB Output is correct
30 Correct 23 ms 17612 KB Output is correct
31 Correct 137 ms 19324 KB Output is correct
32 Correct 133 ms 19284 KB Output is correct
33 Correct 125 ms 19204 KB Output is correct
34 Correct 121 ms 19400 KB Output is correct
35 Correct 118 ms 19384 KB Output is correct
36 Correct 115 ms 19404 KB Output is correct
37 Correct 124 ms 19404 KB Output is correct
38 Correct 127 ms 19400 KB Output is correct
39 Correct 119 ms 19392 KB Output is correct
40 Correct 130 ms 19660 KB Output is correct
41 Correct 23 ms 17616 KB Output is correct
42 Correct 25 ms 17928 KB Output is correct
43 Correct 25 ms 18064 KB Output is correct
44 Correct 22 ms 17616 KB Output is correct
45 Correct 25 ms 17868 KB Output is correct
46 Correct 22 ms 17616 KB Output is correct
47 Correct 24 ms 17868 KB Output is correct
48 Correct 24 ms 17876 KB Output is correct
49 Correct 24 ms 17804 KB Output is correct
50 Correct 23 ms 17880 KB Output is correct
51 Correct 128 ms 19304 KB Output is correct
52 Correct 168 ms 19148 KB Output is correct
53 Correct 127 ms 19152 KB Output is correct
54 Correct 126 ms 19152 KB Output is correct
55 Incorrect 123 ms 19148 KB Output isn't correct
56 Halted 0 ms 0 KB -