Submission #743696

# Submission time Handle Problem Language Result Execution time Memory
743696 2023-05-17T17:53:57 Z KG07 Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 43564 KB
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[2100000];
int h[1000001];
long long d[1000001];
priority_queue<pair<int, int>> q;
void L(int x, int y, bool z){
    int x_ = x, y_ = y;
    if(!z){
        x_ = 0;
        y_ = 0;
    }
    while(x < y){
        if(x % 2 == 1){
            a[x].first = x_;
            a[x].second = y_;
            x++;
        }
        if(y % 2 == 0){
            a[y].first = x_;
            a[y].second = y_;
            y--;
        }
        x /= 2;
        y /= 2;
    }
    if(x == y){
        a[x].first = x_;
        a[y].second = y_;
    }
}
int g(int x){
    while(!a[x].first){
        x /= 2;
    }
    return x;
}

int main() {
    // Write C++ code here
    int n, m;
    cin >> n >> m;
    int k = 1, o = 0;
    while(k < n){
        k *= 2;
    }
    for(int i = 0; i < n; i++){
        cin >> h[i];
        q.push({h[i], i});
        o = max(o, h[i]);
    }
    L(k, k+n-1, true);
    while(!q.empty()){
        int w = q.top().first;
        int z = q.top().second;
        q.pop();
        int t = g(k+z);
        int x = a[t].first, y = a[t].second;
        L(a[t].first, a[t].second, false);
        d[w] += 1ll * (k+z-x+1) * (y-k-z+1);
        if(k+z == x && k+z == y){
            continue;
        }
        if(k+z > x){
            L(x, k+z-1, true);
        }
        if(k+z < y){
            L(k+z+1, y, true);
        }
    }
    for(int i = o; i; i--){
        d[i-1] += d[i];
    }
    for(int i = 0; i < m; i++){
        int w;
        cin >> w;
        cout << 1ll * n * (n+1) / 2 - d[w+1] << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4016 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 5 ms 7308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 6 ms 7700 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 4 ms 5972 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4016 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 5 ms 7308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 6 ms 7700 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 4 ms 5972 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 5 ms 7764 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 8112 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4016 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 5 ms 7308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 6 ms 7700 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 4 ms 5972 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 5 ms 7764 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 8112 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 6 ms 8020 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 6 ms 8020 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4016 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 5 ms 7308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 6 ms 7700 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 4 ms 5972 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 5 ms 7764 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 8112 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 6 ms 8020 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 6 ms 8020 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 316 KB Output is correct
22 Correct 7 ms 8148 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 8 ms 8148 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 4288 KB Output is correct
2 Correct 54 ms 11584 KB Output is correct
3 Correct 47 ms 4332 KB Output is correct
4 Correct 49 ms 11328 KB Output is correct
5 Correct 54 ms 4160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 5184 KB Output is correct
2 Correct 218 ms 5236 KB Output is correct
3 Correct 200 ms 5180 KB Output is correct
4 Correct 203 ms 5332 KB Output is correct
5 Correct 226 ms 5168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 12316 KB Output is correct
2 Correct 221 ms 12216 KB Output is correct
3 Correct 205 ms 12236 KB Output is correct
4 Correct 218 ms 12436 KB Output is correct
5 Correct 220 ms 12392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4016 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 5 ms 7308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 6 ms 7700 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 4 ms 5972 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 44 ms 4288 KB Output is correct
12 Correct 54 ms 11584 KB Output is correct
13 Correct 47 ms 4332 KB Output is correct
14 Correct 49 ms 11328 KB Output is correct
15 Correct 54 ms 4160 KB Output is correct
16 Correct 49 ms 4160 KB Output is correct
17 Correct 71 ms 11592 KB Output is correct
18 Correct 59 ms 11620 KB Output is correct
19 Correct 44 ms 4160 KB Output is correct
20 Correct 59 ms 11444 KB Output is correct
21 Correct 45 ms 4160 KB Output is correct
22 Correct 53 ms 11372 KB Output is correct
23 Correct 51 ms 4412 KB Output is correct
24 Correct 56 ms 11284 KB Output is correct
25 Correct 45 ms 4404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4016 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 5 ms 7308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 6 ms 7700 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 4 ms 5972 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 5 ms 7764 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 8112 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 6 ms 8020 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 6 ms 8020 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 316 KB Output is correct
22 Correct 7 ms 8148 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 8 ms 8148 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 44 ms 4288 KB Output is correct
27 Correct 54 ms 11584 KB Output is correct
28 Correct 47 ms 4332 KB Output is correct
29 Correct 49 ms 11328 KB Output is correct
30 Correct 54 ms 4160 KB Output is correct
31 Correct 203 ms 5184 KB Output is correct
32 Correct 218 ms 5236 KB Output is correct
33 Correct 200 ms 5180 KB Output is correct
34 Correct 203 ms 5332 KB Output is correct
35 Correct 226 ms 5168 KB Output is correct
36 Correct 207 ms 12316 KB Output is correct
37 Correct 221 ms 12216 KB Output is correct
38 Correct 205 ms 12236 KB Output is correct
39 Correct 218 ms 12436 KB Output is correct
40 Correct 220 ms 12392 KB Output is correct
41 Correct 49 ms 4160 KB Output is correct
42 Correct 71 ms 11592 KB Output is correct
43 Correct 59 ms 11620 KB Output is correct
44 Correct 44 ms 4160 KB Output is correct
45 Correct 59 ms 11444 KB Output is correct
46 Correct 45 ms 4160 KB Output is correct
47 Correct 53 ms 11372 KB Output is correct
48 Correct 51 ms 4412 KB Output is correct
49 Correct 56 ms 11284 KB Output is correct
50 Correct 45 ms 4404 KB Output is correct
51 Correct 211 ms 5804 KB Output is correct
52 Correct 200 ms 12764 KB Output is correct
53 Correct 188 ms 5856 KB Output is correct
54 Correct 213 ms 12804 KB Output is correct
55 Correct 203 ms 5824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4016 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 5 ms 7308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 6 ms 7700 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 4 ms 5972 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 5 ms 7764 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 8112 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 6 ms 8020 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 6 ms 8020 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 316 KB Output is correct
22 Correct 7 ms 8148 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 8 ms 8148 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 44 ms 4288 KB Output is correct
27 Correct 54 ms 11584 KB Output is correct
28 Correct 47 ms 4332 KB Output is correct
29 Correct 49 ms 11328 KB Output is correct
30 Correct 54 ms 4160 KB Output is correct
31 Correct 203 ms 5184 KB Output is correct
32 Correct 218 ms 5236 KB Output is correct
33 Correct 200 ms 5180 KB Output is correct
34 Correct 203 ms 5332 KB Output is correct
35 Correct 226 ms 5168 KB Output is correct
36 Correct 207 ms 12316 KB Output is correct
37 Correct 221 ms 12216 KB Output is correct
38 Correct 205 ms 12236 KB Output is correct
39 Correct 218 ms 12436 KB Output is correct
40 Correct 220 ms 12392 KB Output is correct
41 Correct 49 ms 4160 KB Output is correct
42 Correct 71 ms 11592 KB Output is correct
43 Correct 59 ms 11620 KB Output is correct
44 Correct 44 ms 4160 KB Output is correct
45 Correct 59 ms 11444 KB Output is correct
46 Correct 45 ms 4160 KB Output is correct
47 Correct 53 ms 11372 KB Output is correct
48 Correct 51 ms 4412 KB Output is correct
49 Correct 56 ms 11284 KB Output is correct
50 Correct 45 ms 4404 KB Output is correct
51 Correct 211 ms 5804 KB Output is correct
52 Correct 200 ms 12764 KB Output is correct
53 Correct 188 ms 5856 KB Output is correct
54 Correct 213 ms 12804 KB Output is correct
55 Correct 203 ms 5824 KB Output is correct
56 Execution timed out 1034 ms 43564 KB Time limit exceeded
57 Halted 0 ms 0 KB -