Submission #1096483

# Submission time Handle Problem Language Result Execution time Memory
1096483 2024-10-04T15:07:39 Z Trisanu_Das Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 102956 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second

int pairs(int l, int r){
    int len = r - l + 1;
    return len * (len + 1) / 2;
}

signed main() {
    ios_base::sync_with_stdio(0); 
    cin.tie(NULL);
    int n, q; cin >> n >> q;
    vector<pair<int, int> > qries(q), h(n);
    int ans[q];
    for(int i = 0; i < n; i++) {
        cin >> h[i].ff; h[i].ss = i;
    } 
    for(int i = 0; i < q; i++){
        cin >> qries[i].ff; qries[i].ss = i;
    }
    sort(qries.rbegin(), qries.rend());
    sort(h.begin(), h.end());
    set<int> s({-1, n});
    int curr = n - 1, ans_curr = n * (n + 1) / 2;
    for(auto qry : qries){
        int val = qry.ff, idx = qry.ss;
        while(curr > -1 && h[curr].ff > val){
            auto it = s.lower_bound(h[curr].ss);
            int r = *it, l = *(--it);
            r--; l++;
            ans_curr += pairs(l, h[curr].ss - 1) +
                   pairs(h[curr].ss + 1, r) -
                   pairs(l, r);
            s.insert(h[curr].ss); curr--;
        }
        ans[idx] = ans_curr;
    }
    for(auto a : ans) cout << a << '\n';
}
# Verdict Execution time Memory 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 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
# Verdict Execution time Memory 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 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 0 ms 456 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
# Verdict Execution time Memory 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 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 0 ms 456 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 456 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 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 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 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 0 ms 456 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 456 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 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 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2396 KB Output is correct
2 Correct 13 ms 2652 KB Output is correct
3 Correct 12 ms 2408 KB Output is correct
4 Correct 12 ms 2396 KB Output is correct
5 Correct 12 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 10504 KB Output is correct
2 Correct 46 ms 10580 KB Output is correct
3 Correct 50 ms 10324 KB Output is correct
4 Correct 52 ms 10696 KB Output is correct
5 Correct 48 ms 10352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 10720 KB Output is correct
2 Correct 57 ms 10612 KB Output is correct
3 Correct 60 ms 10536 KB Output is correct
4 Correct 51 ms 10832 KB Output is correct
5 Correct 51 ms 10804 KB Output is correct
# Verdict Execution time Memory 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 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 13 ms 2396 KB Output is correct
12 Correct 13 ms 2652 KB Output is correct
13 Correct 12 ms 2408 KB Output is correct
14 Correct 12 ms 2396 KB Output is correct
15 Correct 12 ms 2396 KB Output is correct
16 Correct 20 ms 3664 KB Output is correct
17 Correct 36 ms 5716 KB Output is correct
18 Correct 37 ms 6740 KB Output is correct
19 Correct 36 ms 6224 KB Output is correct
20 Correct 26 ms 4688 KB Output is correct
21 Correct 12 ms 2396 KB Output is correct
22 Correct 24 ms 4564 KB Output is correct
23 Correct 34 ms 5920 KB Output is correct
24 Correct 33 ms 5844 KB Output is correct
25 Correct 26 ms 4700 KB Output is correct
# Verdict Execution time Memory 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 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 0 ms 456 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 456 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 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 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 13 ms 2396 KB Output is correct
27 Correct 13 ms 2652 KB Output is correct
28 Correct 12 ms 2408 KB Output is correct
29 Correct 12 ms 2396 KB Output is correct
30 Correct 12 ms 2396 KB Output is correct
31 Correct 47 ms 10504 KB Output is correct
32 Correct 46 ms 10580 KB Output is correct
33 Correct 50 ms 10324 KB Output is correct
34 Correct 52 ms 10696 KB Output is correct
35 Correct 48 ms 10352 KB Output is correct
36 Correct 52 ms 10720 KB Output is correct
37 Correct 57 ms 10612 KB Output is correct
38 Correct 60 ms 10536 KB Output is correct
39 Correct 51 ms 10832 KB Output is correct
40 Correct 51 ms 10804 KB Output is correct
41 Correct 20 ms 3664 KB Output is correct
42 Correct 36 ms 5716 KB Output is correct
43 Correct 37 ms 6740 KB Output is correct
44 Correct 36 ms 6224 KB Output is correct
45 Correct 26 ms 4688 KB Output is correct
46 Correct 12 ms 2396 KB Output is correct
47 Correct 24 ms 4564 KB Output is correct
48 Correct 34 ms 5920 KB Output is correct
49 Correct 33 ms 5844 KB Output is correct
50 Correct 26 ms 4700 KB Output is correct
51 Correct 62 ms 10576 KB Output is correct
52 Correct 61 ms 10476 KB Output is correct
53 Correct 63 ms 10692 KB Output is correct
54 Correct 62 ms 10324 KB Output is correct
55 Correct 68 ms 10580 KB Output is correct
# Verdict Execution time Memory 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 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 0 ms 456 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 456 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 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 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 13 ms 2396 KB Output is correct
27 Correct 13 ms 2652 KB Output is correct
28 Correct 12 ms 2408 KB Output is correct
29 Correct 12 ms 2396 KB Output is correct
30 Correct 12 ms 2396 KB Output is correct
31 Correct 47 ms 10504 KB Output is correct
32 Correct 46 ms 10580 KB Output is correct
33 Correct 50 ms 10324 KB Output is correct
34 Correct 52 ms 10696 KB Output is correct
35 Correct 48 ms 10352 KB Output is correct
36 Correct 52 ms 10720 KB Output is correct
37 Correct 57 ms 10612 KB Output is correct
38 Correct 60 ms 10536 KB Output is correct
39 Correct 51 ms 10832 KB Output is correct
40 Correct 51 ms 10804 KB Output is correct
41 Correct 20 ms 3664 KB Output is correct
42 Correct 36 ms 5716 KB Output is correct
43 Correct 37 ms 6740 KB Output is correct
44 Correct 36 ms 6224 KB Output is correct
45 Correct 26 ms 4688 KB Output is correct
46 Correct 12 ms 2396 KB Output is correct
47 Correct 24 ms 4564 KB Output is correct
48 Correct 34 ms 5920 KB Output is correct
49 Correct 33 ms 5844 KB Output is correct
50 Correct 26 ms 4700 KB Output is correct
51 Correct 62 ms 10576 KB Output is correct
52 Correct 61 ms 10476 KB Output is correct
53 Correct 63 ms 10692 KB Output is correct
54 Correct 62 ms 10324 KB Output is correct
55 Correct 68 ms 10580 KB Output is correct
56 Execution timed out 1000 ms 102956 KB Time limit exceeded
57 Halted 0 ms 0 KB -