QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#534561 | #9221. Missing Boundaries | PHarr | WA | 31ms | 9168kb | C++20 | 2.1kb | 2024-08-27 13:53:26 | 2024-08-27 13:53:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i32 = int32_t;
using i64 = long long;
using i128 = __int128;
#define int i64
using vi = vector<int>;
using pii = pair<int, int>;
const int inf = INT_MAX / 2;
void solve() {
int n, L;
cin >> n >> L;
vector<pii> seg, p;
int cnt = 0;
for (int i = 1, l, r; i <= n; i++) {
cin >> l >> r;
if (l != -1 and r != -1) seg.emplace_back(l, r);
else if (l != -1) p.emplace_back(l, 0);
else if (r != -1) p.emplace_back(r, 1);
else cnt++;
}
ranges::sort(seg), ranges::sort(p);
for (int i = 1; i < seg.size(); i++)
if (seg[i - 1].second >= seg[i].first) {
cout << "NIE\n";
return;
}
for (int i = 1; i < p.size(); i++)
if (p[i - 1].first == p[i].first) {
cout << "NIE\n";
return;
}
int i = 0, cntMax = 0, cntMin = 0;
auto work = [&](int l, int r) -> bool {
int lastI = i;
while (i < p.size() and p[i].second <= r) {
if (p[i].first < l) return false;
i++;
}
cntMax += (r - l + 1) - (i - lastI);
if (i == lastI) cntMin++;
else {
for (int j = lastI + 1; j < i; j++)
cntMin += (p[j].first != p[j - 1].first and p[j].second == 0 and p[j - 1].second == 1);
cntMin += (p[lastI].first != l and p[lastI].second == 1);
cntMin += (p[i - 1].first != r and p[i - 1].second == 0);
}
return true;
};
int lst = 1;
for (auto [l, r]: seg) {
if (l > lst and not work(lst, l - 1)) {
cout << "NIE\n";
return;
}
lst = r + 1;
}
if (lst <= L and not work(lst, L)) {
cout << "NIE\n";
return;
}
if (cntMin <= cnt and cnt <= cntMax) {
cout << "TAK\n";
return;
} else {
cout << "NIE\n";
return;
}
}
i32 main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int T;
cin >> T;
while (T--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3868kb
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: 31ms
memory: 9168kb
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'