QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#784581 | #9786. Magical Bags | ucup-team2172# | WA | 1ms | 4084kb | C++23 | 2.6kb | 2024-11-26 15:23:59 | 2024-11-26 15:24:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, ans;
int L[maxn], R[maxn], f[maxn];
vector<pair<int, int> > all;
vector<int> vec[maxn];
inline void solve_contain(){
vector<pair<int, int> > all_new;
sort(all.begin(), all.end(), [&] (const pair<int, int> &ths, const pair<int, int> &oth) { return ths.second < oth.second; });
int mxl = 0;
for (auto p: all) {
if (mxl > p.first) continue; // this interval contains others, single point never contain others
mxl = max(mxl, p.first);
if (p.first != p.second) all_new.push_back(p);
}
all = all_new;
// for (auto p: all) printf("(%d %d) ", p.first, p.second); puts("");
}
int main(){
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int cnt; scanf("%d", &cnt);
int mn = (int)(1e9) + 1, mx = 1;
for (int j = 0; j < cnt; ++j) {
int x; scanf("%d", &x);
vec[i].push_back(x);
mn = min(mn, x);
mx = max(mx, x);
}
if (cnt >= 2) ans += 2;
else ans += 1;
all.push_back(make_pair(mn, mx));
}
solve_contain();
for (int i = 0; i < all.size(); ++i) L[i] = 0, R[i] = (int)(1e9) + 1;
for (int i = 0, j = -1; i < all.size(); ++i) {
for (; j + 1 < all.size() && all[j + 1].first < all[i].second; ++j);
assert(j != -1);
if (j > i) L[i] = max(L[i], all[j].first);
else L[i] = 0;
}
for (int i = (int)all.size() - 1, j = (int)all.size(); i >= 0; --i) {
for (; j - 1 >= 0 && all[j - 1].second > all[i].first; --j);
assert(j != (int)all.size());
if (j < i) R[i] = min(R[i], all[j].second);
else R[i] = (int)(1e9) + 1;
}
vector<pair<int, int> > all_new;
int res = 0;
for (int i = 0; i < all.size(); ++i) {
bool flg = false;
for (auto x: vec[i]) if (x > L[i] && x < R[i]) flg = true;
if (flg) all_new.push_back(all[i]);
}
all = all_new;
for (int i = 0, j = -1; i < all.size(); ++i) {
for (; j + 1 < all.size() && all[j + 1].second < all[i].first; ++j);
// printf("(%d %d) L = %d R = %d\n", all[i].first, all[i].second, L[i], R[i]);
// printf("j = %d\n", j);
if (j == -1) f[i] = 1;
else f[i] = f[j] + 1;
// printf("i = %d f = %d\n", i, f[i]);
res = max(res, f[i]);
}
printf("%d\n", ans - res);
return 0;
}
/*
4
3 4 7 10
2 1 9
4 11 2 8 14
3 6 12 13
4
1 1
1 2
1 3
1 4
9
2 1 10
3 2 5 11
2 3 22
2 21 40
3 32 35 41
2 33 62
2 60 100
3 71 75 101
2 72 102
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4084kb
input:
4 3 4 7 10 2 1 9 4 11 2 8 14 3 6 12 13
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3808kb
input:
4 1 1 1 2 1 3 1 4
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
4 3 4 7 10 2 1 9 4 11 2 8 14 3 6 12 13
output:
7
result:
ok 1 number(s): "7"
Test #4:
score: 0
Accepted
time: 1ms
memory: 4064kb
input:
4 1 1 1 2 1 3 1 4
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 4004kb
input:
100 4 372861091 407948190 424244630 359746969 6 568180757 527358812 494745349 665803213 674832670 586694351 4 696340797 775899164 919971335 716827187 4 123145962 344250363 122030550 251739234 4 342654413 368648894 150539766 255189030 1 194505887 3 755984448 736803561 745474041 4 709314938 498953418 ...
output:
175
result:
wrong answer 1st numbers differ - expected: '177', found: '175'