QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#424329#8106. Mosaic_LiMLE_RE 0ms0kbC++143.2kb2024-05-29 07:12:132024-05-29 07:12:13

Judging History

你现在查看的是最新测评结果

  • [2024-05-29 07:12:13]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-05-29 07:12:13]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define db double
#define FOR(i, s, t) for(int i = (s); i <= (t); ++i)
#define ROF(i, s, t) for(int i = (s); i >= (t); --i)
#define IL inline
#define pii pair<int, int>
#define mkp make_pair
#define fi first
#define se second
#define pb push_back
#define ls (x << 1)
#define rs ((x << 1) | 1)
#define mid ((l + r) >> 1)

using namespace std;

const int N = 1e6 + 5;
const int M = 1e9 + 7;
const int inf = 1e16;

struct seg {
    int l, r;
    int h;

    bool operator <(const seg &s)const {
        if(l != s.l) return l < s.l;
        else if(r != s.r) return r < s.r;
        else return h < s.h;
    }
};

struct node {
    int x, y, id;
};

int n, len[N];
node a[N];
set<seg> S;
set<seg>::iterator i1, i2, i3;

IL bool chk(int R) {
    // cout << R << '\n';
    S.clear(); S.insert((seg){0, R, 0});
    FOR(i, 1, n) {
        int x = a[i].x, y = a[i].y, id = a[i].id;
        // cout << i << '\n';
        // cout << x << ' ' << y << '\n';
        // for(seg s : S) {
        //     cout << s.l << ' ' << s.r << ' ' << s.h << '\n';
        // }
        i1 = i2 = S.upper_bound((seg){x, R + 1, 0}); i1--;
        if((*i1).h != y) return 0;
        len[id] = (*i1).r - x + 1;
        if(len[id] <= 0) return 0;
        if(i1 == S.begin() || (*i1).l < x) { //不会和左侧合并
            seg tmp = (*i1); S.erase(i1);
            if(tmp.l < x) S.insert((seg){tmp.l, x - 1, tmp.h});
            tmp.l = x, tmp.h += len[id];
            if(i2 != S.end() && (*i2).h == tmp.h) tmp.r = (*i2).r, S.erase(i2);
            S.insert(tmp);
        }
        else {
            seg tmp = (*i1); i3 = i1; i3--; S.erase(i1);
            tmp.l = x, tmp.h += len[id];
            if(i2 != S.end() && (*i2).h == tmp.h) tmp.r = (*i2).r, S.erase(i2);
            if((*i3).h == tmp.h) tmp.l = (*i3).l, S.erase(i3);
            S.insert(tmp);
        }
    }
    if(S.size() == 1 && (*S.begin()).r == R) {
        cout << "YES ";
        FOR(i, 1, n) cout << len[i] << ' ';
        cout << '\n';
        return 1;
    }
    return 0;
}

IL bool pd() {
    sort(a + 1, a + n + 1, [&](node A, node B){return (A.y != B.y ? A.y < B.y : A.x > B.x);});
    int l = 0, r = 0;
    FOR(i, 1, n) if(a[i].y == 0) l = max(l, a[i].x);
    FOR(i, 1, n) r = max(r, a[i].x);
    FOR(i, 1, n) if(a[i].y != 0 && l + a[i].y >= r + 1 && chk(l + a[i].y - 1)) return 1;
    return 0;
}

IL void solve() {
    cin >> n; int mx = inf, my = inf;
    FOR(i, 1, n) cin >> a[i].x >> a[i].y, a[i].id = i, mx = min(a[i].x, mx), my = min(a[i].y, my); 
    bool ff = 0;
    FOR(i, 1, n) {
        a[i].x -= mx, a[i].y -= my;
        if(a[i].x == 0 && a[i].y == 0) ff = 1;
    }
    if(n == 1) {
        cout << "YES 1\n";
        return;
    }
    if(pd()) return;
    FOR(i, 1, n) swap(a[i].x, a[i].y);
    if(pd()) return;
    cout << "NO\n";
    return;
}

signed main() {
    freopen("puzzle.in", "r", stdin);
    freopen("puzzle.out", "w", stdout);
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int TT; cin >> TT;
    while(TT--) solve();
    return 0;
}

/*
    Author: _LiMLE_
    start codint at: 21:09
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

3
2
0 0
0 1
2
3 2
2 3
4
1 1
2 1
3 1
1 2

output:


result: