답안 #1107942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107942 2024-11-02T12:15:16 Z sleepntsheep 모자이크 (IOI24_mosaic) C++17
100 / 100
122 ms 30792 KB
#include "mosaic.h"
#include <vector>
#include <array>
#include <cstdio>
#include <algorithm>
#include <cstring>
using ll = long long;
using namespace std;

vector<ll> mosaic(vector<signed> X, vector<signed> Y,
                              vector<signed> T, vector<signed> B,
                              vector<signed> L, vector<signed> R) {
    vector<ll> Ans(T.size());

    int n = (int)X.size(), q = (int)T.size();
    for (int i = 0; i < q; ++i) ++T[i], ++B[i], ++L[i], ++R[i];

    for (auto mode : {'A', 'B'}) {

    static int up[4][1 << 18], left[1 << 18][4];
    memset(up, 0, sizeof up), memset(left, 0, sizeof left);
    for (int i = 1; i <= n; ++i) {
	up[1][i] = X[i - 1], left[i][1] = Y[i - 1];
	if (i <= 3) up[i][1] = Y[i - 1], left[1][i] = X[i - 1];
    }
    for (int k : {2, 3}) for (int i = k; i <= n; ++i) {
	up[k][i] = !up[k - 1][i] && !up[k][i - 1];
	left[i][k] = !left[i - 1][k] && !left[i][k - 1];
	if (i <= 3) up[i][k] |= left[i][k], left[k][i] = up[k][i];
    }

    static int diag_base[1 << 18];
    static ll diag_rig[1 << 18], diag_lef[1 << 18];//, diag_base[1 << 18];
    memset(diag_rig, 0, sizeof diag_rig);
    memset(diag_lef, 0, sizeof diag_lef);
    memset(diag_base, 0, sizeof diag_base);

    for (int i = 1; i + 2 <= n; ++i) {
	diag_base[i] = up[3][i + 2];
	if (mode == 'B') diag_base[1] = 0;
    	diag_rig[i] = diag_base[i] * 1ll * i + diag_rig[i - 1];
	diag_lef[i] = diag_base[i] * 1ll * (n - i) + diag_lef[i - 1];
	diag_base[i] += diag_base[i - 1];
    }

    for (int i = 1; i <= 3; ++i) for (int j = 1; j <= n; ++j) up[i][j] += up[i - 1][j] + up[i][j - 1] - up[i - 1][j - 1];
    for (int i = 1; i <= n; ++i) for (int j = 1; j <= 3; ++j) left[i][j] += left[i - 1][j] + left[i][j - 1] - left[i - 1][j - 1];


    for (int i = 0; i < q; ++i) {
	if (T[i] <= 3) {
	    int b = min(B[i], 3);
	    Ans[i] += up[b][R[i]] - up[b][L[i] - 1] - up[T[i] - 1][R[i]] + up[T[i] - 1][L[i] - 1];
	    T[i] = 4; B[i] = max(B[i], 3);
	}
	if (L[i] <= 3) {
	    int r = min(R[i], 3);
	    Ans[i] += left[B[i]][r] - left[T[i] - 1][r] - left[B[i]][L[i] - 1] + left[T[i] - 1][L[i] - 1];
	    L[i] = 4; R[i] = max(R[i], 3);
	}

	if (B[i] < T[i] || R[i] < L[i]) continue;

	ll high = 1 + R[i] - T[i];
	ll mid = L[i] - T[i] + 1;
	ll low = L[i] - B[i] + 1;

	if (high >= 1) {
	if (mid <= 1) {
	    ll ximal = min(high, B[i] - T[i] + 1ll);
	    int pp = high - ximal + 1;
	    Ans[i] += diag_lef[high] - diag_lef[pp - 1] - ((diag_base[high] - diag_base[pp - 1]) * (n - high - 1ll))
				+ (diag_base[pp - 1] * ximal);
	} else {
	    ll ximal = min(high - mid + 1, B[i] - T[i] + 1ll);
		int pp = high - ximal + 1;
		Ans[i] += diag_lef[high] - diag_lef[pp - 1] - ((diag_base[high] - diag_base[pp - 1]) * (n - high - 1ll)) 
				+ (diag_base[pp - 1] - diag_base[mid - 1]) * ximal;

	    ll Low = max(1ll, low);
	    

	    ximal = R[i] - L[i] + 1;
	    if (ximal >= mid - low) {
		Ans[i] += diag_rig[mid - 1] - diag_rig[Low - 1] + ((diag_base[mid - 1] - diag_base[Low - 1]) * (1ll - low));
	    } else {
		int pp = Low + (ximal - min(ximal, Low - low + 1));
		if (pp == Low) Ans[i] += (diag_base[mid - 1] - diag_base[Low - 1]) * ximal;
	else	Ans[i] += diag_rig[pp] - diag_rig[Low - 1] + ((diag_base[pp] - diag_base[Low - 1]) * (1ll - low))
				+ (diag_base[mid - 1] - diag_base[pp]) * ximal;
	    }
	}
	}
	    
	swap(L[i], T[i]), swap(R[i], B[i]);
    }
    swap(X, Y);
    }

    return Ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13648 KB Output is correct
2 Correct 3 ms 13648 KB Output is correct
3 Correct 3 ms 13900 KB Output is correct
4 Correct 3 ms 13648 KB Output is correct
5 Correct 3 ms 13648 KB Output is correct
6 Correct 3 ms 13608 KB Output is correct
7 Correct 3 ms 13744 KB Output is correct
8 Correct 3 ms 13648 KB Output is correct
9 Correct 4 ms 13648 KB Output is correct
10 Correct 3 ms 13648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13648 KB Output is correct
2 Correct 3 ms 13648 KB Output is correct
3 Correct 3 ms 13900 KB Output is correct
4 Correct 3 ms 13648 KB Output is correct
5 Correct 3 ms 13648 KB Output is correct
6 Correct 3 ms 13608 KB Output is correct
7 Correct 3 ms 13744 KB Output is correct
8 Correct 3 ms 13648 KB Output is correct
9 Correct 4 ms 13648 KB Output is correct
10 Correct 3 ms 13648 KB Output is correct
11 Correct 3 ms 13748 KB Output is correct
12 Correct 3 ms 13648 KB Output is correct
13 Correct 3 ms 13632 KB Output is correct
14 Correct 4 ms 13648 KB Output is correct
15 Correct 3 ms 13748 KB Output is correct
16 Correct 3 ms 13648 KB Output is correct
17 Correct 3 ms 13648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 28728 KB Output is correct
2 Correct 105 ms 28488 KB Output is correct
3 Correct 87 ms 27988 KB Output is correct
4 Correct 92 ms 28476 KB Output is correct
5 Correct 85 ms 26440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13648 KB Output is correct
2 Correct 3 ms 13648 KB Output is correct
3 Correct 3 ms 13900 KB Output is correct
4 Correct 3 ms 13648 KB Output is correct
5 Correct 3 ms 13648 KB Output is correct
6 Correct 3 ms 13608 KB Output is correct
7 Correct 3 ms 13744 KB Output is correct
8 Correct 3 ms 13648 KB Output is correct
9 Correct 4 ms 13648 KB Output is correct
10 Correct 3 ms 13648 KB Output is correct
11 Correct 3 ms 13748 KB Output is correct
12 Correct 3 ms 13648 KB Output is correct
13 Correct 3 ms 13632 KB Output is correct
14 Correct 4 ms 13648 KB Output is correct
15 Correct 3 ms 13748 KB Output is correct
16 Correct 3 ms 13648 KB Output is correct
17 Correct 3 ms 13648 KB Output is correct
18 Correct 74 ms 25224 KB Output is correct
19 Correct 70 ms 25168 KB Output is correct
20 Correct 70 ms 24832 KB Output is correct
21 Correct 68 ms 24904 KB Output is correct
22 Correct 67 ms 24912 KB Output is correct
23 Correct 66 ms 24904 KB Output is correct
24 Correct 61 ms 25172 KB Output is correct
25 Correct 62 ms 25160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 23004 KB Output is correct
2 Correct 112 ms 30464 KB Output is correct
3 Correct 102 ms 29768 KB Output is correct
4 Correct 103 ms 29768 KB Output is correct
5 Correct 107 ms 30024 KB Output is correct
6 Correct 93 ms 30552 KB Output is correct
7 Correct 93 ms 30520 KB Output is correct
8 Correct 91 ms 30400 KB Output is correct
9 Correct 82 ms 27976 KB Output is correct
10 Correct 84 ms 27976 KB Output is correct
11 Correct 77 ms 27976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 30024 KB Output is correct
2 Correct 99 ms 30396 KB Output is correct
3 Correct 90 ms 29000 KB Output is correct
4 Correct 93 ms 29008 KB Output is correct
5 Correct 101 ms 30792 KB Output is correct
6 Correct 78 ms 27984 KB Output is correct
7 Correct 72 ms 27208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 28728 KB Output is correct
2 Correct 105 ms 28488 KB Output is correct
3 Correct 87 ms 27988 KB Output is correct
4 Correct 92 ms 28476 KB Output is correct
5 Correct 85 ms 26440 KB Output is correct
6 Correct 97 ms 30024 KB Output is correct
7 Correct 99 ms 30396 KB Output is correct
8 Correct 90 ms 29000 KB Output is correct
9 Correct 93 ms 29008 KB Output is correct
10 Correct 101 ms 30792 KB Output is correct
11 Correct 78 ms 27984 KB Output is correct
12 Correct 72 ms 27208 KB Output is correct
13 Correct 99 ms 30536 KB Output is correct
14 Correct 122 ms 30536 KB Output is correct
15 Correct 104 ms 30652 KB Output is correct
16 Correct 98 ms 29000 KB Output is correct
17 Correct 99 ms 29884 KB Output is correct
18 Correct 100 ms 30388 KB Output is correct
19 Correct 84 ms 27584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13648 KB Output is correct
2 Correct 3 ms 13648 KB Output is correct
3 Correct 3 ms 13648 KB Output is correct
4 Correct 3 ms 13900 KB Output is correct
5 Correct 3 ms 13648 KB Output is correct
6 Correct 3 ms 13648 KB Output is correct
7 Correct 3 ms 13608 KB Output is correct
8 Correct 3 ms 13744 KB Output is correct
9 Correct 3 ms 13648 KB Output is correct
10 Correct 4 ms 13648 KB Output is correct
11 Correct 3 ms 13648 KB Output is correct
12 Correct 3 ms 13748 KB Output is correct
13 Correct 3 ms 13648 KB Output is correct
14 Correct 3 ms 13632 KB Output is correct
15 Correct 4 ms 13648 KB Output is correct
16 Correct 3 ms 13748 KB Output is correct
17 Correct 3 ms 13648 KB Output is correct
18 Correct 3 ms 13648 KB Output is correct
19 Correct 94 ms 28728 KB Output is correct
20 Correct 105 ms 28488 KB Output is correct
21 Correct 87 ms 27988 KB Output is correct
22 Correct 92 ms 28476 KB Output is correct
23 Correct 85 ms 26440 KB Output is correct
24 Correct 74 ms 25224 KB Output is correct
25 Correct 70 ms 25168 KB Output is correct
26 Correct 70 ms 24832 KB Output is correct
27 Correct 68 ms 24904 KB Output is correct
28 Correct 67 ms 24912 KB Output is correct
29 Correct 66 ms 24904 KB Output is correct
30 Correct 61 ms 25172 KB Output is correct
31 Correct 62 ms 25160 KB Output is correct
32 Correct 60 ms 23004 KB Output is correct
33 Correct 112 ms 30464 KB Output is correct
34 Correct 102 ms 29768 KB Output is correct
35 Correct 103 ms 29768 KB Output is correct
36 Correct 107 ms 30024 KB Output is correct
37 Correct 93 ms 30552 KB Output is correct
38 Correct 93 ms 30520 KB Output is correct
39 Correct 91 ms 30400 KB Output is correct
40 Correct 82 ms 27976 KB Output is correct
41 Correct 84 ms 27976 KB Output is correct
42 Correct 77 ms 27976 KB Output is correct
43 Correct 97 ms 30024 KB Output is correct
44 Correct 99 ms 30396 KB Output is correct
45 Correct 90 ms 29000 KB Output is correct
46 Correct 93 ms 29008 KB Output is correct
47 Correct 101 ms 30792 KB Output is correct
48 Correct 78 ms 27984 KB Output is correct
49 Correct 72 ms 27208 KB Output is correct
50 Correct 99 ms 30536 KB Output is correct
51 Correct 122 ms 30536 KB Output is correct
52 Correct 104 ms 30652 KB Output is correct
53 Correct 98 ms 29000 KB Output is correct
54 Correct 99 ms 29884 KB Output is correct
55 Correct 100 ms 30388 KB Output is correct
56 Correct 84 ms 27584 KB Output is correct
57 Correct 117 ms 30392 KB Output is correct
58 Correct 110 ms 29948 KB Output is correct
59 Correct 111 ms 30280 KB Output is correct
60 Correct 117 ms 29768 KB Output is correct
61 Correct 105 ms 29624 KB Output is correct
62 Correct 111 ms 30080 KB Output is correct
63 Correct 96 ms 27884 KB Output is correct
64 Correct 100 ms 26952 KB Output is correct