Submission #629675

# Submission time Handle Problem Language Result Execution time Memory
629675 2022-08-14T21:43:26 Z flappybird Reconstruction Project (JOI22_reconstruction) C++17
31 / 100
249 ms 15288 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 1010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
int p[MAX][505];
ll r[MAX];
ll l[MAX];
int A[MAX];
int B[MAX];
ll W[MAX];
int find(int t, int x) {
	if (p[t][x] == x) return x;
	else return p[t][x] = find(t, p[t][x]);
}
bool uni(int t, int u, int v) {
	u = find(t, u);
	v = find(t, v);
	if (u == v) return false;
	p[t][u] = v;
	return true;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N, M;
	cin >> N >> M;
	int i, j;
	vector<pair<ll, pii>> in;
	int a, b, c;
	in.push_back({ 0, {0, 0} });
	for (i = 1; i <= M; i++) cin >> a >> b >> c, in.push_back(make_pair(c, pii(a, b)));
	sort(in.begin(), in.end());
	for (i = 1; i <= M; i++) tie(A[i], B[i], W[i]) = make_tuple(in[i].second.first, in[i].second.second, in[i].first);
	for (i = 1; i <= N; i++) for (j = 1; j <= M; j++) p[j][i] = i;
	W[0] = -2000000010;
	W[M + 1] = 2000000010;
	for (i = M; i >= 1; i--) {
		for (j = i; j <= M; j++) if (!uni(j, A[i], B[i])) break;
		r[i] = W[j];
	}
	for (i = 1; i <= N; i++) for (j = 1; j <= M; j++) p[j][i] = i;
	for (i = 1; i <= M; i++) {
		for (j = i; j >= 1; j--) if (!uni(j, A[i], B[i])) break;
		l[i] = W[j];
	}
	vector<pll> sum, mul;
	for (i = 1; i <= M; i++) {
		if (l[i] != W[i]) {
			ll loc = (W[i] + l[i]) / 2 + 1;
			sum.emplace_back(loc, W[i]);
			sum.emplace_back(W[i], -W[i]);
			mul.emplace_back(loc, -1);
			mul.emplace_back(W[i], 1);
		}
		if (r[i] != W[i]) {
			ll loc = (W[i] + r[i]) / 2;
			sum.emplace_back(W[i] + 1, -W[i]);
			sum.emplace_back(loc + 1, W[i]);
			mul.emplace_back(W[i] + 1, 1);
			mul.emplace_back(loc + 1, -1);
		}
	}
	sort(mul.begin(), mul.end());
	sort(sum.begin(), sum.end());
	int Q;
	cin >> Q;
	ll s, m;
	s = m = 0;
	int ptr1, ptr2;
	ptr1 = 0, ptr2 = 0;
	while (Q--) {
		ll x;
		cin >> x;
		while (ptr1 < sum.size() && sum[ptr1].first <= x) s += sum[ptr1++].second;
		while (ptr2 < mul.size() && mul[ptr2].first <= x) m += mul[ptr2++].second;
		cout << x * m + s << ln;
	}
}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:84:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   while (ptr1 < sum.size() && sum[ptr1].first <= x) s += sum[ptr1++].second;
      |          ~~~~~^~~~~~~~~~~~
reconstruction.cpp:85:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   while (ptr2 < mul.size() && mul[ptr2].first <= x) m += mul[ptr2++].second;
      |          ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Runtime error 34 ms 7984 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Runtime error 37 ms 8000 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 226 ms 14704 KB Output is correct
21 Correct 249 ms 14840 KB Output is correct
22 Correct 198 ms 14752 KB Output is correct
23 Correct 197 ms 14768 KB Output is correct
24 Correct 197 ms 14712 KB Output is correct
25 Correct 220 ms 14784 KB Output is correct
26 Correct 229 ms 14796 KB Output is correct
27 Correct 213 ms 14768 KB Output is correct
28 Correct 199 ms 14720 KB Output is correct
29 Correct 204 ms 14828 KB Output is correct
30 Correct 196 ms 14772 KB Output is correct
31 Correct 223 ms 14712 KB Output is correct
32 Correct 202 ms 15288 KB Output is correct
33 Correct 201 ms 14528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Runtime error 34 ms 7984 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Runtime error 34 ms 7984 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -