Submission #134122

# Submission time Handle Problem Language Result Execution time Memory
134122 2019-07-22T06:12:33 Z SamAnd Lottery (CEOI18_lot) C++17
100 / 100
1959 ms 12372 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 u[Q][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;
            u[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] + u[i][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 632 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 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 648 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 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 648 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 4 ms 632 KB Output is correct
13 Correct 56 ms 536 KB Output is correct
14 Correct 37 ms 684 KB Output is correct
15 Correct 37 ms 660 KB Output is correct
16 Correct 45 ms 924 KB Output is correct
17 Correct 42 ms 948 KB Output is correct
18 Correct 42 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1616 ms 688 KB Output is correct
2 Correct 1880 ms 792 KB Output is correct
3 Correct 1157 ms 804 KB Output is correct
4 Correct 935 ms 760 KB Output is correct
5 Correct 532 ms 792 KB Output is correct
6 Correct 892 ms 672 KB Output is correct
7 Correct 527 ms 632 KB Output is correct
8 Correct 691 ms 680 KB Output is correct
9 Correct 923 ms 740 KB Output is correct
10 Correct 938 ms 672 KB Output is correct
11 Correct 72 ms 504 KB Output is correct
12 Correct 620 ms 760 KB Output is correct
13 Correct 617 ms 648 KB Output is correct
14 Correct 622 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1616 ms 688 KB Output is correct
2 Correct 1880 ms 792 KB Output is correct
3 Correct 1157 ms 804 KB Output is correct
4 Correct 935 ms 760 KB Output is correct
5 Correct 532 ms 792 KB Output is correct
6 Correct 892 ms 672 KB Output is correct
7 Correct 527 ms 632 KB Output is correct
8 Correct 691 ms 680 KB Output is correct
9 Correct 923 ms 740 KB Output is correct
10 Correct 938 ms 672 KB Output is correct
11 Correct 72 ms 504 KB Output is correct
12 Correct 620 ms 760 KB Output is correct
13 Correct 617 ms 648 KB Output is correct
14 Correct 622 ms 764 KB Output is correct
15 Correct 1133 ms 768 KB Output is correct
16 Correct 895 ms 672 KB Output is correct
17 Correct 962 ms 860 KB Output is correct
18 Correct 938 ms 892 KB Output is correct
19 Correct 939 ms 892 KB Output is correct
20 Correct 941 ms 768 KB Output is correct
21 Correct 940 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 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 648 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 4 ms 632 KB Output is correct
13 Correct 56 ms 536 KB Output is correct
14 Correct 37 ms 684 KB Output is correct
15 Correct 37 ms 660 KB Output is correct
16 Correct 45 ms 924 KB Output is correct
17 Correct 42 ms 948 KB Output is correct
18 Correct 42 ms 956 KB Output is correct
19 Correct 1616 ms 688 KB Output is correct
20 Correct 1880 ms 792 KB Output is correct
21 Correct 1157 ms 804 KB Output is correct
22 Correct 935 ms 760 KB Output is correct
23 Correct 532 ms 792 KB Output is correct
24 Correct 892 ms 672 KB Output is correct
25 Correct 527 ms 632 KB Output is correct
26 Correct 691 ms 680 KB Output is correct
27 Correct 923 ms 740 KB Output is correct
28 Correct 938 ms 672 KB Output is correct
29 Correct 72 ms 504 KB Output is correct
30 Correct 620 ms 760 KB Output is correct
31 Correct 617 ms 648 KB Output is correct
32 Correct 622 ms 764 KB Output is correct
33 Correct 1133 ms 768 KB Output is correct
34 Correct 895 ms 672 KB Output is correct
35 Correct 962 ms 860 KB Output is correct
36 Correct 938 ms 892 KB Output is correct
37 Correct 939 ms 892 KB Output is correct
38 Correct 941 ms 768 KB Output is correct
39 Correct 940 ms 636 KB Output is correct
40 Correct 1881 ms 2592 KB Output is correct
41 Correct 351 ms 892 KB Output is correct
42 Correct 958 ms 3064 KB Output is correct
43 Correct 931 ms 2548 KB Output is correct
44 Correct 922 ms 2040 KB Output is correct
45 Correct 1959 ms 10400 KB Output is correct
46 Correct 356 ms 2012 KB Output is correct
47 Correct 1030 ms 12372 KB Output is correct
48 Correct 965 ms 10096 KB Output is correct
49 Correct 967 ms 8236 KB Output is correct