답안 #1086770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086770 2024-09-11T12:43:43 Z Muhammad_Aneeq Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 122036 KB
/*
بسم الله الرحمن الرحيم
Author:
                          (:Muhammad Aneeq:)
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int const N=1e6+10,LG=22;
int fen[N]={};
int sp[N][LG];
int h[N];
int n,q;
void build()
{
    for (int i=0;i<n;i++)
        sp[i][0]=h[i];
    for (int i=1;(1<<i)<=n;i++)
        for (int j=0;j+(1<<i)-1<n;j++)
            sp[j][i]=max(sp[j][i-1],sp[j+(1<<(i-1))][i-1]);
}
int get(int l,int r)
{
    int lg=log2(r-l+1);
    return max(sp[l][lg],sp[r-(1<<lg)+1][lg]);
}
inline void solve()
{
    cin>>n>>q;
    for (int i=0;i<n;i++)
        cin>>h[i];
    build();
    vector<pair<int,int>>d;
    for (int i=0;i<n;i++)
        d.push_back({h[i],i});
    sort(begin(d),end(d));
    long long ANS[q]={};
    vector<pair<int,int>>Q;
    for (int i=0;i<q;i++)
    {
        int x;
        cin>>x;
        Q.push_back({x,i});
    }
    sort(begin(Q),end(Q));
    int i=0;
    long long pre=0;
    for (auto k:Q)
    {
        int ind,mx;
        tie(mx,ind)=k;
        vector<int>g;
        long long ans=pre;
        while (i<n&&d[i].first<=mx)
        {
            g.push_back(d[i].second);
            i++;
        }
        sort(begin(g),end(g));
        int p=-1;
        for (auto j:g)
        {
            int st=p,en=j;
            while (st+1<en)
            {
                int mid=(st+en)/2;
                if (get(mid,j)<=mx)
                    en=mid;
                else
                    st=mid;
            }
            long long l1=j-en+1;
            st=j,en=n;
            while (st+1<en)
            {
                int mid=(st+en)/2;
                if (get(j,mid)<=mx)
                    st=mid;
                else
                    en=mid;
            }
            long long l2=st-j+1;
            ans+=(l1-1)*(l2-1);
            ans+=(l1-1);
            ans+=(l2-1);
            ans++;
            p=j;
        }
        ANS[ind]=ans;
        pre=ans;
    }
    for (auto i:ANS)
        cout<<i<<'\n';
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 11376 KB Output is correct
2 Correct 69 ms 11480 KB Output is correct
3 Correct 66 ms 11064 KB Output is correct
4 Correct 63 ms 10752 KB Output is correct
5 Correct 66 ms 10712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 13140 KB Output is correct
2 Correct 91 ms 13308 KB Output is correct
3 Correct 85 ms 13140 KB Output is correct
4 Correct 82 ms 13392 KB Output is correct
5 Correct 79 ms 12876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 13372 KB Output is correct
2 Correct 83 ms 13132 KB Output is correct
3 Correct 83 ms 13140 KB Output is correct
4 Correct 87 ms 14004 KB Output is correct
5 Correct 86 ms 13648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 68 ms 11376 KB Output is correct
12 Correct 69 ms 11480 KB Output is correct
13 Correct 66 ms 11064 KB Output is correct
14 Correct 63 ms 10752 KB Output is correct
15 Correct 66 ms 10712 KB Output is correct
16 Correct 49 ms 10460 KB Output is correct
17 Correct 37 ms 10972 KB Output is correct
18 Correct 26 ms 11228 KB Output is correct
19 Correct 24 ms 10200 KB Output is correct
20 Correct 43 ms 10968 KB Output is correct
21 Correct 64 ms 10584 KB Output is correct
22 Correct 42 ms 10712 KB Output is correct
23 Correct 34 ms 10968 KB Output is correct
24 Correct 29 ms 10448 KB Output is correct
25 Correct 44 ms 10716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 68 ms 11376 KB Output is correct
27 Correct 69 ms 11480 KB Output is correct
28 Correct 66 ms 11064 KB Output is correct
29 Correct 63 ms 10752 KB Output is correct
30 Correct 66 ms 10712 KB Output is correct
31 Correct 82 ms 13140 KB Output is correct
32 Correct 91 ms 13308 KB Output is correct
33 Correct 85 ms 13140 KB Output is correct
34 Correct 82 ms 13392 KB Output is correct
35 Correct 79 ms 12876 KB Output is correct
36 Correct 84 ms 13372 KB Output is correct
37 Correct 83 ms 13132 KB Output is correct
38 Correct 83 ms 13140 KB Output is correct
39 Correct 87 ms 14004 KB Output is correct
40 Correct 86 ms 13648 KB Output is correct
41 Correct 49 ms 10460 KB Output is correct
42 Correct 37 ms 10972 KB Output is correct
43 Correct 26 ms 11228 KB Output is correct
44 Correct 24 ms 10200 KB Output is correct
45 Correct 43 ms 10968 KB Output is correct
46 Correct 64 ms 10584 KB Output is correct
47 Correct 42 ms 10712 KB Output is correct
48 Correct 34 ms 10968 KB Output is correct
49 Correct 29 ms 10448 KB Output is correct
50 Correct 44 ms 10716 KB Output is correct
51 Correct 130 ms 13392 KB Output is correct
52 Correct 133 ms 13136 KB Output is correct
53 Correct 135 ms 13524 KB Output is correct
54 Correct 131 ms 13272 KB Output is correct
55 Correct 134 ms 13644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 68 ms 11376 KB Output is correct
27 Correct 69 ms 11480 KB Output is correct
28 Correct 66 ms 11064 KB Output is correct
29 Correct 63 ms 10752 KB Output is correct
30 Correct 66 ms 10712 KB Output is correct
31 Correct 82 ms 13140 KB Output is correct
32 Correct 91 ms 13308 KB Output is correct
33 Correct 85 ms 13140 KB Output is correct
34 Correct 82 ms 13392 KB Output is correct
35 Correct 79 ms 12876 KB Output is correct
36 Correct 84 ms 13372 KB Output is correct
37 Correct 83 ms 13132 KB Output is correct
38 Correct 83 ms 13140 KB Output is correct
39 Correct 87 ms 14004 KB Output is correct
40 Correct 86 ms 13648 KB Output is correct
41 Correct 49 ms 10460 KB Output is correct
42 Correct 37 ms 10972 KB Output is correct
43 Correct 26 ms 11228 KB Output is correct
44 Correct 24 ms 10200 KB Output is correct
45 Correct 43 ms 10968 KB Output is correct
46 Correct 64 ms 10584 KB Output is correct
47 Correct 42 ms 10712 KB Output is correct
48 Correct 34 ms 10968 KB Output is correct
49 Correct 29 ms 10448 KB Output is correct
50 Correct 44 ms 10716 KB Output is correct
51 Correct 130 ms 13392 KB Output is correct
52 Correct 133 ms 13136 KB Output is correct
53 Correct 135 ms 13524 KB Output is correct
54 Correct 131 ms 13272 KB Output is correct
55 Correct 134 ms 13644 KB Output is correct
56 Execution timed out 1046 ms 122036 KB Time limit exceeded
57 Halted 0 ms 0 KB -