답안 #1106532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106532 2024-10-30T15:01:18 Z Octagons 모자이크 (IOI24_mosaic) C++17
100 / 100
333 ms 26188 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+2, lim = 3;
int n, q, a[lim][N], b[N][lim];
vector<int> v, v2;
ll pref[N], pref2[N];
ll geta(int rw, int l, int r) {
	return a[rw][r] - (l ? a[rw][l-1] : 0);
}
 
ll getb(int col, int l, int r) {
	l = max(l, lim-1);
	if (l > r)return 0;
	return b[r][col] - b[l-1][col];
}
 
ll getp(int l, int r) {
	return pref[r] - (l ? pref[l-1] : 0ll);
}
 
ll getp2(int l, int r) {
	return pref2[r] - (l ? pref2[l-1] : 0ll);
}
 
ll get(int x, int y) {
	if (x < 0 || y < 0)return 0;
	ll ret = 0;
	for (int i = 0; i+1 < lim && i <= x; i++) {
		ret += geta(i, 0, y);
	}
	for (int i = 0; i+1 < lim && i <= y; i++) {
		ret += getb(i, 0, x);
	}
	if (x+1 < lim || y+1 < lim)return ret;
	x -= (lim - 1), y -= (lim - 1);
	int id = upper_bound(v.begin(), v.end(), y+1) - v.begin();
	if (id) {
		--id;
		int id2 = upper_bound(v.begin(), v.end(), y-x) - v.begin();
		--id2;
		id2 = min(id2, id);
		if (id2 == -1) {
			ret += ll(id+1) * ll(y+1) - getp(0, id);
		} else {
			ret += ll(id2+1) * ll(x+1);
			if (id2 != id)ret += ll(id-id2) * ll(y+1) - getp(id2+1, id);
		}
	}
	swap(x, y);
	id = upper_bound(v2.begin(), v2.end(), y+1) - v2.begin();
	if (id) {
		--id;
		int id2 = upper_bound(v2.begin(), v2.end(), y-x) - v2.begin();
		--id2;
		id2 = min(id2, id);
		if (id2 == -1) {
			ret += ll(id+1) * ll(y+1) - getp2(0, id);
		} else {
			ret += ll(id2+1) * ll(x+1);
			if (id2 != id)ret += ll(id-id2) * ll(y+1) - getp2(id2+1, id);
		}
	}
	return ret;
}
 
vector<long long> mosaic(vector<int> X, vector<int> Y, vector<int> T, vector<int> B, vector<int> L, vector<int> R) {
	q = L.size();
	n = X.size();
	v.clear();
	v2.clear();
	vector<long long> ret(q);
	for (int i = 0; i < n; i++) {
		a[0][i] = X[i];
		b[i][0] = Y[i];
		if (i < lim) {
			b[0][i] = X[i];
			a[i][0] = Y[i];
		}
	}
	for (int i = 1; i < lim; i++) {
		for (int j = 1; j < n; j++) {
			a[i][j] = (a[i-1][j] || a[i][j-1] ? 0 : 1);
		}
	}
	for (int i = 0; i < lim; i++) {
		for (int j = 1; j < n; j++) {
			if (i == lim-1) {
				continue;
			}
			a[i][j] += a[i][j-1];
		}
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < lim; j++) {
			b[i][j] = (b[i-1][j] || b[i][j-1] ? 0 : 1);
		}
	}
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < lim; j++) {
			if (j == lim-1) {
				continue;
			}
			b[i][j] += b[i-1][j];
		}
	}
	for (int i = lim-1; i < n; i++) {
		if (a[lim-1][i]) {
			v.push_back(i - (lim - 1));
		}
	}
	for (int j = lim; j < n; j++) {
		if (b[j][lim-1]) {
			v2.push_back(j - (lim - 1));
		}
	}
	ll sm = 0;
	for (int i = 0; i < v.size(); i++) {
		sm += ll(v[i]);
		pref[i] = sm;
	}
	sm = 0;
	for (int i = 0; i < v2.size(); i++) {
		sm += ll(v2[i]);
		pref2[i] = sm;
	}
	for (int i = 0; i < q; i++) {
		int x = T[i], y = L[i];
		int x2 = B[i], y2 = R[i];
		ret[i] = get(x2, y2) - get(x-1, y2) - get(x2, y-1) + get(x-1, y-1);
	}
	return ret;
}

Compilation message

mosaic.cpp: In function 'std::vector<long long int> mosaic(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
mosaic.cpp:118:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
mosaic.cpp:123:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |  for (int i = 0; i < v2.size(); i++) {
      |                  ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 19996 KB Output is correct
2 Correct 84 ms 23872 KB Output is correct
3 Correct 85 ms 23360 KB Output is correct
4 Correct 81 ms 23872 KB Output is correct
5 Correct 68 ms 20796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 202 ms 14408 KB Output is correct
19 Correct 188 ms 18004 KB Output is correct
20 Correct 169 ms 17736 KB Output is correct
21 Correct 167 ms 17692 KB Output is correct
22 Correct 171 ms 17736 KB Output is correct
23 Correct 160 ms 17756 KB Output is correct
24 Correct 141 ms 17924 KB Output is correct
25 Correct 145 ms 17992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 14340 KB Output is correct
2 Correct 319 ms 20032 KB Output is correct
3 Correct 274 ms 25152 KB Output is correct
4 Correct 275 ms 25288 KB Output is correct
5 Correct 261 ms 25564 KB Output is correct
6 Correct 272 ms 25920 KB Output is correct
7 Correct 292 ms 25792 KB Output is correct
8 Correct 251 ms 25936 KB Output is correct
9 Correct 265 ms 22264 KB Output is correct
10 Correct 235 ms 22384 KB Output is correct
11 Correct 222 ms 22388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 20032 KB Output is correct
2 Correct 258 ms 25800 KB Output is correct
3 Correct 202 ms 24352 KB Output is correct
4 Correct 194 ms 24136 KB Output is correct
5 Correct 195 ms 26188 KB Output is correct
6 Correct 187 ms 22340 KB Output is correct
7 Correct 175 ms 21040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 19996 KB Output is correct
2 Correct 84 ms 23872 KB Output is correct
3 Correct 85 ms 23360 KB Output is correct
4 Correct 81 ms 23872 KB Output is correct
5 Correct 68 ms 20796 KB Output is correct
6 Correct 247 ms 20032 KB Output is correct
7 Correct 258 ms 25800 KB Output is correct
8 Correct 202 ms 24352 KB Output is correct
9 Correct 194 ms 24136 KB Output is correct
10 Correct 195 ms 26188 KB Output is correct
11 Correct 187 ms 22340 KB Output is correct
12 Correct 175 ms 21040 KB Output is correct
13 Correct 301 ms 25784 KB Output is correct
14 Correct 249 ms 25664 KB Output is correct
15 Correct 281 ms 25864 KB Output is correct
16 Correct 223 ms 24128 KB Output is correct
17 Correct 235 ms 25408 KB Output is correct
18 Correct 247 ms 25824 KB Output is correct
19 Correct 219 ms 21460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 81 ms 19996 KB Output is correct
20 Correct 84 ms 23872 KB Output is correct
21 Correct 85 ms 23360 KB Output is correct
22 Correct 81 ms 23872 KB Output is correct
23 Correct 68 ms 20796 KB Output is correct
24 Correct 202 ms 14408 KB Output is correct
25 Correct 188 ms 18004 KB Output is correct
26 Correct 169 ms 17736 KB Output is correct
27 Correct 167 ms 17692 KB Output is correct
28 Correct 171 ms 17736 KB Output is correct
29 Correct 160 ms 17756 KB Output is correct
30 Correct 141 ms 17924 KB Output is correct
31 Correct 145 ms 17992 KB Output is correct
32 Correct 63 ms 14340 KB Output is correct
33 Correct 319 ms 20032 KB Output is correct
34 Correct 274 ms 25152 KB Output is correct
35 Correct 275 ms 25288 KB Output is correct
36 Correct 261 ms 25564 KB Output is correct
37 Correct 272 ms 25920 KB Output is correct
38 Correct 292 ms 25792 KB Output is correct
39 Correct 251 ms 25936 KB Output is correct
40 Correct 265 ms 22264 KB Output is correct
41 Correct 235 ms 22384 KB Output is correct
42 Correct 222 ms 22388 KB Output is correct
43 Correct 247 ms 20032 KB Output is correct
44 Correct 258 ms 25800 KB Output is correct
45 Correct 202 ms 24352 KB Output is correct
46 Correct 194 ms 24136 KB Output is correct
47 Correct 195 ms 26188 KB Output is correct
48 Correct 187 ms 22340 KB Output is correct
49 Correct 175 ms 21040 KB Output is correct
50 Correct 301 ms 25784 KB Output is correct
51 Correct 249 ms 25664 KB Output is correct
52 Correct 281 ms 25864 KB Output is correct
53 Correct 223 ms 24128 KB Output is correct
54 Correct 235 ms 25408 KB Output is correct
55 Correct 247 ms 25824 KB Output is correct
56 Correct 219 ms 21460 KB Output is correct
57 Correct 324 ms 25928 KB Output is correct
58 Correct 261 ms 25408 KB Output is correct
59 Correct 333 ms 25664 KB Output is correct
60 Correct 266 ms 25112 KB Output is correct
61 Correct 283 ms 25028 KB Output is correct
62 Correct 257 ms 25268 KB Output is correct
63 Correct 254 ms 22340 KB Output is correct
64 Correct 228 ms 20552 KB Output is correct