QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#32056#1878. No Rest for the WickedcdwWA 1ms14980kbC++201.7kb2022-05-16 20:55:282022-05-16 20:55:30

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-16 20:55:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:14980kb
  • [2022-05-16 20:55:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> ti3;
const int N = 200003;
int n, m, c[N], t[N], s[N], u[N], v[N], fa[N], siz[N], ans[N], mx[N], tp;
int getf(int x){while(x != fa[x]) x = fa[x]; return x;}
struct Node {
	int x, y, val;
	Node(int _1 = 0, int _2 = 0, int _3 = 0): x(_1), y(_2), val(_3){}
} stk[N<<1];
void merg(int x, int y){
	x = getf(x); y = getf(y);
	if(x == y) return;
	if(siz[x] < siz[y]) swap(x, y);
	fa[x] = y; siz[x] += siz[y];
	stk[++tp] = Node(x, y, mx[x]);
	ans[x] = mx[x] = max(mx[x], mx[y]);
}
void work(const vector<ti3> &vc, int L, int R){
	if(vc.empty()) return;
	vector<ti3> vl, vr;
	int md = L + R >> 1, lst = tp;
	for(auto [l, r, id] : vc){
		if(l <= L && R <= r){
			if(id > 0) merg(u[id], v[id]);
			else {
				stk[++tp] = Node(u[-id], 0, mx[u[-id]]);
				ans[u[-id]] = mx[u[-id]] = max(mx[u[-id]], ans[v[-id]]);
			}
		} else {
			if(l <= md) vl.emplace_back(l, r, id);
			if(md < r) vr.emplace_back(l, r, id);
		}
	}
	work(vr, md + 1, R); work(vl, L, md);
	while(tp > lst){
		int x = stk[tp].x, y = stk[tp].y;
		if(y){
			ans[y] = max(ans[x], ans[y]);
			siz[x] -= siz[y];
		}
		fa[x] = x; mx[x] = stk[tp].val; -- tp;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1;i <= n;++ i){cin >> c[i] >> t[i] >> mx[i]; fa[i] = i; siz[i] = 1; ans[i] = mx[i];}
	vector<ti3> ed;
	for(int i = 1;i <= m;++ i){
		cin >> u[i] >> v[i];
		if(c[u[i]] > c[v[i]]) swap(u[i], v[i]);
		int l = c[v[i]], r = min(t[u[i]], t[v[i]]);
		if(l <= r) ed.emplace_back(l, r, i);
		l = c[u[i]]; r = min(t[u[i]], c[v[i]] - 1);
		if(l <= r) ed.emplace_back(l, r, -i);
	}
	work(ed, 1, 1000000000);
	for(int i = 1;i <= n;++ i) printf("%d%c", ans[i], " \n"[i == n]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 14980kb

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: 1ms
memory: 11392kb

input:

1 0
138088047 507565360 682493255

output:

682493255

result:

ok 1 number(s): "682493255"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 13456kb

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 3 4 4

result:

wrong answer 2nd numbers differ - expected: '4', found: '3'