Submission #1260632

#TimeUsernameProblemLanguageResultExecution timeMemory
1260632tvgkFurniture (JOI20_furniture)C++20
0 / 100
2 ms580 KiB
#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 1e3 + 7;

int nRow, nCol, ctr[mxN][2];
set<int> s[mxN][2];

bool Upd(int i, bool tt)
{
    bool res = 0;

    if (!tt)
    {
        while (s[i][0].size() && *s[i][0].rbegin() >= min(ctr[i - 1][0], ctr[i][0]) - 1)
        {
            res = 1;
            ctr[i][0] = *s[i][0].rbegin();
            s[i][0].erase(ctr[i][0]);
        }
    }
    else
    {
        while (s[i][1].size() && *s[i][1].begin() <= max(ctr[i + 1][1], ctr[i][1]) + 1)
        {
            res = 1;
            ctr[i][1] = *s[i][1].begin();
            s[i][1].erase(ctr[i][1]);
        }
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(task".INP", "r", stdin);
    //freopen(task".OUT", "w", stdout);

    cin >> nRow >> nCol;
    for (int i = 1; i <= nRow; i++)
    {
        ctr[i][0] = nCol;
        for (int j = 1; j <= nCol; j++)
        {
            bool tt;
            cin >> tt;
            if (tt)
            {
                s[i][0].insert(j);
                s[i][1].insert(j);
            }
        }
    }
    ctr[nRow + 1][1] = nCol;

    for (int i = 1; i <= nRow; i++)
        Upd(i, 0);
    for (int i = nRow; i >= 1; i--)
        Upd(i, 1);

    int q;
    cin >> q;
    for (int i = 1; i <= q; i++)
    {
        int u, v;
        cin >> u >> v;

        if (min(ctr[u][0], ctr[u - 1][0]) - 1 <= v && v <= max(ctr[u][1], ctr[u + 1][1]) + 1)
        {
            cout << 0 << '\n';
            continue;
        }

        cout << 1 << '\n';

        s[u][0].insert(v);
        s[u][1].insert(v);

        for (int i = u; i <= nRow; i++)
        {
            if (!Upd(i, 0))
                break;
        }
        for (int i = u; i >= 1; i--)
        {
            if (!Upd(i, 1))
                break;
        }
    }
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...