bitset TLE 求助
查看原帖
bitset TLE 求助
1013950
__youzimo2014__楼主2025/1/24 07:39
#include <iostream>
#include <bitset>
#include <stack>
using namespace std;
bitset<32768> s[30005]; // 集合
bitset<32768> uniset; // 全集
int read() {
    int res = 0;
    char ch = getchar_unlocked();
    while (ch < '0' || ch > '9') {
        ch = getchar_unlocked();
    }
    while (ch >= '0' && ch <= '9') {
        res *= 10;
        res += ch - '0';
        ch = getchar_unlocked();
    }
    return res;
}
void write(int x) {
    stack<char> s;
    while (x > 0) {
        s.push(x % 10 + '0');
        x /= 10;
    }
    while (!s.empty()) {
        putchar_unlocked(s.top());
        s.pop();
    }
    putchar_unlocked('\n');
}
int main() {
    int n = read(), m = read(), q = read();
    for (int i = 1; i <= n; i++) {
        int num = read();
        for (int j = 1; j <= num; j++) {
            int tmp = read();
            s[i].set(tmp);
        }
    }
    for (int i = 1; i <= m; i++) uniset.set(i); // 把全集预处理一下
    while (q--) {
        int op = read(), x = read(), y = read();
        if (op == 1) {
            s[x] <<= y;
            s[x] &= uniset;
        } else if (op == 2) {
            s[x] >>= y;
        } else if (op == 3) {
            bitset<32768> tgtset = s[x] & s[y];
            int ans = 0;
            for (int i = 1; i <= m; i++) {
                ans += tgtset[i];
            }
            write(ans);
        } else if (op == 4) {
            bitset<32768> tgtset = s[x] | s[y];
            int ans = 0;
            for (int i = 1; i <= m; i++) {
                ans += tgtset[i];
            }
            write(ans);
        } else if (op == 5) {
            bitset<32768> tgtset = s[x] ^ s[y];
            int ans = 0;
            for (int i = 1; i <= m; i++) {
                ans += tgtset[i];
            }
            write(ans);
        }
    }
    return 0;
}

TLE on #1

2025/1/24 07:39
加载中...