2021牛客暑期多校训练营8 F-Robots

https://ac.nowcoder.com/acm/contest/11259/F

用bitset滚动记录每个点能到达的其他点.暴力,n4/32
每次转移的时候.

  • 如果这个点是'0',
    • 如果右边点为'0', 就|=右边点能到达的点
    • 如果右边点为'1'...
  • 如果这个点为'1' reset这个点(即没有点可以从他开始到达)
codes

const int maxn = 5e2 + 7;

int n, t, m, q;
char s[maxn][maxn];
struct query {
    int id, opt, x, y;
};
vector<query> qer[maxn][maxn];
bitset<maxn * maxn> bs[maxn];

int ans[maxn * 1000];

void solve() {
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> s[i];
    cin >> q;
    for (int i = 1, x1, y1, x2, y2, opt; i <= q; i++) {
        cin >> opt >> x1 >> y1 >> x2 >> y2;
        x1--, x2--, y1--, y2--;
        qer[x1][y1].push_back({i, opt, x2, y2});
    }
    for (int i = n - 1; i >= 0; i--) {
        for (int j = m - 1; j >= 0; j--) {
            if (s[i][j] == '1') {
                bs[j].reset();
            } else {
                if (s[i][j + 1] == '0')
                    bs[j] |= bs[j + 1];
                bs[j][i * m + j] = 1;
            }
            for (auto c:qer[i][j]) {
                int x = c.x, y = c.y;
                if (c.opt == 1) {
                    ans[c.id] = (bs[j][x * m + y] & (y == j));
                } else if (c.opt == 2) {
                    ans[c.id] = (bs[j][x * m + y] & (x == i));
                } else {
                    ans[c.id] = bs[j][x * m + y];
                }
            }
        }
    }
    for (int i = 1; i <= q; i++)
        if (ans[i]) cout << "yes" << endl;
        else cout << "no" << endl;
}

posted @ 2021-08-09 22:34  naymi  阅读(77)  评论(0)    收藏  举报