QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#635946#7752. The Only Way to the Destinationjacob02RE 1ms6872kbC++204.5kb2024-10-12 21:33:112024-10-12 21:33:13

Judging History

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

  • [2024-10-12 21:33:13]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:6872kb
  • [2024-10-12 21:33:11]
  • 提交

answer

#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
typedef long long ll;
using namespace std;
struct Node
{
    ll l, r, c;
}node[100005];
Node e[200005];
int fa[300050];
int emptycnt = 2e5 + 5;
int cnt = 0;
int find(int x) {
    if (fa[x] != x)
        return fa[x] = find(fa[x]);
    return fa[x];
}
void merge(int x, int y) {
    int xx = find(x);
    int yy = find(y);
    if (xx != yy)
        fa[xx] = yy;
}
void init() {
    for (int i = 0; i <= 3e5+20; i++)
        fa[i] = i;
}
bool cmp(Node x, Node y) {
    if (x.c == y.c)
        return x.l < y.l;
    return x.c < y.c;
}
void No() {
    cout << "NO\n";
    exit(0);
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, m;
    int k;
    cin >> n >> m >> k;
    unordered_map<ll, bool>mp;
    int tcnt = 0;
    for (int i = 1; i <= k; i++) {
        cin >> node[i].l >> node[i].r >> node[i].c;
        if (!mp[node[i].c]) {
            tcnt++;
            node[k + tcnt].l = n + 1;
            node[k + tcnt].r = n + 1;
            node[k + tcnt].c = node[i].c;
            mp[node[i].c] = 1;
        }
    }
    sort(node + 1, node + k + tcnt + 1, cmp);
    ll pre = 0;
    for (int i = 1; i <= k + tcnt; i++) {
        if (node[i].c != pre) {
            if (node[i].l > 1) {
                cnt++;
                e[cnt].l = 1;
                e[cnt].r = node[i].l - 1;
                e[cnt].c = node[i].c;
            }
            pre = node[i].c;
        }
        else {
            if (node[i].l > node[i - 1].r + 1) {
                cnt++;
                e[cnt].l = node[i - 1].r + 1;
                e[cnt].r = node[i].l - 1;
                e[cnt].c = node[i].c;
            }
        }
    }
    init();
    pre = 0;
    int p = 1, pe = 0;
    int lp = 1, op = 1;
    int len = 0;
    bool ok = 0;
    for (int i = 1; i <= cnt; i++) {
        if (e[i].c != pre) {
            p = lp;
            op = lp;
            lp = i;
            pe = i - 1;
            ok = 0;
            emptycnt++;
            if (e[i].c - pre > 2)
                No();
            else if (e[i].c - pre == 2) {
                ok = 1;
                if (e[i].r - e[i].l > 0)
                    No();
                if (find(i) == find(emptycnt))
                    No();
                merge(i, emptycnt);
            }
            else {
                while (p <= pe) {
                    if (e[p].r < e[i].l) {
                        p++;
                        continue;
                    }
                    else if (e[p].l > e[i].r)
                        break;
                    else {
                        ll temp = min(e[p].r, e[i].r) - max(e[p].l, e[i].l) + 1;
                        if (temp > 1)
                            No();
                        else {
                            if (find(p) == find(i))
                                No();
                            merge(p, i);
                        }
                    }
                    p++;
                }
            }
            pre = e[i].c;
        }
        else {
            if (ok) {
                if (e[i].r - e[i].l > 1)
                    No();
                if (find(i) == find(emptycnt))
                    No();
                merge(i, emptycnt);
            }
            else {
                p = max(op, p - 1);
                while (p <= pe) {
                    if (e[p].r < e[i].l) {
                        p++;
                        continue;
                    }
                    else if (e[p].l > e[i].r)
                        break;
                    else {
                        ll temp = min(e[p].r, e[i].r) - max(e[p].l, e[i].l) + 1;
                        if (temp > 1)
                            No();
                        else {
                            if (find(p) == find(i))
                                No();
                            merge(p, i);
                        }
                    }
                    p++;
                }
            }
        }
    }
    if (m - e[lp].c > 1)
        No();
    else if (m - e[lp].c == 1) {
        emptycnt++;
        for (int i = lp; i <= cnt; i++) {
            if (e[i].r - e[i].l > 0)
                No();
            if (find(i) == find(emptycnt))
                No();
            merge(i, emptycnt);
        }
    }
    cout << "YES\n";
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 6840kb

input:

5 3 2
2 5 1
1 4 3

output:

YES

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 0ms
memory: 6836kb

input:

5 3 1
2 4 2

output:

NO

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 1ms
memory: 6872kb

input:

2 4 2
2 2 1
1 1 4

output:

NO

result:

ok answer is NO

Test #4:

score: -100
Runtime Error

input:

409455775 596220461 69036
72554058 85866426 497212608
54242898 110165840 236869995
68671059 127632371 324336242
39386477 208393446 248270338
151972182 327931056 231832
36658944 75335495 293646122
29512382 138875677 205628469
149151850 327396301 590717922
114980184 165064700 323939243
1771834 7016377...

output:


result: