답안 #1086782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086782 2024-09-11T13:18:30 Z Muhammad_Aneeq Pilot (NOI19_pilot) C++17
100 / 100
345 ms 52536 KB
/*
بسم الله الرحمن الرحيم
Author:
                          (:Muhammad Aneeq:)
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int const N=1e6+10;
int h[N];
int n,q;
long long ANS[N]={};
int pa[N]={};
long long sz[N]={};
int root(int n)
{
    int z=n;
    while (pa[z]!=z)
        z=pa[z];
    int g=z;
    z=n;
    while (pa[z]!=z)
    {
        int f=pa[z];
        pa[z]=g;
        z=f;
    }
    return 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]<<'\n';
    }
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19804 KB Output is correct
2 Correct 9 ms 19804 KB Output is correct
3 Correct 9 ms 19804 KB Output is correct
4 Correct 8 ms 19800 KB Output is correct
5 Correct 9 ms 19804 KB Output is correct
6 Correct 8 ms 19824 KB Output is correct
7 Correct 9 ms 19912 KB Output is correct
8 Correct 9 ms 19800 KB Output is correct
9 Correct 8 ms 19800 KB Output is correct
10 Correct 8 ms 19804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19804 KB Output is correct
2 Correct 9 ms 19804 KB Output is correct
3 Correct 9 ms 19804 KB Output is correct
4 Correct 8 ms 19800 KB Output is correct
5 Correct 9 ms 19804 KB Output is correct
6 Correct 8 ms 19824 KB Output is correct
7 Correct 9 ms 19912 KB Output is correct
8 Correct 9 ms 19800 KB Output is correct
9 Correct 8 ms 19800 KB Output is correct
10 Correct 8 ms 19804 KB Output is correct
11 Correct 9 ms 19804 KB Output is correct
12 Correct 9 ms 19804 KB Output is correct
13 Correct 8 ms 19880 KB Output is correct
14 Correct 11 ms 19872 KB Output is correct
15 Correct 9 ms 19804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19804 KB Output is correct
2 Correct 9 ms 19804 KB Output is correct
3 Correct 9 ms 19804 KB Output is correct
4 Correct 8 ms 19800 KB Output is correct
5 Correct 9 ms 19804 KB Output is correct
6 Correct 8 ms 19824 KB Output is correct
7 Correct 9 ms 19912 KB Output is correct
8 Correct 9 ms 19800 KB Output is correct
9 Correct 8 ms 19800 KB Output is correct
10 Correct 8 ms 19804 KB Output is correct
11 Correct 9 ms 19804 KB Output is correct
12 Correct 9 ms 19804 KB Output is correct
13 Correct 8 ms 19880 KB Output is correct
14 Correct 11 ms 19872 KB Output is correct
15 Correct 9 ms 19804 KB Output is correct
16 Correct 10 ms 19804 KB Output is correct
17 Correct 10 ms 19888 KB Output is correct
18 Correct 9 ms 19804 KB Output is correct
19 Correct 9 ms 19804 KB Output is correct
20 Correct 9 ms 19800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19804 KB Output is correct
2 Correct 9 ms 19804 KB Output is correct
3 Correct 9 ms 19804 KB Output is correct
4 Correct 8 ms 19800 KB Output is correct
5 Correct 9 ms 19804 KB Output is correct
6 Correct 8 ms 19824 KB Output is correct
7 Correct 9 ms 19912 KB Output is correct
8 Correct 9 ms 19800 KB Output is correct
9 Correct 8 ms 19800 KB Output is correct
10 Correct 8 ms 19804 KB Output is correct
11 Correct 9 ms 19804 KB Output is correct
12 Correct 9 ms 19804 KB Output is correct
13 Correct 8 ms 19880 KB Output is correct
14 Correct 11 ms 19872 KB Output is correct
15 Correct 9 ms 19804 KB Output is correct
16 Correct 10 ms 19804 KB Output is correct
17 Correct 10 ms 19888 KB Output is correct
18 Correct 9 ms 19804 KB Output is correct
19 Correct 9 ms 19804 KB Output is correct
20 Correct 9 ms 19800 KB Output is correct
21 Correct 9 ms 20060 KB Output is correct
22 Correct 10 ms 19916 KB Output is correct
23 Correct 9 ms 19956 KB Output is correct
24 Correct 11 ms 20060 KB Output is correct
25 Correct 10 ms 20060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 21196 KB Output is correct
2 Correct 31 ms 21180 KB Output is correct
3 Correct 26 ms 21196 KB Output is correct
4 Correct 26 ms 21072 KB Output is correct
5 Correct 26 ms 21200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 22224 KB Output is correct
2 Correct 31 ms 22164 KB Output is correct
3 Correct 32 ms 22224 KB Output is correct
4 Correct 29 ms 22220 KB Output is correct
5 Correct 31 ms 22228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 22212 KB Output is correct
2 Correct 32 ms 22216 KB Output is correct
3 Correct 31 ms 22216 KB Output is correct
4 Correct 31 ms 22224 KB Output is correct
5 Correct 32 ms 22224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19804 KB Output is correct
2 Correct 9 ms 19804 KB Output is correct
3 Correct 9 ms 19804 KB Output is correct
4 Correct 8 ms 19800 KB Output is correct
5 Correct 9 ms 19804 KB Output is correct
6 Correct 8 ms 19824 KB Output is correct
7 Correct 9 ms 19912 KB Output is correct
8 Correct 9 ms 19800 KB Output is correct
9 Correct 8 ms 19800 KB Output is correct
10 Correct 8 ms 19804 KB Output is correct
11 Correct 28 ms 21196 KB Output is correct
12 Correct 31 ms 21180 KB Output is correct
13 Correct 26 ms 21196 KB Output is correct
14 Correct 26 ms 21072 KB Output is correct
15 Correct 26 ms 21200 KB Output is correct
16 Correct 26 ms 21236 KB Output is correct
17 Correct 28 ms 21200 KB Output is correct
18 Correct 26 ms 21196 KB Output is correct
19 Correct 27 ms 21000 KB Output is correct
20 Correct 30 ms 21144 KB Output is correct
21 Correct 23 ms 21208 KB Output is correct
22 Correct 25 ms 21196 KB Output is correct
23 Correct 27 ms 21204 KB Output is correct
24 Correct 27 ms 21204 KB Output is correct
25 Correct 25 ms 21300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19804 KB Output is correct
2 Correct 9 ms 19804 KB Output is correct
3 Correct 9 ms 19804 KB Output is correct
4 Correct 8 ms 19800 KB Output is correct
5 Correct 9 ms 19804 KB Output is correct
6 Correct 8 ms 19824 KB Output is correct
7 Correct 9 ms 19912 KB Output is correct
8 Correct 9 ms 19800 KB Output is correct
9 Correct 8 ms 19800 KB Output is correct
10 Correct 8 ms 19804 KB Output is correct
11 Correct 9 ms 19804 KB Output is correct
12 Correct 9 ms 19804 KB Output is correct
13 Correct 8 ms 19880 KB Output is correct
14 Correct 11 ms 19872 KB Output is correct
15 Correct 9 ms 19804 KB Output is correct
16 Correct 10 ms 19804 KB Output is correct
17 Correct 10 ms 19888 KB Output is correct
18 Correct 9 ms 19804 KB Output is correct
19 Correct 9 ms 19804 KB Output is correct
20 Correct 9 ms 19800 KB Output is correct
21 Correct 9 ms 20060 KB Output is correct
22 Correct 10 ms 19916 KB Output is correct
23 Correct 9 ms 19956 KB Output is correct
24 Correct 11 ms 20060 KB Output is correct
25 Correct 10 ms 20060 KB Output is correct
26 Correct 28 ms 21196 KB Output is correct
27 Correct 31 ms 21180 KB Output is correct
28 Correct 26 ms 21196 KB Output is correct
29 Correct 26 ms 21072 KB Output is correct
30 Correct 26 ms 21200 KB Output is correct
31 Correct 29 ms 22224 KB Output is correct
32 Correct 31 ms 22164 KB Output is correct
33 Correct 32 ms 22224 KB Output is correct
34 Correct 29 ms 22220 KB Output is correct
35 Correct 31 ms 22228 KB Output is correct
36 Correct 33 ms 22212 KB Output is correct
37 Correct 32 ms 22216 KB Output is correct
38 Correct 31 ms 22216 KB Output is correct
39 Correct 31 ms 22224 KB Output is correct
40 Correct 32 ms 22224 KB Output is correct
41 Correct 26 ms 21236 KB Output is correct
42 Correct 28 ms 21200 KB Output is correct
43 Correct 26 ms 21196 KB Output is correct
44 Correct 27 ms 21000 KB Output is correct
45 Correct 30 ms 21144 KB Output is correct
46 Correct 23 ms 21208 KB Output is correct
47 Correct 25 ms 21196 KB Output is correct
48 Correct 27 ms 21204 KB Output is correct
49 Correct 27 ms 21204 KB Output is correct
50 Correct 25 ms 21300 KB Output is correct
51 Correct 42 ms 22068 KB Output is correct
52 Correct 39 ms 21708 KB Output is correct
53 Correct 41 ms 21964 KB Output is correct
54 Correct 44 ms 21896 KB Output is correct
55 Correct 38 ms 21964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19804 KB Output is correct
2 Correct 9 ms 19804 KB Output is correct
3 Correct 9 ms 19804 KB Output is correct
4 Correct 8 ms 19800 KB Output is correct
5 Correct 9 ms 19804 KB Output is correct
6 Correct 8 ms 19824 KB Output is correct
7 Correct 9 ms 19912 KB Output is correct
8 Correct 9 ms 19800 KB Output is correct
9 Correct 8 ms 19800 KB Output is correct
10 Correct 8 ms 19804 KB Output is correct
11 Correct 9 ms 19804 KB Output is correct
12 Correct 9 ms 19804 KB Output is correct
13 Correct 8 ms 19880 KB Output is correct
14 Correct 11 ms 19872 KB Output is correct
15 Correct 9 ms 19804 KB Output is correct
16 Correct 10 ms 19804 KB Output is correct
17 Correct 10 ms 19888 KB Output is correct
18 Correct 9 ms 19804 KB Output is correct
19 Correct 9 ms 19804 KB Output is correct
20 Correct 9 ms 19800 KB Output is correct
21 Correct 9 ms 20060 KB Output is correct
22 Correct 10 ms 19916 KB Output is correct
23 Correct 9 ms 19956 KB Output is correct
24 Correct 11 ms 20060 KB Output is correct
25 Correct 10 ms 20060 KB Output is correct
26 Correct 28 ms 21196 KB Output is correct
27 Correct 31 ms 21180 KB Output is correct
28 Correct 26 ms 21196 KB Output is correct
29 Correct 26 ms 21072 KB Output is correct
30 Correct 26 ms 21200 KB Output is correct
31 Correct 29 ms 22224 KB Output is correct
32 Correct 31 ms 22164 KB Output is correct
33 Correct 32 ms 22224 KB Output is correct
34 Correct 29 ms 22220 KB Output is correct
35 Correct 31 ms 22228 KB Output is correct
36 Correct 33 ms 22212 KB Output is correct
37 Correct 32 ms 22216 KB Output is correct
38 Correct 31 ms 22216 KB Output is correct
39 Correct 31 ms 22224 KB Output is correct
40 Correct 32 ms 22224 KB Output is correct
41 Correct 26 ms 21236 KB Output is correct
42 Correct 28 ms 21200 KB Output is correct
43 Correct 26 ms 21196 KB Output is correct
44 Correct 27 ms 21000 KB Output is correct
45 Correct 30 ms 21144 KB Output is correct
46 Correct 23 ms 21208 KB Output is correct
47 Correct 25 ms 21196 KB Output is correct
48 Correct 27 ms 21204 KB Output is correct
49 Correct 27 ms 21204 KB Output is correct
50 Correct 25 ms 21300 KB Output is correct
51 Correct 42 ms 22068 KB Output is correct
52 Correct 39 ms 21708 KB Output is correct
53 Correct 41 ms 21964 KB Output is correct
54 Correct 44 ms 21896 KB Output is correct
55 Correct 38 ms 21964 KB Output is correct
56 Correct 345 ms 40112 KB Output is correct
57 Correct 325 ms 51640 KB Output is correct
58 Correct 308 ms 49848 KB Output is correct
59 Correct 318 ms 50492 KB Output is correct
60 Correct 329 ms 52536 KB Output is correct