QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#775713 | #9786. Magical Bags | ucup-team3584# | WA | 0ms | 3832kb | C++23 | 3.9kb | 2024-11-23 16:32:23 | 2024-11-23 16:32:24 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }
inline double time() {
return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
int n;
vector<S> tree;
segtree() : segtree(0) {}
segtree(int n) : n(n), tree(vector<S>(n << 1, e())) {}
segtree(const vector<S> &v) : n((int)v.size()) {
tree.resize(n * 2);
for (int i = 0; i < n; ++i) {
tree[n + i] = v[i];
}
for (int i = n - 1; i >= 1; --i) {
update(i);
}
}
void update(int k) { tree[k] = op(tree[k << 1 | 0], tree[k << 1 | 1]); }
S operator[](int i) { return tree[i + n]; }
void set(int i, S x) {
i += n;
tree[i] = x;
while (i >>= 1) {
update(i);
}
}
// [l,r)
S query(int l, int r) {
S sml = e(), smr = e();
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) sml = op(sml, tree[l++]);
if (r & 1) smr = op(tree[--r], smr);
}
return op(sml, smr);
}
};
using S = int;
S op(S a, S b) { return min(a, b); }
S e() { return 2e9; }
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<vector<int>> v(n);
vector<pair<int, int>> in(n), out(n);
for (int i = 0; i < n; ++i) {
int m;
cin >> m;
v[i].resize(m);
for (int j = 0; j < m; ++j) {
cin >> v[i][j];
}
sort(v[i].begin(), v[i].end());
in[i] = {v[i][0], i};
out[i] = {v[i].back(), i};
}
sort(in.begin(), in.end());
sort(out.begin(), out.end());
in.emplace_back(2e9, -1);
out.emplace_back(2e9, -1);
vector<pair<int, int>> pos(n);
for (int i = 0; i < n; ++i) {
pos[in[i].second].first = i;
pos[out[i].second].second = i;
}
segtree<S, op, e> seg(n);
int res = 0;
set<int> st;
for (int i = 0, j = 0; i < n or j < n;) {
if (in[i].first <= out[j].first) {
int idx = in[i].second;
st.insert(idx);
i += 1;
} else {
if (i != n) {
cout << n << endl;
return 0;
}
int idx = out[j].second;
if (in[pos[idx].first].first == out[j].first) {
// 元々1個しか入ってない
res += 1;
st.clear();
} else {
// 2個以上入ってる
if (st.find(idx) == st.end()) {
res += 2;
} else {
// 自分以降にinにあって、自分より早くoutにあるもの
// in_max <= k < out_min
int l = pos[idx].first;
int r = i;
int in_max = in[r - 1].first;
int out_min = seg.query(l, r);
bool one = false;
for (int k : v[idx]) {
if (in_max <= k and k < out_min) {
one = true;
break;
}
}
if (one) {
res += 1;
st.clear();
} else {
res += 2;
st.erase(idx);
}
}
}
seg.set(pos[idx].first, out[j].first);
j += 1;
}
}
cout << res << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 0ms
memory: 3584kb
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: 3832kb
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: 0ms
memory: 3752kb
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: 3624kb
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:
100
result:
wrong answer 1st numbers differ - expected: '177', found: '100'