QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#549432#9221. Missing BoundariesAINgrayWA 123ms18352kbC++174.9kb2024-09-06 15:29:092024-09-06 15:29:10

Judging History

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

  • [2024-09-06 15:29:10]
  • 评测
  • 测评结果:WA
  • 用时:123ms
  • 内存:18352kb
  • [2024-09-06 15:29:09]
  • 提交

answer

#include <bits/stdc++.h>

void Main(void);

int main(void) {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
    Main();
    return 0;
}

void Yes(void) {std::cout << "TAK" << '\n'; return;}
void No(void) {std::cout << "NIE" << '\n'; return;}

void Case(void) {
    int n, len; std::cin >> n >> len;
    std::vector<std::pair<int, int>> ve(n); for (auto&[l, r] : ve) std::cin >> l >> r;

    int both_miss = 0;
    std::vector<int> l_miss, r_miss;
    std::vector<std::pair<int, int>> rg;
                for (const auto[l, r] : ve) if (l == -1 and r == -1) ++both_miss; else if (l == -1) l_miss.push_back(r); else if (r == -1) r_miss.push_back(l); else rg.push_back({l, r});
    std::sort(l_miss.begin(), l_miss.end());
    std::sort(r_miss.begin(), r_miss.end());
    std::sort(rg.begin(), rg.end());

    std::set<int> set;
    for (const auto[l, r] : ve) {
        if (l != -1) {
            if (set.find(l) == set.end()) set.insert(l);
            else {No(); return;}
        }
        if (r != -1 and r != l) {
            if (set.find(r) == set.end()) set.insert(r);
            else {No(); return;}
        }
    }

    for (int i = 1; i < int(rg.size()); ++i) if (rg[i].first <= rg[i - 1].second) {No(); return;}

    for (const auto[l, r] : rg) {
        int l_miss_lh = std::lower_bound(l_miss.begin(), l_miss.end(), l) - l_miss.begin() - 1;
        int l_miss_rh = std::lower_bound(l_miss.begin(), l_miss.end(), r) - l_miss.begin();
        int r_miss_lh = std::lower_bound(r_miss.begin(), r_miss.end(), l) - r_miss.begin() - 1;
        int r_miss_rh = std::lower_bound(r_miss.begin(), r_miss.end(), r) - r_miss.begin();
        if (l_miss_lh + 1 != l_miss_rh) {No(); return;}
        if (r_miss_lh + 1 != r_miss_rh) {No(); return;}
    }

    std::vector<std::pair<int, int>> wait;
    if (rg.empty()) wait.push_back({1, len});
    else {
        if (rg.front().first > 1) wait.push_back({1, rg.front().first - 1});
        for (int i = 1; i < int(rg.size()); ++i) if (rg[i - 1].second + 1 <= rg[i].first - 1) wait.push_back({rg[i - 1].second + 1, rg[i].first - 1});
        if (rg.back().second < len) wait.push_back({rg.back().second + 1, len});
    }

    int both_chance = 0, both_need = 0, l_miss_p = 0, r_miss_p = 0;
    for (int i = 0; i < int(rg.size()); ++i) {
        auto [l, r] = rg[i];

        int last = -1;
        while ((l_miss_p < int(l_miss.size()) or r_miss_p < int(r_miss.size())) and l <= r) {
            if (l_miss_p < int(l_miss.size()) and r_miss_p < int(r_miss.size())) {
                if (l_miss[l_miss_p] < r_miss[r_miss_p]) {
                    if (l <= l_miss[l_miss_p] and l_miss[l_miss_p] <= r) {
                        both_chance += l_miss[l_miss_p] - l;
                        l = l_miss[l_miss_p] + 1;
                        ++l_miss_p;
                        last = -1;
                    } else {break;}
                } else {
                    if (l <= r_miss[r_miss_p] and r_miss[r_miss_p] <= r) {
                        if (last == -1) {
                            ++both_need;
                            both_chance += r_miss[r_miss_p] - l;
                            l = r_miss[r_miss_p] + 1;
                            ++r_miss_p;
                            last = 1;
                        } else {
                            both_chance += r_miss[r_miss_p] - l;
                            l = r_miss[r_miss_p] + 1;
                            ++r_miss_p;
                            last = 1;
                        }
                    } else {break;}
                }
            } else if (l_miss_p < int(l_miss.size())) {
                if (l <= l_miss[l_miss_p] and l_miss[l_miss_p] <= r) {
                    both_chance += l_miss[l_miss_p] - l;
                    l = l_miss[l_miss_p] + 1;
                    ++l_miss_p;
                    last = -1;
                } else {break;}
            } else if (r_miss_p < int(r_miss.size())) {
                if (l <= r_miss[r_miss_p] and r_miss[r_miss_p] <= r) {
                    if (last == -1) {
                        ++both_need;
                        both_chance += r_miss[r_miss_p] - l;
                        l = r_miss[r_miss_p] + 1;
                        ++r_miss_p;
                        last = 1;
                    } else {
                        both_chance += r_miss[r_miss_p] - l;
                        l = r_miss[r_miss_p] + 1;
                        ++r_miss_p;
                        last = 1;
                    }
                } else {break;}
            }
        }

        if (l <= r) {
            ++both_need;
            both_chance += r - l;
        }
    }

    if (0 <= (int)(both_miss) - both_need and (int)(both_miss) - both_need <= both_chance) {Yes(); return;}
    else {No(); return;}
    return;
}

void Main(void) {
    int t; std::cin >> t;
    for (int i = 1; i <= t; ++i) Case();
    return;
}

詳細信息

Test #1:

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

input:

3
4 51
1 -1
11 50
-1 -1
-1 10
3 2
-1 -1
-1 -1
-1 -1
2 3
1 2
2 3

output:

TAK
NIE
NIE

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 123ms
memory: 18352kb

input:

1
200000 1000000000
490669427 -1
224278942 224287156
821104480 -1
861696576 861702036
807438935 807440055
574078002 574083717
465630141 -1
195378188 -1
-1 13500961
-1 977536179
92893115 -1
-1 661145418
-1 215804863
-1 685338515
544348999 -1
465532902 -1
130346949 -1
-1 526666304
635604584 635605404
...

output:

NIE

result:

wrong answer 1st lines differ - expected: 'TAK', found: 'NIE'