QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#376232 | #4209. Stranded Far From Home | Cyanmond | 0 | 96ms | 34480kb | C++20 | 5.2kb | 2024-04-04 00:11:52 | 2024-04-04 00:11:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll inf = 1ll << 50;
#define L(i, l, r) for (int i = (l); i < (r); ++i)
#define R(i, l, r) for (int i = (r - 1); i >= (l); --i)
#define ALL(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
int n, m;
vector<ll> s;
vector<int> a, b;
vector<ll> val_s;
int p;
vector<vector<int>> edge_map, ver_map;
vector<vector<int>> g;
vector<vector<int>> origin;
vector<vector<ll>> nxt_weight, all_sum;
struct UnionFind {
int n;
vector<int> data;
vector<set<pair<ll, int>>> rs;
vector<ll> sum;
UnionFind(int n_) : n(n_) {
data.assign(n, -1);
rs.resize(n);
L(i, 0, m) {
rs[a[i]].insert({s[b[i]], b[i]});
rs[b[i]].insert({s[a[i]], a[i]});
}
sum = s;
}
int leader(int v) {
if (data[v] < 0) {
return v;
} else {
return data[v] = leader(data[v]);
}
}
void merge(int a, int b) {
a = leader(a);
b = leader(b);
if (a == b) {
return;
}
if (data[a] > data[b]) {
swap(a, b);
}
data[a] += data[b];
data[b] = a;
for (const auto &e : rs[b]) {
rs[a].insert(e);
}
sum[a] += sum[b];
}
};
constexpr int D = 30;
void chmin(ll &a, const ll b) {
a = min(a, b);
}
void read() {
cin >> n >> m;
s.resize(n);
for (auto &e : s) {
cin >> e;
}
a.resize(m);
b.resize(m);
g.resize(n);
L(i, 0, m) {
cin >> a[i] >> b[i];
--a[i], --b[i];
}
val_s = s;
sort(ALL(val_s));
val_s.erase(unique(ALL(val_s)), val_s.end());
p = sz(val_s);
edge_map.resize(p);
L(i, 0, m) {
const int pos = lower_bound(ALL(val_s), max(s[a[i]], s[b[i]])) - val_s.begin();
edge_map[pos].push_back(i);
}
ver_map.resize(p);
L(i, 0, n) {
const int pos = lower_bound(ALL(val_s), s[i]) - val_s.begin();
ver_map[pos].push_back(i);
}
}
void process() {
vector<bool> ans(n);
int v_id = 0;
nxt_weight.assign(D, vector<ll>(n, inf));
all_sum.assign(D, vector<ll>(n, inf));
origin.assign(D, vector<int>(n, -1));
L(d, 0, D) {
while (v_id != p and val_s[v_id] <= (1 << d)) {
for (const int i : edge_map[v_id]) {
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
++v_id;
}
auto &ori = origin[d];
L(i, 0, n) {
if (ori[i] != -1) {
continue;
}
queue<int> que;
que.push(i);
ori[i] = i;
while (not que.empty()) {
const int f = que.front();
que.pop();
for (const int t : g[f]) {
if (ori[t] == -1) {
ori[t] = i;
que.push(t);
}
}
}
}
vector<vector<int>> vs(n);
L(i, 0, n) {
vs[ori[i]].push_back(i);
}
L(i, 0, n) {
sort(ALL(vs[i]));
for (const int f : vs[i]) {
all_sum[d][i] += s[f];
for (const int t : g[f]) {
if (binary_search(ALL(vs[i]), t)) {
continue;
}
chmin(nxt_weight[d][i], s[t]);
}
}
}
}
UnionFind uft(n);
L(now_val, 0, p) {
for (const int i : edge_map[now_val]) {
uft.merge(a[i], b[i]);
}
for (const int i : ver_map[now_val]) {
// answer query
int leader = uft.leader(i);
auto &adj_set = uft.rs[leader];
while ((not adj_set.empty()) and adj_set.begin()->first <= val_s[now_val]) {
adj_set.erase(adj_set.begin());
}
ll now_sum = uft.sum[leader];
if (adj_set.empty()) {
ans[i] = true;
continue;
}
if (adj_set.begin()->first > now_sum) {
ans[i] = false;
continue;
}
int d = 0;
while ((1 << d) <= now_sum) {
++d;
}
if (d >= D) {
ans[i] = true;
continue;
}
while (d < D) {
now_sum = all_sum[d][origin[d][i]];
ll nxt_g = nxt_weight[d][origin[d][i]];
if (nxt_g == inf) {
ans[i] = true;
break;
}
if (nxt_g > now_sum) {
ans[i] = false;
break;
}
++d;
}
if (d == D) {
ans[i] = true;
}
}
}
for (const auto e : ans) {
cout << (e ? 1 : 0);
}
cout << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
read();
// process();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 4068kb
input:
1622 1998 29021716 740464354 721037601 759718475 973636178 59068917 294028640 285332651 203821680 397646208 488684783 448548424 565347277 112938323 832704692 837437153 508335516 167646888 798998153 86605661 820823253 705498382 116513873 672806499 522392461 568294614 457655230 647498964 577669416 506...
output:
result:
wrong answer 1st lines differ - expected: '011110101110001100101101111110...1000100110101000000111111011011', found: ''
Subtask #2:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 28ms
memory: 14848kb
input:
200000 199999 100000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
result:
wrong answer 1st lines differ - expected: '100000000000000000000000000000...0000000000000000000000000000000', found: ''
Subtask #3:
score: 0
Wrong Answer
Test #30:
score: 0
Wrong Answer
time: 96ms
memory: 34480kb
input:
199999 199998 758475118 758475116 758475114 758475112 758475110 758475108 758475106 758475104 758475102 758475100 758475098 758475096 758475094 758475092 758475090 758475088 758475086 758475084 758475082 758475080 758475078 758475076 758475074 758475072 758475070 758475068 758475066 758475064 758475...
output:
result:
wrong answer 1st lines differ - expected: '111111111111111111111111111111...1111111111111111111111111111111', found: ''
Subtask #4:
score: 0
Wrong Answer
Test #39:
score: 0
Wrong Answer
time: 31ms
memory: 13148kb
input:
155555 200000 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735...
output:
result:
wrong answer 1st lines differ - expected: '111111111111111111111111111111...1111111111111111111111111111100', found: ''
Subtask #5:
score: 0
Skipped
Dependency #1:
0%