답안 #1104684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104684 2024-10-24T08:43:11 Z Nonoze 모자이크 (IOI24_mosaic) C++17
100 / 100
209 ms 65320 KB
#include "mosaic.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define cmax(a, b) a=max(a, b)
#define cmin(a, b) a=min(a, b)
#define fi first
#define se second

vector<int> diagor, diagol, diago;

int query(int l, int r) {
	if (l>r) return 0;
	if (l==0) return diago[r];
	return diago[r]-diago[l-1];
}

int queryl(int l, int r) {
	if (l>r) return 0;
	if (l==0) return diagol[r];
	int rem=l*query(l, r);
	return diagol[r]-diagol[l-1]-rem;
}

int queryr(int l, int r) {
	if (l>r) return 0;
	if (l==0) return diagor[r];
	int rem=(sz(diago)-r-1)*query(l, r);
	return diagor[r]-diagor[l-1]-rem;
}

int calc(int x, int y, int a, int b) {
	assert(x==0);
	int mn=min(a+1, b-y+1);
	int l=y-a, midl=y-a+mn-1, midr=b-mn+1, r=b;
	int ansl=queryl(l, midl-1);
	int ansr=queryr(midr+1, r);
	int ansmid=query(midl, midr)*mn;
	return ansl+ansr+ansmid;
}


int to_add, sz;

int calcq(int x, int a, int y, int b, vector<vector<int>>& line, vector<vector<int>>& column) {
	int ans=0;
	int fx=x, fy=y, fa=a, fb=b;
	cmax(fx, sz), cmax(fy, sz);
	if (fx<=fa && fy<=fb) {
		ans+=calc(0, fy-fx+to_add, fa-fx, fb-fx+to_add);
	}
	if (x<sz && b>=sz) {
		for (int i=x; i<min(a+1, sz); i++) {
			ans+=line[i][b]-line[i][max(sz-1, y-1)];
		}
	}
	if (y<sz) {
		for (int i=y; i<min(b+1, sz); i++) {
			ans+=column[a][i]-(x?column[x-1][i]:0);
		}
	}
	return ans;
}

vector<signed> x, y, t, b, l, r;
int n, q;


vector<int> mosaic(vector<signed> X, vector<signed> Y, vector<signed> T, vector<signed> B, vector<signed> L, vector<signed> R) {	
	x=X, y=Y, t=T, b=B, l=L, r=R, n=sz(x), q=sz(t);
	sz=min(5LL, n);
	vector<vector<int>> line(sz), column(n);
	for (int i=0; i<n; i++) line[0].pb(x[i]), column[i].pb(y[i]);
	for (int i=1; i<sz; i++) line[i].pb(column[i][0]), column[0].pb(line[0][i]);
	for (int i=1; i<sz; i++) {
		for (int j=1; j<n; j++) {
			if (line[i-1][j]==0 && line[i][j-1]==0) line[i].pb(1);
			else line[i].pb(0);
		}
	}
	for (int i=1; i<n; i++) {
		for (int j=1; j<sz; j++) {
			if (column[i-1][j]==0 && column[i][j-1]==0) column[i].pb(1);
			else column[i].pb(0);
		}
	}

	to_add=n-1-sz+1;
	for (int i=n-1; i>=sz; i--) diago.pb(column[i][sz-1]);
	for (int i=sz-1; i<n; i++) diago.pb(line[sz-1][i]);
	for (int i=0; i<sz; i++) {
		for (int j=1; j<n; j++) {
			line[i][j]+=line[i][j-1];
			column[j][i]+=column[j-1][i];
		}
	}
	diagor=diagol=diago;
	diagor[0]=sz(diago)*diago[0];
	for (int i=1; i<sz(diago); i++) diagol[i]=diagol[i-1]+diago[i]*(i+1);
	for (int i=1; i<sz(diago); i++) diagor[i]=diagor[i-1]+diago[i]*(sz(diago)-i);
	for (int i=1; i<sz(diago); i++) diago[i]+=diago[i-1];
	vector<int> ans;
	for (int tt=0; tt<q; tt++) {
		ans.pb(calcq(t[tt], b[tt], l[tt], r[tt], line, column));
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 63532 KB Output is correct
2 Correct 148 ms 63032 KB Output is correct
3 Correct 199 ms 63024 KB Output is correct
4 Correct 161 ms 63012 KB Output is correct
5 Correct 113 ms 39016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 72 ms 17856 KB Output is correct
19 Correct 71 ms 17596 KB Output is correct
20 Correct 73 ms 17340 KB Output is correct
21 Correct 114 ms 17340 KB Output is correct
22 Correct 77 ms 17412 KB Output is correct
23 Correct 75 ms 16864 KB Output is correct
24 Correct 72 ms 17120 KB Output is correct
25 Correct 70 ms 16908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 14272 KB Output is correct
2 Correct 173 ms 64808 KB Output is correct
3 Correct 166 ms 64240 KB Output is correct
4 Correct 175 ms 64288 KB Output is correct
5 Correct 150 ms 64488 KB Output is correct
6 Correct 163 ms 64824 KB Output is correct
7 Correct 154 ms 64820 KB Output is correct
8 Correct 158 ms 64824 KB Output is correct
9 Correct 124 ms 40256 KB Output is correct
10 Correct 123 ms 40244 KB Output is correct
11 Correct 117 ms 40256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 64808 KB Output is correct
2 Correct 145 ms 64828 KB Output is correct
3 Correct 149 ms 63272 KB Output is correct
4 Correct 144 ms 63400 KB Output is correct
5 Correct 142 ms 65320 KB Output is correct
6 Correct 107 ms 40552 KB Output is correct
7 Correct 96 ms 29916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 63532 KB Output is correct
2 Correct 148 ms 63032 KB Output is correct
3 Correct 199 ms 63024 KB Output is correct
4 Correct 161 ms 63012 KB Output is correct
5 Correct 113 ms 39016 KB Output is correct
6 Correct 146 ms 64808 KB Output is correct
7 Correct 145 ms 64828 KB Output is correct
8 Correct 149 ms 63272 KB Output is correct
9 Correct 144 ms 63400 KB Output is correct
10 Correct 142 ms 65320 KB Output is correct
11 Correct 107 ms 40552 KB Output is correct
12 Correct 96 ms 29916 KB Output is correct
13 Correct 153 ms 64832 KB Output is correct
14 Correct 142 ms 64868 KB Output is correct
15 Correct 145 ms 65072 KB Output is correct
16 Correct 152 ms 63216 KB Output is correct
17 Correct 142 ms 64808 KB Output is correct
18 Correct 157 ms 64808 KB Output is correct
19 Correct 106 ms 35924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 146 ms 63532 KB Output is correct
20 Correct 148 ms 63032 KB Output is correct
21 Correct 199 ms 63024 KB Output is correct
22 Correct 161 ms 63012 KB Output is correct
23 Correct 113 ms 39016 KB Output is correct
24 Correct 72 ms 17856 KB Output is correct
25 Correct 71 ms 17596 KB Output is correct
26 Correct 73 ms 17340 KB Output is correct
27 Correct 114 ms 17340 KB Output is correct
28 Correct 77 ms 17412 KB Output is correct
29 Correct 75 ms 16864 KB Output is correct
30 Correct 72 ms 17120 KB Output is correct
31 Correct 70 ms 16908 KB Output is correct
32 Correct 76 ms 14272 KB Output is correct
33 Correct 173 ms 64808 KB Output is correct
34 Correct 166 ms 64240 KB Output is correct
35 Correct 175 ms 64288 KB Output is correct
36 Correct 150 ms 64488 KB Output is correct
37 Correct 163 ms 64824 KB Output is correct
38 Correct 154 ms 64820 KB Output is correct
39 Correct 158 ms 64824 KB Output is correct
40 Correct 124 ms 40256 KB Output is correct
41 Correct 123 ms 40244 KB Output is correct
42 Correct 117 ms 40256 KB Output is correct
43 Correct 146 ms 64808 KB Output is correct
44 Correct 145 ms 64828 KB Output is correct
45 Correct 149 ms 63272 KB Output is correct
46 Correct 144 ms 63400 KB Output is correct
47 Correct 142 ms 65320 KB Output is correct
48 Correct 107 ms 40552 KB Output is correct
49 Correct 96 ms 29916 KB Output is correct
50 Correct 153 ms 64832 KB Output is correct
51 Correct 142 ms 64868 KB Output is correct
52 Correct 145 ms 65072 KB Output is correct
53 Correct 152 ms 63216 KB Output is correct
54 Correct 142 ms 64808 KB Output is correct
55 Correct 157 ms 64808 KB Output is correct
56 Correct 106 ms 35924 KB Output is correct
57 Correct 209 ms 64800 KB Output is correct
58 Correct 167 ms 64552 KB Output is correct
59 Correct 187 ms 65064 KB Output is correct
60 Correct 165 ms 64928 KB Output is correct
61 Correct 184 ms 64152 KB Output is correct
62 Correct 150 ms 64552 KB Output is correct
63 Correct 122 ms 40548 KB Output is correct
64 Correct 91 ms 28652 KB Output is correct