답안 #867805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867805 2023-10-29T13:38:35 Z sleepntsheep Pilot (NOI19_pilot) C++17
100 / 100
825 ms 39064 KB
#include <iostream>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;
#define N 1000005
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,tune=native")


int n, q;
array<int, 2> a[N], b[N];
set<int> s;
ll z, c[N], fw[N];
inline ll C2(ll x) { return x*(x+1)/2; }

inline int upd(int p) { for (;p<N;p+=p&-p) ++fw[p]; return p; }
inline int qry(int p) { int z=0; for (;p;p-=p&-p)z+=fw[p];return z; }
inline int search(int k)
{
    int p = 0, s = 0;
    for (int j=21;j--;) if (p+(1<<j)<N && s+fw[p+(1<<j)]<=k) s += fw[p+=1<<j];
    return p+1;
}

int main()
{
    ShinLena;
    cin >> n >> q;
    for (int i = 0; i < n; ++i) cin >> a[i][0], a[i][1] = i + 2;
    for (int i = 0; i < q; ++i) cin >> b[i][0], b[i][1] = i;
    upd(1); upd(n+2);
    sort(a, a+n);
    sort(b, b+q);
    z = C2(n);
    for (int i = q, j = n - 1; i--;)
    {
        for (; j >= 0 && a[j][0] > b[i][0]; --j)
        {
            int cn = qry(a[j][1]), r = search(cn), l = search(cn-1);
            ll w = (r-l-1), wl=a[j][1]-l-1, wr =r-a[j][1]-1;
            z += -C2(w) + C2(wl) + C2(wr);
            upd(a[j][1]);
        }
        c[b[i][1]] = z;
    }
    for (int i = 0; i < q; ++i) cout << c[i] << '\n';


    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 1 ms 10588 KB Output is correct
17 Correct 1 ms 10584 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 1 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 1 ms 10588 KB Output is correct
17 Correct 1 ms 10584 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 1 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
21 Correct 2 ms 10584 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 10588 KB Output is correct
2 Correct 15 ms 10588 KB Output is correct
3 Correct 15 ms 10716 KB Output is correct
4 Correct 14 ms 10712 KB Output is correct
5 Correct 15 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 13908 KB Output is correct
2 Correct 39 ms 13776 KB Output is correct
3 Correct 39 ms 14160 KB Output is correct
4 Correct 40 ms 13912 KB Output is correct
5 Correct 41 ms 13908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 13824 KB Output is correct
2 Correct 42 ms 13808 KB Output is correct
3 Correct 39 ms 13740 KB Output is correct
4 Correct 40 ms 13652 KB Output is correct
5 Correct 46 ms 13804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 15 ms 10588 KB Output is correct
12 Correct 15 ms 10588 KB Output is correct
13 Correct 15 ms 10716 KB Output is correct
14 Correct 14 ms 10712 KB Output is correct
15 Correct 15 ms 10588 KB Output is correct
16 Correct 22 ms 10844 KB Output is correct
17 Correct 33 ms 10840 KB Output is correct
18 Correct 42 ms 10628 KB Output is correct
19 Correct 37 ms 10836 KB Output is correct
20 Correct 28 ms 10752 KB Output is correct
21 Correct 14 ms 10720 KB Output is correct
22 Correct 27 ms 10836 KB Output is correct
23 Correct 36 ms 10628 KB Output is correct
24 Correct 37 ms 10832 KB Output is correct
25 Correct 28 ms 11088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 1 ms 10588 KB Output is correct
17 Correct 1 ms 10584 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 1 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
21 Correct 2 ms 10584 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 15 ms 10588 KB Output is correct
27 Correct 15 ms 10588 KB Output is correct
28 Correct 15 ms 10716 KB Output is correct
29 Correct 14 ms 10712 KB Output is correct
30 Correct 15 ms 10588 KB Output is correct
31 Correct 38 ms 13908 KB Output is correct
32 Correct 39 ms 13776 KB Output is correct
33 Correct 39 ms 14160 KB Output is correct
34 Correct 40 ms 13912 KB Output is correct
35 Correct 41 ms 13908 KB Output is correct
36 Correct 39 ms 13824 KB Output is correct
37 Correct 42 ms 13808 KB Output is correct
38 Correct 39 ms 13740 KB Output is correct
39 Correct 40 ms 13652 KB Output is correct
40 Correct 46 ms 13804 KB Output is correct
41 Correct 22 ms 10844 KB Output is correct
42 Correct 33 ms 10840 KB Output is correct
43 Correct 42 ms 10628 KB Output is correct
44 Correct 37 ms 10836 KB Output is correct
45 Correct 28 ms 10752 KB Output is correct
46 Correct 14 ms 10720 KB Output is correct
47 Correct 27 ms 10836 KB Output is correct
48 Correct 36 ms 10628 KB Output is correct
49 Correct 37 ms 10832 KB Output is correct
50 Correct 28 ms 11088 KB Output is correct
51 Correct 64 ms 13648 KB Output is correct
52 Correct 61 ms 13528 KB Output is correct
53 Correct 65 ms 13700 KB Output is correct
54 Correct 63 ms 13552 KB Output is correct
55 Correct 65 ms 13552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 1 ms 10588 KB Output is correct
17 Correct 1 ms 10584 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 1 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
21 Correct 2 ms 10584 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 15 ms 10588 KB Output is correct
27 Correct 15 ms 10588 KB Output is correct
28 Correct 15 ms 10716 KB Output is correct
29 Correct 14 ms 10712 KB Output is correct
30 Correct 15 ms 10588 KB Output is correct
31 Correct 38 ms 13908 KB Output is correct
32 Correct 39 ms 13776 KB Output is correct
33 Correct 39 ms 14160 KB Output is correct
34 Correct 40 ms 13912 KB Output is correct
35 Correct 41 ms 13908 KB Output is correct
36 Correct 39 ms 13824 KB Output is correct
37 Correct 42 ms 13808 KB Output is correct
38 Correct 39 ms 13740 KB Output is correct
39 Correct 40 ms 13652 KB Output is correct
40 Correct 46 ms 13804 KB Output is correct
41 Correct 22 ms 10844 KB Output is correct
42 Correct 33 ms 10840 KB Output is correct
43 Correct 42 ms 10628 KB Output is correct
44 Correct 37 ms 10836 KB Output is correct
45 Correct 28 ms 10752 KB Output is correct
46 Correct 14 ms 10720 KB Output is correct
47 Correct 27 ms 10836 KB Output is correct
48 Correct 36 ms 10628 KB Output is correct
49 Correct 37 ms 10832 KB Output is correct
50 Correct 28 ms 11088 KB Output is correct
51 Correct 64 ms 13648 KB Output is correct
52 Correct 61 ms 13528 KB Output is correct
53 Correct 65 ms 13700 KB Output is correct
54 Correct 63 ms 13552 KB Output is correct
55 Correct 65 ms 13552 KB Output is correct
56 Correct 765 ms 38856 KB Output is correct
57 Correct 806 ms 38552 KB Output is correct
58 Correct 732 ms 38304 KB Output is correct
59 Correct 706 ms 38304 KB Output is correct
60 Correct 825 ms 39064 KB Output is correct