过了但有疑问
查看原帖
过了但有疑问
932039
lzy20091001楼主2024/1/3 22:24

处理大于 mm 但没有被删除的元素时需要与上另一个 bitset,为什么输出时进行与会 WA,而每进行一次操作就与则 AC?

WA:

#include <iostream>
#include <bitset>

std::bitset<30005> s[30005];

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    int n, m, q;

    std::cin >> n >> m >> q;
    for (int i = 1; i <= n; i++)
    {
        int c;
        std::cin >> c;
        for (int j = 1; j <= c; j++)
        {
            int x;
            std::cin >> x;
            s[i].set(x - 1);
        }
    }
    for (int i = 0; i < m; i++)
        s[0].set(i);

    while (q--)
    {
        int o, x, y;
        std::cin >> o >> x >> y;
        if (o == 1)
            s[x] <<= y;
        else if (o == 2)
            s[x] >>= y;
        else if (o == 3)
            std::cout << (s[0] & s[x] & s[y]).count() << "\n";
        else if (o == 4)
            std::cout << ((s[0] & s[x]) | (s[0] & s[y])).count() << "\n";
        else
            std::cout << ((s[0] & s[x]) ^ (s[0] & s[y])).count() << "\n";
    }

    return 0;
}

AC:

#include <iostream>
#include <bitset>

std::bitset<30005> s[30005];

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    int n, m, q;

    std::cin >> n >> m >> q;
    for (int i = 1; i <= n; i++)
    {
        int c;
        std::cin >> c;
        for (int j = 1; j <= c; j++)
        {
            int x;
            std::cin >> x;
            s[i].set(x - 1);
        }
    }

    for (int i = 0; i < m; i++)
        s[0].set(i);
    while (q--)
    {
        int o, x, y;
        std::cin >> o >> x >> y;
        if (o == 1)
        {
            s[x] <<= y;
            s[x] &= s[0];
        }
        else if (o == 2)
        {
            s[x] >>= y;
            s[x] &= s[0];
        }
        else if (o == 3)
            // std::cout << (s[0] & s[x] & s[y]).count() << "\n";
            std::cout << (s[x] & s[y]).count() << "\n";
        else if (o == 4)
            // std::cout << ((s[0] & s[x]) | (s[0] & s[y])).count() << "\n";
            std::cout << (s[x] | s[y]).count() << "\n";
        else
            // std::cout << ((s[0] & s[x]) ^ (s[0] & s[y])).count() << "\n";
            std::cout << (s[x] ^ s[y]).count() << "\n";
    }

    return 0;
}

2024/1/3 22:24
加载中...