답안 #884244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884244 2023-12-07T02:24:32 Z noiaint Paint (COI20_paint) C++17
8 / 100
906 ms 6064 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

#define file ""

#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()

#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
#define popcount __builtin_popcountll

mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
    return l + rd() % (r - l + 1);
}

const int N = 1e6 + 5;
const int mod = (int)1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int oo = 1e9;
const long long ooo = 1e18;

template<class X, class Y> bool mini(X &a, Y b) {
    return a > b ? (a = b, true) : false;
}
template<class X, class Y> bool maxi(X &a, Y b) {
    return a < b ? (a = b, true) : false;
}
void add(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
}

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int m, n, q;
vector<vector<int> > a;

namespace task1 {

bool check() {
    return m * n <= 10000 && q <= 10000;
}

bool inside(int x, int y) {
    return 1 <= x && x <= m && 1 <= y && y <= n;
}

void Paint(int Ax, int Ay, int NewColor) {
    vector<vector<int> > vis(m + 5, vector<int> (n + 5, 0));
    queue<pair<int,int> > Q;
    Q.push({Ax, Ay});
    vis[Ax][Ay] = true;

    int FirstColor = a[Ax][Ay];
    a[Ax][Ay] = NewColor;

    while (Q.size()) {
        int x, y;
        tie(x, y) = Q.front(); Q.pop();

        for (int k = 0; k < 4; ++k) {
            int nx = x + dx[k];
            int ny = y + dy[k];

            if (!vis[nx][ny] && inside(nx, ny) && a[nx][ny] == FirstColor) {
                a[nx][ny] = NewColor;
                vis[nx][ny] = true;
                Q.push({nx, ny});
            }
        }
    }
}

void solve() {
    while (q--) {
        int x, y, NewColor;
        cin >> x >> y >> NewColor;
        Paint(x, y, NewColor);
    }

    for (int i = 1; i <= m; ++i) {
        for (int j = 1; j <= n; ++j) cout << a[i][j] << ' ';
        cout << '\n';
    }
}

}

namespace task2 {

bool check() {
    return m == 1;
}

struct SegmentTree {
    vector<long long> sum, lazy;
    vector<bool> rec;
    int n;

    void init(int _n) {
        n = _n;
        sum.assign(n * 4 + 5, 0);
        lazy.assign(n * 4 + 5, 0);
        rec.assign(n * 4 + 5, 0);
    }

    void down(int i, int L, int R) {
        if (!rec[i])
            return;
        int M = (L + R) >> 1;
        sum[i << 1] = 1LL * lazy[i] * (M - L + 1);
        sum[i << 1 | 1] = 1LL * lazy[i] * (R - M);
        for (int j = i * 2; j <= i * 2 + 1; ++j) lazy[j] = lazy[i], rec[j] = rec[i];
        lazy[i] = rec[i] = 0;
    }

    void update(int i, int L, int R, int l, int r, int val) {
        if (r < L || l > R)
            return;
        if (l <= L && R <= r) {
            sum[i] = 1LL * (R - L + 1) * val;
            lazy[i] = val;
            rec[i] = true;
            return;
        }

        down(i, L, R);
        int M = (L + R) >> 1;
        update(i << 1, L, M, l, r, val);
        update(i << 1 | 1, M + 1, R, l, r, val);
        sum[i] = sum[i << 1] + sum[i << 1 | 1];
    }

    long long get(int i, int L, int R, int l, int r) {
        if (r < L || l > R)
            return 0;
        if (l <= L && R <= r)
            return sum[i];

        down(i, L, R);
        int M = (L + R) >> 1;
        return get(i << 1, L, M, l, r) + get(i << 1 | 1, M + 1, R, l, r);
    }

    void update(int l, int r, int val) {
        update(1, 1, n, l, r, val);
    }
    long long get(int l, int r) {
        return get(1, 1, n, l, r);
    }

} t;

void solve() {
    t.init(n);
    for (int i = 1; i <= n; ++i) t.update(i, i, a[1][i]);

    while (q--) {
        int x, NewColor;
        cin >> x >> x >> NewColor;

        int lpos, rpos;
        int l = 1, r = x;
        int res = x;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (t.get(mid, x) == t.get(x, x) * (x - mid + 1)) {
                res = mid;
                r = mid - 1;
            } else l = mid + 1;
        }

        lpos = res;

        l = x, r = n;
        res = x;

        while (l <= r) {
            int mid = (l + r) / 2;
            if (t.get(x, mid) == t.get(x, x) * (mid - x + 1)) {
                res = mid;
                l = mid + 1;
            } else r = mid - 1;
        }

        rpos = res;

        t.update(lpos, rpos, NewColor);
    }

    for (int i = 1; i <= n; ++i) cout << t.get(i, i) << ' ';
}

}

void process() {
    cin >> m >> n;
    a.resize(m + 5, vector<int>(n + 5, 0));
    for (int i = 1; i <= m; ++i)
        for (int j = 1; j <= n; ++j) cin >> a[i][j];
    cin >> q;

    if (task1::check()) {task1::solve(); return;}
    if (task2::check()) {task2::solve(); return;}

//    task1::solve();
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #else
    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);
    #endif

    int tc = 1;
    // cin >> tc;

    while (tc--) {
        process();
    }

    return 0;
}

/*

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 10 ms 604 KB Output is correct
4 Correct 25 ms 608 KB Output is correct
5 Correct 352 ms 620 KB Output is correct
6 Correct 502 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 906 ms 6064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1452 KB Output isn't correct
2 Halted 0 ms 0 KB -