QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784816 | #9786. Magical Bags | ucup-team2172# | WA | 1ms | 3804kb | C++23 | 2.3kb | 2024-11-26 16:01:50 | 2024-11-26 16:01:50 |
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("");
}
set<int> sl, sr;
#define IT set<int>::iterator
int main(){
scanf("%d", &n);
int ans = 2 * 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);
}
all.push_back(make_pair(mn, mx));
sl.insert(mn);
sr.insert(mx);
}
int i = 0;
for(auto [x , y] : all){
auto it = sl.lower_bound(y);
--it;
if(*it <= x) L[i] = 0;
else L[i] = *it;
it = sr.lower_bound(x);
if(*it >= y) R[i] = 1e9 + 1;
else R[i] = * it;
i += 1;
}
// solve_contain();
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;
sort(all.begin(), all.end(), [&] (const pair<int, int> &ths, const pair<int, int> &oth) { return ths.second < oth.second; });
int cur = 0;
for (int i = 0; i < all.size(); ++i) {
if(all[i].first > cur){
ans--;
cur = all[i].second;
}
}
printf("%d\n", ans);
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3804kb
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: -100
Wrong Answer
time: 1ms
memory: 3800kb
input:
4 1 1 1 2 1 3 1 4
output:
5
result:
wrong answer 1st numbers differ - expected: '4', found: '5'