Submission #1119857

# Submission time Handle Problem Language Result Execution time Memory
1119857 2024-11-27T14:06:47 Z Aviansh Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 75080 KB
#include <bits/stdc++.h>

using namespace std;

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,q;
    cin >> n >> q;
    int h[n];
    vector<int> mp[1000005];
    for(int i = 0;i<n;i++){
        cin >> h[i];
        mp[h[i]].push_back(i);
    }
    pair<int,int> qs[q];
    for(int i = 0;i<q;i++){
        int y;
        cin >> y;
        qs[i]={y,i};
    }
    sort(qs,qs+q);
    long long ans[q];
    long long currans = ((1LL*n*(n-1))/2)+n;
    set<pair<int,int>>rangs;
    rangs.insert({0,n-1});
    int las = 1e6+1;
    bool wor = 1;
    for(int i = q-1;i>=0;i--){
        while(wor&&las>qs[i].first){
            for(int i : (mp[las])){
                set<pair<int,int>>::iterator it = (--rangs.upper_bound({i,2e9}));
                pair<int,int>p = *it;
                int len = p.second-p.first+1;
                currans-=((1LL*len*(len-1))/2)+len;
                rangs.erase(it);
                if(p.first!=i){
                    rangs.insert({p.first,i-1});
                    len = i-p.first;
                    currans+=((1LL*len*(len-1))/2)+len;
                }
                if(p.second!=i){
                    rangs.insert({i+1,p.second});
                    len = p.second-i;
                    currans+=((1LL*len*(len-1))/2)+len;
                }
            }
            if(las==0){
                wor=0;
            }
            las--;
        }
        ans[qs[i].second]=currans;
    }
    for(long long i : ans){
        cout << i << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23888 KB Output is correct
2 Correct 28 ms 23888 KB Output is correct
3 Correct 24 ms 23888 KB Output is correct
4 Correct 27 ms 23760 KB Output is correct
5 Correct 30 ms 23888 KB Output is correct
6 Correct 25 ms 23888 KB Output is correct
7 Correct 23 ms 23888 KB Output is correct
8 Correct 26 ms 23888 KB Output is correct
9 Correct 21 ms 23888 KB Output is correct
10 Correct 21 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23888 KB Output is correct
2 Correct 28 ms 23888 KB Output is correct
3 Correct 24 ms 23888 KB Output is correct
4 Correct 27 ms 23760 KB Output is correct
5 Correct 30 ms 23888 KB Output is correct
6 Correct 25 ms 23888 KB Output is correct
7 Correct 23 ms 23888 KB Output is correct
8 Correct 26 ms 23888 KB Output is correct
9 Correct 21 ms 23888 KB Output is correct
10 Correct 21 ms 23764 KB Output is correct
11 Correct 24 ms 23888 KB Output is correct
12 Correct 26 ms 23888 KB Output is correct
13 Correct 24 ms 23696 KB Output is correct
14 Correct 25 ms 23888 KB Output is correct
15 Correct 25 ms 23932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23888 KB Output is correct
2 Correct 28 ms 23888 KB Output is correct
3 Correct 24 ms 23888 KB Output is correct
4 Correct 27 ms 23760 KB Output is correct
5 Correct 30 ms 23888 KB Output is correct
6 Correct 25 ms 23888 KB Output is correct
7 Correct 23 ms 23888 KB Output is correct
8 Correct 26 ms 23888 KB Output is correct
9 Correct 21 ms 23888 KB Output is correct
10 Correct 21 ms 23764 KB Output is correct
11 Correct 24 ms 23888 KB Output is correct
12 Correct 26 ms 23888 KB Output is correct
13 Correct 24 ms 23696 KB Output is correct
14 Correct 25 ms 23888 KB Output is correct
15 Correct 25 ms 23932 KB Output is correct
16 Correct 39 ms 23748 KB Output is correct
17 Correct 27 ms 23888 KB Output is correct
18 Correct 32 ms 23740 KB Output is correct
19 Correct 28 ms 23956 KB Output is correct
20 Correct 28 ms 23908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23888 KB Output is correct
2 Correct 28 ms 23888 KB Output is correct
3 Correct 24 ms 23888 KB Output is correct
4 Correct 27 ms 23760 KB Output is correct
5 Correct 30 ms 23888 KB Output is correct
6 Correct 25 ms 23888 KB Output is correct
7 Correct 23 ms 23888 KB Output is correct
8 Correct 26 ms 23888 KB Output is correct
9 Correct 21 ms 23888 KB Output is correct
10 Correct 21 ms 23764 KB Output is correct
11 Correct 24 ms 23888 KB Output is correct
12 Correct 26 ms 23888 KB Output is correct
13 Correct 24 ms 23696 KB Output is correct
14 Correct 25 ms 23888 KB Output is correct
15 Correct 25 ms 23932 KB Output is correct
16 Correct 39 ms 23748 KB Output is correct
17 Correct 27 ms 23888 KB Output is correct
18 Correct 32 ms 23740 KB Output is correct
19 Correct 28 ms 23956 KB Output is correct
20 Correct 28 ms 23908 KB Output is correct
21 Correct 36 ms 23888 KB Output is correct
22 Correct 32 ms 23876 KB Output is correct
23 Correct 25 ms 23888 KB Output is correct
24 Correct 24 ms 23888 KB Output is correct
25 Correct 26 ms 23888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 26192 KB Output is correct
2 Correct 44 ms 27140 KB Output is correct
3 Correct 38 ms 25936 KB Output is correct
4 Correct 51 ms 26776 KB Output is correct
5 Correct 49 ms 25952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 29472 KB Output is correct
2 Correct 66 ms 29520 KB Output is correct
3 Correct 66 ms 29472 KB Output is correct
4 Correct 57 ms 29588 KB Output is correct
5 Correct 55 ms 29512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 29448 KB Output is correct
2 Correct 60 ms 29512 KB Output is correct
3 Correct 73 ms 29480 KB Output is correct
4 Correct 65 ms 29768 KB Output is correct
5 Correct 58 ms 29824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23888 KB Output is correct
2 Correct 28 ms 23888 KB Output is correct
3 Correct 24 ms 23888 KB Output is correct
4 Correct 27 ms 23760 KB Output is correct
5 Correct 30 ms 23888 KB Output is correct
6 Correct 25 ms 23888 KB Output is correct
7 Correct 23 ms 23888 KB Output is correct
8 Correct 26 ms 23888 KB Output is correct
9 Correct 21 ms 23888 KB Output is correct
10 Correct 21 ms 23764 KB Output is correct
11 Correct 44 ms 26192 KB Output is correct
12 Correct 44 ms 27140 KB Output is correct
13 Correct 38 ms 25936 KB Output is correct
14 Correct 51 ms 26776 KB Output is correct
15 Correct 49 ms 25952 KB Output is correct
16 Correct 48 ms 26960 KB Output is correct
17 Correct 83 ms 28240 KB Output is correct
18 Correct 78 ms 28236 KB Output is correct
19 Correct 69 ms 27160 KB Output is correct
20 Correct 70 ms 28084 KB Output is correct
21 Correct 39 ms 25968 KB Output is correct
22 Correct 73 ms 28048 KB Output is correct
23 Correct 65 ms 27280 KB Output is correct
24 Correct 81 ms 27976 KB Output is correct
25 Correct 67 ms 27140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23888 KB Output is correct
2 Correct 28 ms 23888 KB Output is correct
3 Correct 24 ms 23888 KB Output is correct
4 Correct 27 ms 23760 KB Output is correct
5 Correct 30 ms 23888 KB Output is correct
6 Correct 25 ms 23888 KB Output is correct
7 Correct 23 ms 23888 KB Output is correct
8 Correct 26 ms 23888 KB Output is correct
9 Correct 21 ms 23888 KB Output is correct
10 Correct 21 ms 23764 KB Output is correct
11 Correct 24 ms 23888 KB Output is correct
12 Correct 26 ms 23888 KB Output is correct
13 Correct 24 ms 23696 KB Output is correct
14 Correct 25 ms 23888 KB Output is correct
15 Correct 25 ms 23932 KB Output is correct
16 Correct 39 ms 23748 KB Output is correct
17 Correct 27 ms 23888 KB Output is correct
18 Correct 32 ms 23740 KB Output is correct
19 Correct 28 ms 23956 KB Output is correct
20 Correct 28 ms 23908 KB Output is correct
21 Correct 36 ms 23888 KB Output is correct
22 Correct 32 ms 23876 KB Output is correct
23 Correct 25 ms 23888 KB Output is correct
24 Correct 24 ms 23888 KB Output is correct
25 Correct 26 ms 23888 KB Output is correct
26 Correct 44 ms 26192 KB Output is correct
27 Correct 44 ms 27140 KB Output is correct
28 Correct 38 ms 25936 KB Output is correct
29 Correct 51 ms 26776 KB Output is correct
30 Correct 49 ms 25952 KB Output is correct
31 Correct 72 ms 29472 KB Output is correct
32 Correct 66 ms 29520 KB Output is correct
33 Correct 66 ms 29472 KB Output is correct
34 Correct 57 ms 29588 KB Output is correct
35 Correct 55 ms 29512 KB Output is correct
36 Correct 87 ms 29448 KB Output is correct
37 Correct 60 ms 29512 KB Output is correct
38 Correct 73 ms 29480 KB Output is correct
39 Correct 65 ms 29768 KB Output is correct
40 Correct 58 ms 29824 KB Output is correct
41 Correct 48 ms 26960 KB Output is correct
42 Correct 83 ms 28240 KB Output is correct
43 Correct 78 ms 28236 KB Output is correct
44 Correct 69 ms 27160 KB Output is correct
45 Correct 70 ms 28084 KB Output is correct
46 Correct 39 ms 25968 KB Output is correct
47 Correct 73 ms 28048 KB Output is correct
48 Correct 65 ms 27280 KB Output is correct
49 Correct 81 ms 27976 KB Output is correct
50 Correct 67 ms 27140 KB Output is correct
51 Correct 95 ms 29516 KB Output is correct
52 Correct 123 ms 30280 KB Output is correct
53 Correct 98 ms 29512 KB Output is correct
54 Correct 103 ms 30168 KB Output is correct
55 Correct 88 ms 29512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23888 KB Output is correct
2 Correct 28 ms 23888 KB Output is correct
3 Correct 24 ms 23888 KB Output is correct
4 Correct 27 ms 23760 KB Output is correct
5 Correct 30 ms 23888 KB Output is correct
6 Correct 25 ms 23888 KB Output is correct
7 Correct 23 ms 23888 KB Output is correct
8 Correct 26 ms 23888 KB Output is correct
9 Correct 21 ms 23888 KB Output is correct
10 Correct 21 ms 23764 KB Output is correct
11 Correct 24 ms 23888 KB Output is correct
12 Correct 26 ms 23888 KB Output is correct
13 Correct 24 ms 23696 KB Output is correct
14 Correct 25 ms 23888 KB Output is correct
15 Correct 25 ms 23932 KB Output is correct
16 Correct 39 ms 23748 KB Output is correct
17 Correct 27 ms 23888 KB Output is correct
18 Correct 32 ms 23740 KB Output is correct
19 Correct 28 ms 23956 KB Output is correct
20 Correct 28 ms 23908 KB Output is correct
21 Correct 36 ms 23888 KB Output is correct
22 Correct 32 ms 23876 KB Output is correct
23 Correct 25 ms 23888 KB Output is correct
24 Correct 24 ms 23888 KB Output is correct
25 Correct 26 ms 23888 KB Output is correct
26 Correct 44 ms 26192 KB Output is correct
27 Correct 44 ms 27140 KB Output is correct
28 Correct 38 ms 25936 KB Output is correct
29 Correct 51 ms 26776 KB Output is correct
30 Correct 49 ms 25952 KB Output is correct
31 Correct 72 ms 29472 KB Output is correct
32 Correct 66 ms 29520 KB Output is correct
33 Correct 66 ms 29472 KB Output is correct
34 Correct 57 ms 29588 KB Output is correct
35 Correct 55 ms 29512 KB Output is correct
36 Correct 87 ms 29448 KB Output is correct
37 Correct 60 ms 29512 KB Output is correct
38 Correct 73 ms 29480 KB Output is correct
39 Correct 65 ms 29768 KB Output is correct
40 Correct 58 ms 29824 KB Output is correct
41 Correct 48 ms 26960 KB Output is correct
42 Correct 83 ms 28240 KB Output is correct
43 Correct 78 ms 28236 KB Output is correct
44 Correct 69 ms 27160 KB Output is correct
45 Correct 70 ms 28084 KB Output is correct
46 Correct 39 ms 25968 KB Output is correct
47 Correct 73 ms 28048 KB Output is correct
48 Correct 65 ms 27280 KB Output is correct
49 Correct 81 ms 27976 KB Output is correct
50 Correct 67 ms 27140 KB Output is correct
51 Correct 95 ms 29516 KB Output is correct
52 Correct 123 ms 30280 KB Output is correct
53 Correct 98 ms 29512 KB Output is correct
54 Correct 103 ms 30168 KB Output is correct
55 Correct 88 ms 29512 KB Output is correct
56 Execution timed out 1073 ms 75080 KB Time limit exceeded
57 Halted 0 ms 0 KB -