QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#466206 | #1878. No Rest for the Wicked | GenshinImpactsFault | ML | 11ms | 67632kb | C++14 | 2.1kb | 2024-07-07 16:56:36 | 2024-07-07 16:56:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 400010;
int n, m;
int c[N], t[N], s[N];
int id[N];
struct Edge {
int x, y, w;
}; Edge edge[N];
int tot, fa[N];
vector<int> e[N];
int dfn[N], low[N], rev[N], idx = 0, f[N][21], dep[N];
int ans[N];
vector<int> vec[N * 4];
int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
void dfs(int u, int ff) {
dep[u] = dep[ff] + 1, f[u][0] = ff;
for(int i = 1; i <= 20; i++) f[u][i] = f[f[u][i - 1]][i - 1];
dfn[u] = ++idx, rev[idx] = u;
for(auto v : e[u]) dfs(v, u);
low[u] = idx;
}
void build(int u, int l, int r) {
for(int i = l; i <= r; i++) {
if(rev[i] <= n) vec[u].push_back(rev[i]);
}
if(l >= r) return ;
int mid = (l + r) >> 1;
build(u * 2, l, mid), build(u * 2 + 1, mid + 1, r);
}
void mdy(int u, int l, int r, int L, int R, int w) {
if(L <= l && r <= R) {
for(auto v : vec[u]) {
if(!ans[v]) ans[v] = w;
}
vec[u].clear(); return ;
}
int mid = (l + r) >> 1;
if(L <= mid) mdy(u * 2, l, mid, L, R, w);
if(R > mid) mdy(u * 2 + 1, mid + 1, r, L, R, w);
}
int main() {
ios::sync_with_stdio(0); cin.tie(nullptr);
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> c[i] >> t[i] >> s[i];
id[i] = i;
}
sort(id + 1, id + n + 1, [](int x, int y) { return s[x] > s[y]; });
for(int i = 1; i <= m; i++) {
cin >> edge[i].x >> edge[i].y;
edge[i].w = max(c[edge[i].x], c[edge[i].y]);
}
sort(edge + 1, edge + m + 1, [](Edge x, Edge y) { return x.w < y.w; });
tot = n;
for(int i = 1; i <= n; i++) fa[i] = i;
for(int i = 1; i <= m; i++) {
int x = edge[i].x, y = edge[i].y, w = edge[i].w;
x = find(x), y = find(y); if(x == y) continue;
++tot, fa[x] = fa[y] = fa[tot] = tot, c[tot] = w;
e[tot].push_back(x), e[tot].push_back(y);
}
dfs(tot, 0);
build(1, 1, tot);
for(int i = 1; i <= n; i++) {
int u = id[i], x = u;
for(int j = 20; ~j; j--) {
if(!f[x][j]) continue;
if(c[f[x][j]] <= t[u]) x = f[x][j];
}
mdy(1, 1, tot, dfn[x], low[x], s[u]);
}
for(int i = 1; i <= n; i++) cout << ans[i] << " \n"[i == n];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 65188kb
input:
4 3 2 3 1 1 1 4 1 2 2 1 1 3 1 2 1 3 1 4
output:
2 4 2 3
result:
ok 4 number(s): "2 4 2 3"
Test #2:
score: 0
Accepted
time: 5ms
memory: 67332kb
input:
1 0 138088047 507565360 682493255
output:
682493255
result:
ok 1 number(s): "682493255"
Test #3:
score: 0
Accepted
time: 0ms
memory: 65052kb
input:
4 4 1 4 3 2 4 2 2 4 3 3 4 4 1 2 1 3 2 3 3 4
output:
4 4 4 4
result:
ok 4 number(s): "4 4 4 4"
Test #4:
score: 0
Accepted
time: 11ms
memory: 67304kb
input:
4 6 178072496 839649317 45448733 194708659 935253395 946862151 18249835 428083054 205076387 264987407 972905801 813257839 1 2 1 3 1 4 2 3 2 4 3 4
output:
946862151 946862151 946862151 946862151
result:
ok 4 number(s): "946862151 946862151 946862151 946862151"
Test #5:
score: 0
Accepted
time: 3ms
memory: 67632kb
input:
6 9 28300078 870529222 753188708 536298772 594473950 960983978 529901549 892644015 629235196 243957096 964819865 557992404 816732311 926011948 125114736 542880646 854233712 893836623 1 4 1 6 2 3 2 5 2 6 3 4 3 5 4 5 5 6
output:
960983978 960983978 960983978 960983978 893836623 960983978
result:
ok 6 numbers
Test #6:
score: -100
Memory Limit Exceeded
input:
8 12 145668143 803690704 831047661 521729328 779388601 536431978 431184019 964406648 502003747 576412706 849278976 294536686 192427822 686389291 757517237 233074855 931142020 210401181 471103022 766254684 616437478 428586523 540241082 342381939 1 2 1 3 1 4 1 6 1 7 1 8 2 4 2 6 2 8 3 4 4 6 4 7