Submission #134125

# Submission time Handle Problem Language Result Execution time Memory
134125 2019-07-22T06:14:17 Z SamAnd Lottery (CEOI18_lot) C++17
100 / 100
1951 ms 8416 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 10004, Q = 102;
struct ban
{
    int i;
    int d;
};
bool operator<(const ban& a, const ban& b)
{
    return a.d < b.d;
}

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

int t[N];

int p[N];
int np[N];

int ans[Q][N];
int hh[Q];

int ka()
{
    int x = 0;
    while (1)
    {
        char y = getchar();
        if (y == ' ' || y == '\n')
            return x;
        x = (x * 10) + (y - '0');
    }
}

char e[10];
void tp(int x)
{
    if (x == 0)
    {
        putchar('0');
        putchar(' ');
        return;
    }
    int i = 0;
    while (x)
    {
        e[i++] = (x % 10) + '0';
        x /= 10;
    }
    for (i = i - 1; i >= 0; --i)
        putchar(e[i]);
    putchar(' ');
}

int main()
{
    n = ka();
    m = ka();
    for (int i = 1; i <= n; ++i)
        a[i] = ka();
    q = ka();
    for (int i = 1; i <= q; ++i)
    {
        b[i].i = i;
        b[i].d = ka();
    }
    sort(b + 1, b + q + 1);
    for (int d = 0; d <= m; ++d)
    {
        int l = 1, r = q;
        while ((r - l) > 4)
        {
            int m = (l + r) / 2;
            if (b[m].d >= d)
                r = m;
            else
                l = m;
        }
        bool z = false;
        for (int m = l; m <= r; ++m)
        {
            if (b[m].d >= d)
            {
                t[d] = m;
                z = true;
                break;
            }
        }
        if (!z)
            t[d] = q + 1;
    }
    for (int i = 1; i <= n; ++i)
    {
        memset(np, 0, sizeof np);
        for (int j = 1; j <= n; ++j)
        {
            np[j] = p[j - 1];
            if (a[i] != a[j])
                ++np[j];
            if (i - m >= 1 && j - m >= 1)
            {
                if (a[i - m] != a[j - m])
                    --np[j];
            }
        }
        memcpy(p, np, sizeof np);
        for (int j = m; j <= n; ++j)
        {
            if (i == j)
                continue;
            ans[t[p[j]]][i]++;
            /*for (int k = 1; k <= q; ++k)
            {
                if (p[j] <= b[k].d)
                    ans[b[k].i][i]++;
            }*/
        }
    }
    for (int j = m; j <= n; ++j)
    {
        for (int i = 1; i <= q; ++i)
            ans[i][j] += ans[i - 1][j];
    }
    for (int i = 1; i <= q; ++i)
        hh[b[i].i] = i;
    for (int i = 1; i <= q; ++i)
    {
        for (int j = m; j <= n; ++j)
            tp(ans[hh[i]][j]);
        putchar('\n');
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 4 ms 504 KB Output is correct
13 Correct 57 ms 520 KB Output is correct
14 Correct 36 ms 632 KB Output is correct
15 Correct 36 ms 632 KB Output is correct
16 Correct 45 ms 760 KB Output is correct
17 Correct 42 ms 760 KB Output is correct
18 Correct 42 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1609 ms 648 KB Output is correct
2 Correct 1865 ms 760 KB Output is correct
3 Correct 1161 ms 684 KB Output is correct
4 Correct 954 ms 872 KB Output is correct
5 Correct 531 ms 632 KB Output is correct
6 Correct 888 ms 892 KB Output is correct
7 Correct 515 ms 504 KB Output is correct
8 Correct 659 ms 696 KB Output is correct
9 Correct 934 ms 812 KB Output is correct
10 Correct 937 ms 640 KB Output is correct
11 Correct 72 ms 376 KB Output is correct
12 Correct 624 ms 760 KB Output is correct
13 Correct 615 ms 636 KB Output is correct
14 Correct 625 ms 772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1609 ms 648 KB Output is correct
2 Correct 1865 ms 760 KB Output is correct
3 Correct 1161 ms 684 KB Output is correct
4 Correct 954 ms 872 KB Output is correct
5 Correct 531 ms 632 KB Output is correct
6 Correct 888 ms 892 KB Output is correct
7 Correct 515 ms 504 KB Output is correct
8 Correct 659 ms 696 KB Output is correct
9 Correct 934 ms 812 KB Output is correct
10 Correct 937 ms 640 KB Output is correct
11 Correct 72 ms 376 KB Output is correct
12 Correct 624 ms 760 KB Output is correct
13 Correct 615 ms 636 KB Output is correct
14 Correct 625 ms 772 KB Output is correct
15 Correct 1151 ms 812 KB Output is correct
16 Correct 890 ms 760 KB Output is correct
17 Correct 965 ms 860 KB Output is correct
18 Correct 948 ms 768 KB Output is correct
19 Correct 947 ms 796 KB Output is correct
20 Correct 949 ms 664 KB Output is correct
21 Correct 942 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 4 ms 504 KB Output is correct
13 Correct 57 ms 520 KB Output is correct
14 Correct 36 ms 632 KB Output is correct
15 Correct 36 ms 632 KB Output is correct
16 Correct 45 ms 760 KB Output is correct
17 Correct 42 ms 760 KB Output is correct
18 Correct 42 ms 760 KB Output is correct
19 Correct 1609 ms 648 KB Output is correct
20 Correct 1865 ms 760 KB Output is correct
21 Correct 1161 ms 684 KB Output is correct
22 Correct 954 ms 872 KB Output is correct
23 Correct 531 ms 632 KB Output is correct
24 Correct 888 ms 892 KB Output is correct
25 Correct 515 ms 504 KB Output is correct
26 Correct 659 ms 696 KB Output is correct
27 Correct 934 ms 812 KB Output is correct
28 Correct 937 ms 640 KB Output is correct
29 Correct 72 ms 376 KB Output is correct
30 Correct 624 ms 760 KB Output is correct
31 Correct 615 ms 636 KB Output is correct
32 Correct 625 ms 772 KB Output is correct
33 Correct 1151 ms 812 KB Output is correct
34 Correct 890 ms 760 KB Output is correct
35 Correct 965 ms 860 KB Output is correct
36 Correct 948 ms 768 KB Output is correct
37 Correct 947 ms 796 KB Output is correct
38 Correct 949 ms 664 KB Output is correct
39 Correct 942 ms 764 KB Output is correct
40 Correct 1878 ms 2316 KB Output is correct
41 Correct 350 ms 876 KB Output is correct
42 Correct 959 ms 2188 KB Output is correct
43 Correct 918 ms 1912 KB Output is correct
44 Correct 928 ms 1912 KB Output is correct
45 Correct 1951 ms 8248 KB Output is correct
46 Correct 356 ms 2040 KB Output is correct
47 Correct 1022 ms 8416 KB Output is correct
48 Correct 964 ms 6652 KB Output is correct
49 Correct 965 ms 7404 KB Output is correct