QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#466860 | #1878. No Rest for the Wicked | GenshinImpactsFault | WA | 11ms | 91744kb | C++14 | 2.7kb | 2024-07-08 11:13:02 | 2024-07-08 11:13:02 |
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 p[N], lp;
struct Edge {
int x, y;
}; Edge edge[N];
int ans[N];
vector<int> q[N];
vector<pair<int, int> > bicon[N * 4], oneway[N * 4];
struct Sta {
int u, fa, w, sz;
}; Sta sta[N * 2]; int top = 0;
int fa[N], w[N], sz[N];
int find(int x) {
return x == fa[x] ? x : find(fa[x]);
}
void insert_bi(int u, int l, int r, int L, int R, pair<int, int > w) {
if(L <= l && r <= R) {
bicon[u].push_back(w); return ;
}
int mid = (l + r) >> 1;
if(L <= mid) insert_bi(u * 2, l, mid, L, R, w);
if(R > mid) insert_bi(u * 2 + 1, mid + 1, r, L, R, w);
}
void insert_one(int u, int l, int r, int L, int R, pair<int, int > w) {
if(L <= l && r <= R) {
oneway[u].push_back(w); return ;
}
int mid = (l + r) >> 1;
if(L <= mid) insert_one(u * 2, l, mid, L, R, w);
if(R > mid) insert_one(u * 2 + 1, mid + 1, r, L, R, w);
}
void merge(int x, int y) {
x = find(x), y = find(y); if(x == y) return ;
if(sz[x] > sz[y]) swap(x, y);
++top;
sta[top].fa = x, sta[top].u = x;
sta[top].sz = sz[x], sta[top].w = w[x];
++top;
sta[top].fa = y, sta[top].u = y;
sta[top].sz = sz[y], sta[top].w = w[y];
fa[x] = y, sz[y] += sz[x], w[y] = max(w[y], w[x]);
}
void dfs(int u, int l, int r) {
int cur = top;
for(auto v : bicon[u]) merge(v.first, v.second);
for(auto v : oneway[u]) {
int x = v.first, y = v.second;
x = find(x), y = find(y);
if(x == y) continue;
++top;
sta[top].u = x, sta[top].fa = x;
sta[top].sz = sz[x], sta[top].w = w[x];
w[x] = max(w[x], w[y]);
}
if(l >= r) {
for(auto v : q[l]) ans[v] = w[find(v)];
return ;
}
else {
int mid = (l + r) >> 1;
dfs(u * 2 + 1, mid + 1, r), dfs(u * 2, l, mid);
}
for(; top > cur; --top) {
fa[sta[top].u] = sta[top].fa;
sz[sta[top].u] = sta[top].sz;
w[sta[top].u] = sta[top].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];
p[++lp] = c[i], p[++lp] = t[i];
}
sort(p + 1, p + lp + 1), lp = unique(p + 1, p + lp + 1) - p - 1;
for(int i = 1; i <= n; i++) {
c[i] = lower_bound(p + 1, p + lp + 1, c[i]) - p;
t[i] = lower_bound(p + 1, p + lp + 1, t[i]) - p;
q[c[i]].push_back(i);
}
for(int i = 1; i <= m; i++) {
int x, y; cin >> x >> y;
if(max(c[x], c[y]) <= min(t[x], t[y])) {
insert_bi(1, 1, lp, max(c[x], c[y]), min(t[x], t[y]), {x, y});
}
if(c[x] > c[y]) swap(x, y);
if(c[x] <= min(t[x], c[y] - 1)) {
insert_one(1, 1, lp, c[x], min(t[x], c[y] - 1), {x, y});
}
}
for(int i = 1; i <= n; i++) fa[i] = i, w[i] = s[i], sz[i] = 1;
dfs(1, 1, lp);
for(int i = 1; i <= n; i++) cout << ans[i] << " \n"[i == n];
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 7ms
memory: 89680kb
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: 11ms
memory: 91608kb
input:
1 0 138088047 507565360 682493255
output:
682493255
result:
ok 1 number(s): "682493255"
Test #3:
score: 0
Accepted
time: 7ms
memory: 89672kb
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: 4ms
memory: 89756kb
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: 7ms
memory: 91744kb
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: 0
Accepted
time: 8ms
memory: 89616kb
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
output:
831047661 831047661 831047661 831047661 757517237 831047661 831047661 831047661
result:
ok 8 numbers
Test #7:
score: -100
Wrong Answer
time: 11ms
memory: 89676kb
input:
10 15 655656582 957993326 217780522 363058173 566585702 743894263 647838538 859340013 196392035 640149142 953472346 198526606 702268047 718140369 962437830 124896500 917182037 295362562 192263727 942734873 850558512 772259555 981713859 93132130 238923474 989797499 19116545 409753844 743389814 382909...
output:
962437830 962437830 962437830 962437830 962437830 295362562 962437830 93132130 743894263 962437830
result:
wrong answer 9th numbers differ - expected: '962437830', found: '743894263'