Submission #1086766

# Submission time Handle Problem Language Result Execution time Memory
1086766 2024-09-11T12:30:03 Z Muhammad_Aneeq Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 40564 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;
    vector<int>g;
    for (auto k:Q)
    {
        int mx=k.first;
        long long ans=pre;
        g={};
        while (i<n&&d[i].first<=mx)
        {
            g.push_back(d[i].second);
            i++;
        }
        for (auto j:g)
        {
            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++;
        }
        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();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 344 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 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 344 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 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 0 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 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 344 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 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 0 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 604 KB Output is correct
16 Correct 1 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 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 344 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 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 0 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 604 KB Output is correct
16 Correct 1 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 0 ms 348 KB Output is correct
20 Correct 0 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 1 ms 348 KB Output is correct
25 Correct 1 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 3328 KB Output is correct
2 Correct 84 ms 3568 KB Output is correct
3 Correct 80 ms 3360 KB Output is correct
4 Correct 74 ms 3348 KB Output is correct
5 Correct 77 ms 3288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 5452 KB Output is correct
2 Correct 72 ms 5708 KB Output is correct
3 Correct 69 ms 5460 KB Output is correct
4 Correct 72 ms 5708 KB Output is correct
5 Correct 69 ms 5452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 5716 KB Output is correct
2 Correct 71 ms 5688 KB Output is correct
3 Correct 70 ms 5712 KB Output is correct
4 Correct 76 ms 5664 KB Output is correct
5 Correct 75 ms 5968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 344 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 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 82 ms 3328 KB Output is correct
12 Correct 84 ms 3568 KB Output is correct
13 Correct 80 ms 3360 KB Output is correct
14 Correct 74 ms 3348 KB Output is correct
15 Correct 77 ms 3288 KB Output is correct
16 Correct 56 ms 2776 KB Output is correct
17 Correct 37 ms 3028 KB Output is correct
18 Correct 24 ms 2772 KB Output is correct
19 Correct 18 ms 2520 KB Output is correct
20 Correct 45 ms 3028 KB Output is correct
21 Correct 76 ms 3284 KB Output is correct
22 Correct 44 ms 3028 KB Output is correct
23 Correct 32 ms 2776 KB Output is correct
24 Correct 24 ms 2524 KB Output is correct
25 Correct 47 ms 2776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 344 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 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 0 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 604 KB Output is correct
16 Correct 1 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 0 ms 348 KB Output is correct
20 Correct 0 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 1 ms 348 KB Output is correct
25 Correct 1 ms 472 KB Output is correct
26 Correct 82 ms 3328 KB Output is correct
27 Correct 84 ms 3568 KB Output is correct
28 Correct 80 ms 3360 KB Output is correct
29 Correct 74 ms 3348 KB Output is correct
30 Correct 77 ms 3288 KB Output is correct
31 Correct 69 ms 5452 KB Output is correct
32 Correct 72 ms 5708 KB Output is correct
33 Correct 69 ms 5460 KB Output is correct
34 Correct 72 ms 5708 KB Output is correct
35 Correct 69 ms 5452 KB Output is correct
36 Correct 73 ms 5716 KB Output is correct
37 Correct 71 ms 5688 KB Output is correct
38 Correct 70 ms 5712 KB Output is correct
39 Correct 76 ms 5664 KB Output is correct
40 Correct 75 ms 5968 KB Output is correct
41 Correct 56 ms 2776 KB Output is correct
42 Correct 37 ms 3028 KB Output is correct
43 Correct 24 ms 2772 KB Output is correct
44 Correct 18 ms 2520 KB Output is correct
45 Correct 45 ms 3028 KB Output is correct
46 Correct 76 ms 3284 KB Output is correct
47 Correct 44 ms 3028 KB Output is correct
48 Correct 32 ms 2776 KB Output is correct
49 Correct 24 ms 2524 KB Output is correct
50 Correct 47 ms 2776 KB Output is correct
51 Correct 102 ms 5576 KB Output is correct
52 Correct 97 ms 5536 KB Output is correct
53 Correct 101 ms 5456 KB Output is correct
54 Correct 112 ms 5408 KB Output is correct
55 Correct 100 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 344 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 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 0 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 604 KB Output is correct
16 Correct 1 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 0 ms 348 KB Output is correct
20 Correct 0 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 1 ms 348 KB Output is correct
25 Correct 1 ms 472 KB Output is correct
26 Correct 82 ms 3328 KB Output is correct
27 Correct 84 ms 3568 KB Output is correct
28 Correct 80 ms 3360 KB Output is correct
29 Correct 74 ms 3348 KB Output is correct
30 Correct 77 ms 3288 KB Output is correct
31 Correct 69 ms 5452 KB Output is correct
32 Correct 72 ms 5708 KB Output is correct
33 Correct 69 ms 5460 KB Output is correct
34 Correct 72 ms 5708 KB Output is correct
35 Correct 69 ms 5452 KB Output is correct
36 Correct 73 ms 5716 KB Output is correct
37 Correct 71 ms 5688 KB Output is correct
38 Correct 70 ms 5712 KB Output is correct
39 Correct 76 ms 5664 KB Output is correct
40 Correct 75 ms 5968 KB Output is correct
41 Correct 56 ms 2776 KB Output is correct
42 Correct 37 ms 3028 KB Output is correct
43 Correct 24 ms 2772 KB Output is correct
44 Correct 18 ms 2520 KB Output is correct
45 Correct 45 ms 3028 KB Output is correct
46 Correct 76 ms 3284 KB Output is correct
47 Correct 44 ms 3028 KB Output is correct
48 Correct 32 ms 2776 KB Output is correct
49 Correct 24 ms 2524 KB Output is correct
50 Correct 47 ms 2776 KB Output is correct
51 Correct 102 ms 5576 KB Output is correct
52 Correct 97 ms 5536 KB Output is correct
53 Correct 101 ms 5456 KB Output is correct
54 Correct 112 ms 5408 KB Output is correct
55 Correct 100 ms 5456 KB Output is correct
56 Execution timed out 1037 ms 40564 KB Time limit exceeded
57 Halted 0 ms 0 KB -