답안 #1086767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086767 2024-09-11T12:32:47 Z Muhammad_Aneeq Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 43440 KB
/*
بسم الله الرحمن الرحيم
Author:
                          (:Muhammad Aneeq:)
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int const N=1e6+10;
int fen[N]={};
int h[N];
int n,q;
int sum(int r)
{
    int s=0;
    for (;r>=0;r=(r&(r+1))-1)
        s+=fen[r];
    return s;
}
int get(int l,int r)
{
    return sum(r)-sum(l-1);
}
void update(int i)
{
    for (;i<n;i=(i|(i+1)))
        fen[i]++;
}
inline void solve()
{
    cin>>n>>q;
    for (int i=0;i<n;i++)
        cin>>h[i];
    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 mx=k.first;
        long long ans=pre;
        while (i<n&&d[i].first<=mx)
        {
            int j=d[i].second;
            update(j);
            int st=-1,en=j;
            while (st+1<en)
            {
                int mid=(st+en)/2;
                if (get(mid,j)==j-mid+1)
                    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)==mid-j+1)
                    st=mid;
                else
                    en=mid;
            }
            long long l2=st-j+1;
            ans+=(l1-1)*(l2-1);
            ans+=l2+l1-2;
            ans++;
            i++;
        }
        ANS[k.second]=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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 412 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 412 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 412 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 412 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2560 KB Output is correct
2 Correct 81 ms 2768 KB Output is correct
3 Correct 76 ms 2520 KB Output is correct
4 Correct 72 ms 2520 KB Output is correct
5 Correct 74 ms 2520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 5420 KB Output is correct
2 Correct 70 ms 5704 KB Output is correct
3 Correct 87 ms 5500 KB Output is correct
4 Correct 72 ms 5712 KB Output is correct
5 Correct 68 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 5712 KB Output is correct
2 Correct 74 ms 5704 KB Output is correct
3 Correct 69 ms 5716 KB Output is correct
4 Correct 81 ms 5680 KB Output is correct
5 Correct 84 ms 5828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 412 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 79 ms 2560 KB Output is correct
12 Correct 81 ms 2768 KB Output is correct
13 Correct 76 ms 2520 KB Output is correct
14 Correct 72 ms 2520 KB Output is correct
15 Correct 74 ms 2520 KB Output is correct
16 Correct 55 ms 2520 KB Output is correct
17 Correct 36 ms 2776 KB Output is correct
18 Correct 21 ms 2776 KB Output is correct
19 Correct 19 ms 2516 KB Output is correct
20 Correct 51 ms 2524 KB Output is correct
21 Correct 76 ms 2524 KB Output is correct
22 Correct 46 ms 2524 KB Output is correct
23 Correct 33 ms 2524 KB Output is correct
24 Correct 24 ms 2524 KB Output is correct
25 Correct 46 ms 2524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 412 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 79 ms 2560 KB Output is correct
27 Correct 81 ms 2768 KB Output is correct
28 Correct 76 ms 2520 KB Output is correct
29 Correct 72 ms 2520 KB Output is correct
30 Correct 74 ms 2520 KB Output is correct
31 Correct 69 ms 5420 KB Output is correct
32 Correct 70 ms 5704 KB Output is correct
33 Correct 87 ms 5500 KB Output is correct
34 Correct 72 ms 5712 KB Output is correct
35 Correct 68 ms 5456 KB Output is correct
36 Correct 73 ms 5712 KB Output is correct
37 Correct 74 ms 5704 KB Output is correct
38 Correct 69 ms 5716 KB Output is correct
39 Correct 81 ms 5680 KB Output is correct
40 Correct 84 ms 5828 KB Output is correct
41 Correct 55 ms 2520 KB Output is correct
42 Correct 36 ms 2776 KB Output is correct
43 Correct 21 ms 2776 KB Output is correct
44 Correct 19 ms 2516 KB Output is correct
45 Correct 51 ms 2524 KB Output is correct
46 Correct 76 ms 2524 KB Output is correct
47 Correct 46 ms 2524 KB Output is correct
48 Correct 33 ms 2524 KB Output is correct
49 Correct 24 ms 2524 KB Output is correct
50 Correct 46 ms 2524 KB Output is correct
51 Correct 102 ms 5460 KB Output is correct
52 Correct 98 ms 5400 KB Output is correct
53 Correct 109 ms 5460 KB Output is correct
54 Correct 94 ms 5384 KB Output is correct
55 Correct 103 ms 5528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 412 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 79 ms 2560 KB Output is correct
27 Correct 81 ms 2768 KB Output is correct
28 Correct 76 ms 2520 KB Output is correct
29 Correct 72 ms 2520 KB Output is correct
30 Correct 74 ms 2520 KB Output is correct
31 Correct 69 ms 5420 KB Output is correct
32 Correct 70 ms 5704 KB Output is correct
33 Correct 87 ms 5500 KB Output is correct
34 Correct 72 ms 5712 KB Output is correct
35 Correct 68 ms 5456 KB Output is correct
36 Correct 73 ms 5712 KB Output is correct
37 Correct 74 ms 5704 KB Output is correct
38 Correct 69 ms 5716 KB Output is correct
39 Correct 81 ms 5680 KB Output is correct
40 Correct 84 ms 5828 KB Output is correct
41 Correct 55 ms 2520 KB Output is correct
42 Correct 36 ms 2776 KB Output is correct
43 Correct 21 ms 2776 KB Output is correct
44 Correct 19 ms 2516 KB Output is correct
45 Correct 51 ms 2524 KB Output is correct
46 Correct 76 ms 2524 KB Output is correct
47 Correct 46 ms 2524 KB Output is correct
48 Correct 33 ms 2524 KB Output is correct
49 Correct 24 ms 2524 KB Output is correct
50 Correct 46 ms 2524 KB Output is correct
51 Correct 102 ms 5460 KB Output is correct
52 Correct 98 ms 5400 KB Output is correct
53 Correct 109 ms 5460 KB Output is correct
54 Correct 94 ms 5384 KB Output is correct
55 Correct 103 ms 5528 KB Output is correct
56 Execution timed out 1043 ms 43440 KB Time limit exceeded
57 Halted 0 ms 0 KB -