답안 #617443

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617443 2022-08-01T11:20:52 Z patrikpavic2 Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
992 ms 63028 KB
#include <cstdio>
#include <vector>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
typedef pair < int, pii > pip;

const int N = 1e6 + 500;
const int NN = 505;
const int INF = 0x3f3f3f3f;

vector < pip > edg;
vector < pii > v[NN];

int kofa = 0, n, m, q;
int bar[N], gor[N], qq[N];
ll odg1[N], odg2[N], cnt1[N], cnt2[N];

int miin(int A, int B){
	if(!kofa) return (edg[A].X <= edg[B].X ? A : B);
	else 	  return (edg[A].X > edg[B].X ? A : B);
}

int get_path(int cur, int lst, int krj){
	if(cur == krj) return m;
	for(pii tmp : v[cur]){
		if(tmp.X == lst) continue;
		int rt = get_path(tmp.X, cur, krj);
		if(rt == -1) continue;
		return miin(rt, tmp.Y);
	}
	return -1;
}

void izbrisi(int i){
	int a = edg[i].Y.X, b = edg[i].Y.Y;
	v[a].erase(find(v[a].begin(), v[a].end(), (pii){b, i}));
	v[b].erase(find(v[b].begin(), v[b].end(), (pii){a, i}));
}

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 0;i < m;i++){
		int a, b, w; scanf("%d%d%d", &a, &b, &w);
		edg.PB({w, {a, b}});
	}
	edg.PB({INF, {-1, -1}});
	sort(edg.begin(), edg.end());
	for(int i = 0;i < m;i++){
		int a = edg[i].Y.X, b = edg[i].Y.Y, w = edg[i].X;
		int rt = get_path(a, a, b);
		if(rt == -1)
			bar[i] = -INF; 
		else{
			bar[i] = edg[rt].X + (w - edg[rt].X + 2) / 2;
			izbrisi(rt);
		}
		v[a].PB({b, i}); v[b].PB({a, i});
	}
	for(int i = 1;i <= n;i++) v[i].clear();
	kofa = 1; edg.back().X = -INF;
	for(int i = m - 1;i >= 0;i--){
		int a = edg[i].Y.X, b = edg[i].Y.Y, w = edg[i].X;
		int rt = get_path(a, a, b);
		if(rt == -1)
			gor[i] = INF; 
		else{
			gor[i] = w + (edg[rt].X - w) / 2;
			izbrisi(rt);
		}
		v[a].PB({b, i}); v[b].PB({a, i});
	}
	scanf("%d", &q);
	for(int i = 0;i < q;i++) scanf("%d", qq + i); 
	qq[q] = (ll)INF + 1;
	for(int j = 0;j < m;j++){
		int l = lower_bound(qq, qq + q, bar[j]) - qq;
		int dl = upper_bound(qq, qq + q, edg[j].X) - qq;
		int r = upper_bound(qq, qq + q, gor[j]) - qq;
		odg1[l] += edg[j].X; odg1[dl] -= edg[j].X;
		cnt1[l]++; cnt1[dl]--;
		odg2[dl] += edg[j].X; odg2[r] -= edg[j].X;
		cnt2[dl]++; cnt2[r]--;
	}
	for(int j = 0;j < q;j++){
		if(j){ 
			odg1[j] += odg1[j - 1]; odg2[j] += odg2[j - 1];
			cnt1[j] += cnt1[j - 1]; cnt2[j] += cnt2[j - 1];
		}
		printf("%lld\n", odg1[j] - cnt1[j] * qq[j] + qq[j] * cnt2[j] - odg2[j]);
	}
	return 0;
}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
reconstruction.cpp:51:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   int a, b, w; scanf("%d%d%d", &a, &b, &w);
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~~
reconstruction.cpp:80:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
reconstruction.cpp:81:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |  for(int i = 0;i < q;i++) scanf("%d", qq + i);
      |                           ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 898 ms 4072 KB Output is correct
21 Correct 363 ms 4068 KB Output is correct
22 Correct 601 ms 4080 KB Output is correct
23 Correct 671 ms 4044 KB Output is correct
24 Correct 588 ms 4088 KB Output is correct
25 Correct 699 ms 4128 KB Output is correct
26 Correct 768 ms 4116 KB Output is correct
27 Correct 725 ms 4024 KB Output is correct
28 Correct 723 ms 4088 KB Output is correct
29 Correct 630 ms 4160 KB Output is correct
30 Correct 789 ms 4216 KB Output is correct
31 Correct 741 ms 4056 KB Output is correct
32 Correct 765 ms 4112 KB Output is correct
33 Correct 738 ms 4088 KB Output is correct
34 Correct 454 ms 5204 KB Output is correct
35 Correct 759 ms 4100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 669 ms 60040 KB Output is correct
5 Correct 641 ms 60088 KB Output is correct
6 Correct 655 ms 60048 KB Output is correct
7 Correct 337 ms 61872 KB Output is correct
8 Correct 350 ms 62072 KB Output is correct
9 Correct 348 ms 62040 KB Output is correct
10 Correct 609 ms 60140 KB Output is correct
11 Correct 332 ms 62196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 305 ms 57436 KB Output is correct
21 Correct 263 ms 57560 KB Output is correct
22 Correct 236 ms 57504 KB Output is correct
23 Correct 231 ms 57508 KB Output is correct
24 Correct 233 ms 57520 KB Output is correct
25 Correct 233 ms 57504 KB Output is correct
26 Correct 232 ms 57560 KB Output is correct
27 Correct 269 ms 57584 KB Output is correct
28 Correct 238 ms 57548 KB Output is correct
29 Correct 241 ms 57556 KB Output is correct
30 Correct 222 ms 57560 KB Output is correct
31 Correct 243 ms 57420 KB Output is correct
32 Correct 227 ms 58104 KB Output is correct
33 Correct 222 ms 57356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 898 ms 4072 KB Output is correct
21 Correct 363 ms 4068 KB Output is correct
22 Correct 601 ms 4080 KB Output is correct
23 Correct 671 ms 4044 KB Output is correct
24 Correct 588 ms 4088 KB Output is correct
25 Correct 699 ms 4128 KB Output is correct
26 Correct 768 ms 4116 KB Output is correct
27 Correct 725 ms 4024 KB Output is correct
28 Correct 723 ms 4088 KB Output is correct
29 Correct 630 ms 4160 KB Output is correct
30 Correct 789 ms 4216 KB Output is correct
31 Correct 741 ms 4056 KB Output is correct
32 Correct 765 ms 4112 KB Output is correct
33 Correct 738 ms 4088 KB Output is correct
34 Correct 454 ms 5204 KB Output is correct
35 Correct 759 ms 4100 KB Output is correct
36 Correct 643 ms 5356 KB Output is correct
37 Correct 358 ms 5228 KB Output is correct
38 Correct 556 ms 5192 KB Output is correct
39 Correct 552 ms 5184 KB Output is correct
40 Correct 522 ms 5248 KB Output is correct
41 Correct 602 ms 5216 KB Output is correct
42 Correct 710 ms 5212 KB Output is correct
43 Correct 678 ms 5148 KB Output is correct
44 Correct 630 ms 5244 KB Output is correct
45 Correct 496 ms 5236 KB Output is correct
46 Correct 621 ms 5208 KB Output is correct
47 Correct 652 ms 5192 KB Output is correct
48 Correct 683 ms 5152 KB Output is correct
49 Correct 638 ms 5140 KB Output is correct
50 Correct 409 ms 6380 KB Output is correct
51 Correct 622 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 898 ms 4072 KB Output is correct
21 Correct 363 ms 4068 KB Output is correct
22 Correct 601 ms 4080 KB Output is correct
23 Correct 671 ms 4044 KB Output is correct
24 Correct 588 ms 4088 KB Output is correct
25 Correct 699 ms 4128 KB Output is correct
26 Correct 768 ms 4116 KB Output is correct
27 Correct 725 ms 4024 KB Output is correct
28 Correct 723 ms 4088 KB Output is correct
29 Correct 630 ms 4160 KB Output is correct
30 Correct 789 ms 4216 KB Output is correct
31 Correct 741 ms 4056 KB Output is correct
32 Correct 765 ms 4112 KB Output is correct
33 Correct 738 ms 4088 KB Output is correct
34 Correct 454 ms 5204 KB Output is correct
35 Correct 759 ms 4100 KB Output is correct
36 Correct 1 ms 308 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 308 KB Output is correct
39 Correct 669 ms 60040 KB Output is correct
40 Correct 641 ms 60088 KB Output is correct
41 Correct 655 ms 60048 KB Output is correct
42 Correct 337 ms 61872 KB Output is correct
43 Correct 350 ms 62072 KB Output is correct
44 Correct 348 ms 62040 KB Output is correct
45 Correct 609 ms 60140 KB Output is correct
46 Correct 332 ms 62196 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 305 ms 57436 KB Output is correct
49 Correct 263 ms 57560 KB Output is correct
50 Correct 236 ms 57504 KB Output is correct
51 Correct 231 ms 57508 KB Output is correct
52 Correct 233 ms 57520 KB Output is correct
53 Correct 233 ms 57504 KB Output is correct
54 Correct 232 ms 57560 KB Output is correct
55 Correct 269 ms 57584 KB Output is correct
56 Correct 238 ms 57548 KB Output is correct
57 Correct 241 ms 57556 KB Output is correct
58 Correct 222 ms 57560 KB Output is correct
59 Correct 243 ms 57420 KB Output is correct
60 Correct 227 ms 58104 KB Output is correct
61 Correct 222 ms 57356 KB Output is correct
62 Correct 643 ms 5356 KB Output is correct
63 Correct 358 ms 5228 KB Output is correct
64 Correct 556 ms 5192 KB Output is correct
65 Correct 552 ms 5184 KB Output is correct
66 Correct 522 ms 5248 KB Output is correct
67 Correct 602 ms 5216 KB Output is correct
68 Correct 710 ms 5212 KB Output is correct
69 Correct 678 ms 5148 KB Output is correct
70 Correct 630 ms 5244 KB Output is correct
71 Correct 496 ms 5236 KB Output is correct
72 Correct 621 ms 5208 KB Output is correct
73 Correct 652 ms 5192 KB Output is correct
74 Correct 683 ms 5152 KB Output is correct
75 Correct 638 ms 5140 KB Output is correct
76 Correct 409 ms 6380 KB Output is correct
77 Correct 622 ms 5208 KB Output is correct
78 Correct 912 ms 59020 KB Output is correct
79 Correct 626 ms 60972 KB Output is correct
80 Correct 786 ms 60040 KB Output is correct
81 Correct 789 ms 60036 KB Output is correct
82 Correct 807 ms 59192 KB Output is correct
83 Correct 910 ms 59032 KB Output is correct
84 Correct 976 ms 59028 KB Output is correct
85 Correct 973 ms 58984 KB Output is correct
86 Correct 992 ms 58980 KB Output is correct
87 Correct 777 ms 60688 KB Output is correct
88 Correct 922 ms 58984 KB Output is correct
89 Correct 925 ms 59016 KB Output is correct
90 Correct 946 ms 59144 KB Output is correct
91 Correct 879 ms 58948 KB Output is correct
92 Correct 680 ms 63028 KB Output is correct
93 Correct 932 ms 60224 KB Output is correct