답안 #248675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
248675 2020-07-13T05:21:50 Z SamAnd Pilot (NOI19_pilot) C++17
100 / 100
694 ms 53112 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 1000006;
struct ban
{
    int x, i;
};
bool operator<(const ban& a, const ban& b)
{
    return a.x < b.x;
}

int n, m;
ban a[N];
ban b[N];

int p[N], q[N];
bool c[N];
int fi(int x)
{
    if (x == p[x])
        return x;
    return p[x] = fi(p[x]);
}

ll yans;

void kpc(int x, int y)
{
    x = fi(x);
    y = fi(y);
    yans -= (q[x] * 1LL * (q[x] + 1)) / 2;
    yans -= (q[y] * 1LL * (q[y] + 1)) / 2;
    p[x] = y;
    q[y] += q[x];
    yans += (q[y] * 1LL * (q[y] + 1)) / 2;
}

ll ans[N];

void solv()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
    {
        a[i].i = i;
        scanf("%d", &a[i].x);
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= m; ++i)
    {
        b[i].i = i;
        scanf("%d", &b[i].x);
    }
    sort(b + 1, b + m + 1);

    for (int i = 1; i <= n; ++i)
    {
        p[i] = i;
    }

    int j = 1;
    for (int i = 1; i <= m; ++i)
    {
        while (j <= n && a[j].x <= b[i].x)
        {
            q[a[j].i] = 1;
            ++yans;
            c[a[j].i] = true;
            if (c[a[j].i - 1])
                kpc(a[j].i, a[j].i - 1);
            if (c[a[j].i + 1])
                kpc(a[j].i, a[j].i + 1);
            ++j;
        }
        ans[b[i].i] = yans;
    }
    for (int i = 1; i <= m; ++i)
        printf("%lld\n", ans[i]);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}

Compilation message

pilot.cpp: In function 'void solv()':
pilot.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
pilot.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i].x);
         ~~~~~^~~~~~~~~~~~~~~
pilot.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &b[i].x);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1916 KB Output is correct
2 Correct 26 ms 2680 KB Output is correct
3 Correct 25 ms 2424 KB Output is correct
4 Correct 29 ms 2568 KB Output is correct
5 Correct 24 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 4296 KB Output is correct
2 Correct 60 ms 4436 KB Output is correct
3 Correct 49 ms 4344 KB Output is correct
4 Correct 50 ms 4600 KB Output is correct
5 Correct 50 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 4344 KB Output is correct
2 Correct 50 ms 4344 KB Output is correct
3 Correct 50 ms 4344 KB Output is correct
4 Correct 49 ms 4344 KB Output is correct
5 Correct 51 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 25 ms 1916 KB Output is correct
12 Correct 26 ms 2680 KB Output is correct
13 Correct 25 ms 2424 KB Output is correct
14 Correct 29 ms 2568 KB Output is correct
15 Correct 24 ms 2424 KB Output is correct
16 Correct 23 ms 2432 KB Output is correct
17 Correct 24 ms 2680 KB Output is correct
18 Correct 24 ms 2748 KB Output is correct
19 Correct 21 ms 2424 KB Output is correct
20 Correct 24 ms 2688 KB Output is correct
21 Correct 25 ms 2432 KB Output is correct
22 Correct 23 ms 2552 KB Output is correct
23 Correct 23 ms 2560 KB Output is correct
24 Correct 23 ms 2560 KB Output is correct
25 Correct 24 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 25 ms 1916 KB Output is correct
27 Correct 26 ms 2680 KB Output is correct
28 Correct 25 ms 2424 KB Output is correct
29 Correct 29 ms 2568 KB Output is correct
30 Correct 24 ms 2424 KB Output is correct
31 Correct 48 ms 4296 KB Output is correct
32 Correct 60 ms 4436 KB Output is correct
33 Correct 49 ms 4344 KB Output is correct
34 Correct 50 ms 4600 KB Output is correct
35 Correct 50 ms 4344 KB Output is correct
36 Correct 50 ms 4344 KB Output is correct
37 Correct 50 ms 4344 KB Output is correct
38 Correct 50 ms 4344 KB Output is correct
39 Correct 49 ms 4344 KB Output is correct
40 Correct 51 ms 4600 KB Output is correct
41 Correct 23 ms 2432 KB Output is correct
42 Correct 24 ms 2680 KB Output is correct
43 Correct 24 ms 2748 KB Output is correct
44 Correct 21 ms 2424 KB Output is correct
45 Correct 24 ms 2688 KB Output is correct
46 Correct 25 ms 2432 KB Output is correct
47 Correct 23 ms 2552 KB Output is correct
48 Correct 23 ms 2560 KB Output is correct
49 Correct 23 ms 2560 KB Output is correct
50 Correct 24 ms 2552 KB Output is correct
51 Correct 61 ms 5416 KB Output is correct
52 Correct 61 ms 5368 KB Output is correct
53 Correct 59 ms 5496 KB Output is correct
54 Correct 59 ms 5368 KB Output is correct
55 Correct 59 ms 5368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 25 ms 1916 KB Output is correct
27 Correct 26 ms 2680 KB Output is correct
28 Correct 25 ms 2424 KB Output is correct
29 Correct 29 ms 2568 KB Output is correct
30 Correct 24 ms 2424 KB Output is correct
31 Correct 48 ms 4296 KB Output is correct
32 Correct 60 ms 4436 KB Output is correct
33 Correct 49 ms 4344 KB Output is correct
34 Correct 50 ms 4600 KB Output is correct
35 Correct 50 ms 4344 KB Output is correct
36 Correct 50 ms 4344 KB Output is correct
37 Correct 50 ms 4344 KB Output is correct
38 Correct 50 ms 4344 KB Output is correct
39 Correct 49 ms 4344 KB Output is correct
40 Correct 51 ms 4600 KB Output is correct
41 Correct 23 ms 2432 KB Output is correct
42 Correct 24 ms 2680 KB Output is correct
43 Correct 24 ms 2748 KB Output is correct
44 Correct 21 ms 2424 KB Output is correct
45 Correct 24 ms 2688 KB Output is correct
46 Correct 25 ms 2432 KB Output is correct
47 Correct 23 ms 2552 KB Output is correct
48 Correct 23 ms 2560 KB Output is correct
49 Correct 23 ms 2560 KB Output is correct
50 Correct 24 ms 2552 KB Output is correct
51 Correct 61 ms 5416 KB Output is correct
52 Correct 61 ms 5368 KB Output is correct
53 Correct 59 ms 5496 KB Output is correct
54 Correct 59 ms 5368 KB Output is correct
55 Correct 59 ms 5368 KB Output is correct
56 Correct 693 ms 52216 KB Output is correct
57 Correct 687 ms 51576 KB Output is correct
58 Correct 653 ms 48764 KB Output is correct
59 Correct 650 ms 49912 KB Output is correct
60 Correct 694 ms 53112 KB Output is correct