QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#32057#1878. No Rest for the WickedcdwWA 432ms25160kbC++201.7kb2022-05-16 21:06:012022-05-16 21:06:03

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 21:06:03]
  • 评测
  • 测评结果:WA
  • 用时:432ms
  • 内存:25160kb
  • [2022-05-16 21:06:01]
  • 提交

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];
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[y] = x; 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[y] = y; 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: 6ms
memory: 12664kb

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: 4ms
memory: 12400kb

input:

1 0
138088047 507565360 682493255

output:

682493255

result:

ok 1 number(s): "682493255"

Test #3:

score: 0
Accepted
time: 1ms
memory: 12016kb

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: 6ms
memory: 11232kb

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: 2ms
memory: 11596kb

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

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: 0
Accepted
time: 4ms
memory: 11744kb

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 962437830 962437830

result:

ok 10 numbers

Test #8:

score: 0
Accepted
time: 82ms
memory: 13212kb

input:

200000 0
502890149 961474984 684355115
618086103 863569344 434733367
727711900 778917401 449199413
8011174 379179141 725890925
16795793 212474180 91233201
61041710 591880437 771789122
355201933 882765325 383668478
373739996 969001869 183781175
129261352 519815461 474556248
429116592 640858017 982574...

output:

684355115 434733367 449199413 725890925 91233201 771789122 383668478 183781175 474556248 982574287 109783216 367982401 479081650 344433184 613639949 572319457 77913195 538793070 88264426 986349435 648825997 904978549 91971034 949673971 367631282 322547831 867048248 787073323 415650496 193731725 6270...

result:

ok 200000 numbers

Test #9:

score: -100
Wrong Answer
time: 432ms
memory: 25160kb

input:

50000 100000
631923742 927638850 939027944
422118774 472623964 360940542
544501667 748795023 796768185
805611366 815713744 938768947
222601144 475048694 663730623
468473535 638903288 368277564
488325252 551840773 890693442
115749645 775910896 250388190
559998274 589294310 815047287
601668630 9808861...

output:

939027944 999960592 999960592 938768947 999997749 999988627 999988627 999997749 999939508 999921872 999997749 999997749 937233019 999997749 999997749 999997749 999939508 999988627 730368989 999921872 999997749 999921872 828135260 999921872 999997749 999997749 999997749 999921872 286117326 999997749 ...

result:

wrong answer 18th numbers differ - expected: '999997749', found: '999988627'