QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#754949 | #9557. Temperance | ucup-team133# | TL | 1106ms | 44716kb | C++23 | 3.1kb | 2024-11-16 16:07:32 | 2024-11-16 16:07:33 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (auto& e : v) {
is >> e;
}
return is;
}
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
for (std::string_view sep = ""; const auto& e : v) {
os << std::exchange(sep, " ") << e;
}
return os;
}
template <class T, class U = T> bool chmin(T& x, U&& y) {
return y < x and (x = std::forward<U>(y), true);
}
template <class T, class U = T> bool chmax(T& x, U&& y) {
return x < y and (x = std::forward<U>(y), true);
}
template <class T> void mkuni(std::vector<T>& v) {
std::ranges::sort(v);
auto result = std::ranges::unique(v);
v.erase(result.begin(), result.end());
}
template <class T> int lwb(const std::vector<T>& v, const T& x) {
return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}
using namespace std;
using ll = long long;
const int MAX = 1e5 + 10;
void solve() {
int n;
cin >> n;
vector v(n, vector<int>(3));
cin >> v;
vector G(MAX, vector<vector<int>>(3));
vector deg(MAX, vector<int>(3));
vector<int> DEG(n, 3);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
G[v[i][j]][j].emplace_back(i);
}
}
vector alive(MAX, vector<bool>(3, true));
vector<bool> ALIVE(n, true);
set<tuple<int, int, int>> s;
queue<int> que;
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < 3; j++) {
deg[i][j] = G[i][j].size();
s.emplace(deg[i][j], i, j);
}
}
for (int k = 0, cur = 0; k < n; k++) {
while (not que.empty() or (not s.empty() and get<0>(*s.begin()) <= k)) {
if (not que.empty()) {
int i = que.front();
que.pop();
cur++;
for (int j = 0; j < 3; j++) {
if (not alive[v[i][j]][j]) continue;
s.erase({deg[v[i][j]][j], v[i][j], j});
deg[v[i][j]][j]--;
s.emplace(deg[v[i][j]][j], v[i][j], j);
}
} else {
auto [_, x, y] = *s.begin();
s.erase(s.begin());
assert(alive[x][y]);
alive[x][y] = false;
for (int i : G[x][y]) {
if (not ALIVE[i]) continue;
bool safe = false;
for (int j = 0; j < 3; j++) {
if (alive[v[i][j]][j]) {
safe = true;
}
}
if (not safe) {
ALIVE[i] = false;
que.emplace(i);
}
}
}
}
cout << cur << (k + 1 == n ? "\n" : " ");
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int T;
cin >> T;
for (; T--;) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 139ms
memory: 44580kb
input:
2 5 1 1 1 1 1 2 1 1 3 2 3 5 2 2 4 3 1 1 1 2 2 2 3 3 3
output:
0 0 2 5 5 0 3 3
result:
ok 8 numbers
Test #2:
score: 0
Accepted
time: 1106ms
memory: 44716kb
input:
16 1 1 1 1 2 1 1 1 1 1 100000 3 1 1 1 1 1 100000 1 100000 1 4 1 1 1 1 1 100000 1 100000 1 1 100000 100000 5 1 1 1 1 1 100000 1 100000 1 1 100000 100000 100000 1 1 6 1 1 1 1 1 100000 1 100000 1 1 100000 100000 100000 1 1 100000 1 100000 7 1 1 1 1 1 100000 1 100000 1 1 100000 100000 100000 1 1 100000 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 1 5 0 0 0 0 6 6 0 0 0 0 7 7 7 0 0 0 0 8 8 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 1 5 0 0 0 0 6 6 0 0 0 0 7 7 7 0 0 0 0 8 8 8 8
result:
ok 72 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
10000 22 1 4 4 7 2 6 6 5 4 4 4 1 1 7 1 7 6 6 5 8 6 4 4 8 6 7 6 1 7 3 5 7 8 5 1 3 2 1 7 1 2 5 6 1 2 3 1 1 7 3 8 1 4 6 6 5 7 4 4 7 7 7 5 3 4 6 13 2 7 3 2 7 5 5 1 5 8 7 1 6 6 7 3 5 8 8 1 6 4 8 4 1 4 3 6 2 5 6 8 4 1 5 5 5 3 4 28 4 7 2 3 8 5 1 1 6 1 7 4 5 5 6 6 1 5 4 5 2 1 1 5 2 6 3 4 3 6 4 5 7 3 3 6 6 8...