QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#310262#7998. 矩阵_ZMF_100 ✓6850ms427956kbC++115.8kb2024-01-21 09:52:522024-01-21 09:52:52

Judging History

你现在查看的是最新测评结果

  • [2024-01-21 09:52:52]
  • 评测
  • 测评结果:100
  • 用时:6850ms
  • 内存:427956kb
  • [2024-01-21 09:52:52]
  • 提交

answer

/*
60 + 0 + 100 + 64 = 224.
*/

#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define L(i, j, k) for (int i = (j); i <= (k); i++)
#define R(i, j, k) for (int i = (j); i >= (k); i--)
#define pb push_back
#define pii pair<int, int>
inline int read()
{
	int sum = 0, nega = 1;
	char ch = getchar();
	while (ch > '9'||ch < '0')
	{
	    if (ch == '-') nega = -1;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
	return sum * nega;
}
const int N = 3009, M = N * N, mod = 1e9 + 7;
inline void add(int &x, int y) {x = (x + y) % mod;}
inline void del(int &x, int y) {x = (x - y + mod) % mod;}
inline int Pow(int x, int y, int mo)
{
	int res = 1, base = x;
	while(y)
	{
		if(y & 1) res = 1ll * res * base % mo;
		base = 1ll * base * base % mo; y >>= 1;
	} return res;
}
int det[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
int n, Q;
struct node
{
	int x[4], v[4];
}b[M];
int a[N][N], p[N][N], val[M];
inline int id(int x, int y) {return (x - 1) * n + y;}
inline void get(int w1, int w2, int w3, int x, int y)
{
	L(i, 0, 3)
		L(j, 0, 3)
			if(b[w1].x[i] == b[w2].x[j] && b[w1].x[i] != w3 && b[w1].x[i])
			{
		//		cout << w1 << " " << w2 << " " << w3 << " " << b[w1].x[i] << "awa" << endl;
				p[x][y] = b[w1].x[i];
				val[p[x][y]] = (val[w1] - b[w1].v[i] + mod) % mod; return ;
			}
	puts("-1"); return ;
}
inline void get1(int x, int l, int y)
{
	if(l == 1)
	{
		int nw = id(x, 1);
		a[x][1] = 0, p[x][1] = nw;
		a[x][2] = (mod - b[nw].v[1]) % mod; nw = b[nw].x[1];
		p[x][2] = nw;
		val[p[x][2]] = a[x][2]; val[p[x][1]] = 0; l++;
	}
	y = min(n - 1, y);
	L(i, l, y)
	{
		int tt = 0;
		L(j, 1, 3)
			if(b[p[x][i]].x[j] == p[x][i - 1]) {tt = j; break;}
		tt ^= 1;
		p[x][i + 1] = b[p[x][i]].x[tt]; val[p[x][i + 1]] = (val[p[x][i]] - b[p[x][i]].v[tt] + mod);
		(val[p[x][i + 1]] >= mod) ? val[p[x][i + 1]] -= mod : 0;
	}
 	return ;
}
inline void get2(int x, int l, int y)
{
	if(l == 1)
	{
		int nw = id(1, x);
		a[1][x] = 0, p[1][x] = nw;
		a[2][x] = (mod - b[nw].v[3]) % mod; nw = b[nw].x[3]; p[2][x] = nw;
		val[p[2][x]] = a[2][x]; val[p[1][x]] = 0; l++;
	}
	y = min(n - 1, y);
	L(i, l, y)
	{
		int tt = 0;
		L(j, 1, 3)
			if(b[p[i][x]].x[j] == p[i - 1][x]) {tt = j; break;}
		tt ^= 1;
		p[i + 1][x] = b[p[i][x]].x[tt];
		val[p[i + 1][x]] = (val[p[i][x]] - b[p[i][x]].v[tt] + mod);
		(val[p[i + 1][x]] >= mod) ? val[p[i + 1][x]] -= mod : 0;
	}
	return ;
}
inline void get3(int x, int y)
{
	int nw = id(x, 1);
	a[x][1] = 0, p[x][1] = nw;
	a[x][2] = (mod - b[nw].v[1]) % mod; nw = b[nw].x[1];  p[x][2] = nw;
	y = min(n - 1, y);
	L(i, 2, y)
	{
		int tt = 0;
		L(j, 1, 3)
			if(b[p[x][i]].x[j] == p[x][i - 1]) {tt = j; break;}
		tt ^= 1;
		p[x][i + 1] = b[p[x][i]].x[tt]; a[x][i + 1] = (a[x][i] - b[p[x][i]].v[tt]);
		if(a[x][i + 1] < 0) a[x][i + 1] += mod;
		else if(a[x][i + 1] >= mod) a[x][i + 1] -= mod;
	}
	L(i, 1, y + 1) val[p[x][i]] = a[x][i];
 	return ;
}
inline void upd(int x, int w1, int w2)
{
	int ff = 3;
	if(b[x].x[0] == w1) ff = 0;
	else if(b[x].x[1] == w1) ff = 1;
	else if(b[x].x[2] == w1) ff = 2;
	b[x].x[ff] = w2;
	b[x].v[ff] = (val[x] - val[w2] + mod);
	if(b[x].v[ff] >= mod) b[x].v[ff] -= mod;  return ;
}
inline void mdf(int x, int w1, int d)
{
	L(i, 0, 3)
		if(b[x].x[i] == w1) {add(b[x].v[i], d); return ;} return ;
}
inline void update(int ax, int ay, int bx, int by)
{
	if(ax == bx) return ;
	L(i, ay, by)
	{
		upd(p[ax][i], p[ax - 1][i], p[bx - (i - ay)][ay - 1]), upd(p[bx][i], p[bx + 1][i], p[bx - (i - ay)][by + 1]),
		upd(p[ax - 1][i], p[ax][i], p[ax + (i - ay)][by]), upd(p[bx + 1][i], p[bx][i], p[ax + (i - ay)][ay]);
	}
	L(i, ax, bx)
	{
		upd(p[i][ay], p[i][ay - 1], p[bx + 1][ay + (i - ax)]), upd(p[i][by], p[i][by + 1], p[ax - 1][ay + (i - ax)]),
		upd(p[i][ay - 1], p[i][ay], p[ax][ay + (bx - i)]), upd(p[i][by + 1], p[i][by], p[bx][ay + (bx - i)]);
	}
	return ;
}
inline void modify(int ax, int ay, int bx, int by, int d)
{
	int tt = (mod - d) % mod;
	L(i, ay, by) mdf(p[ax][i], p[ax - 1][i], d), mdf(p[ax - 1][i], p[ax][i], tt);
	L(i, ay, by) mdf(p[bx][i], p[bx + 1][i], d), mdf(p[bx + 1][i], p[bx][i], tt);
	L(i, ax, bx) mdf(p[i][ay], p[i][ay - 1], d), mdf(p[i][ay - 1], p[i][ay], tt);
	L(i, ax, bx) mdf(p[i][by], p[i][by + 1], d), mdf(p[i][by + 1], p[i][by], tt);
	return ;
}
int tn;
int pown[M];
signed main()
{
//	freopen("5.in", "r", stdin);
	n = read(), Q = read(); tn = n;
	L(i, 2, n + 1)
	{
		a[i][2] = i;
		L(j, 3, n + 1) a[i][j] = 1ll * a[i][j - 1] * i % 998244353;
	}
	n += 2;
	L(i, 1, n)
		L(j, 1, n)
		{
			val[id(i, j)] = a[i][j];
			int wx = id(i, j);
			L(k, 0, 3)
			{
				int ax = i + det[k][0], ay = j + det[k][1];
				if(ax <= 0 || ax > n || ay <= 0 || ay > n) continue;
				int wy = id(ax, ay);
				b[wx].x[k] = wy;
				b[wx].v[k] = (a[i][j] - a[ax][ay] + mod) % mod;
 			}
		}
	L(i, 1, Q)
	{
		int op = read(), ax = read() + 1, ay = read() + 1, bx = read() + 1, by = read() + 1;
		get1(ax - 1, 1, by + 1); get1(bx + 1, 1, by + 1);
		get2(ay - 1, 1, bx + 1); get2(by + 1, 1, bx + 1);
		get(p[ax - 1][ay], p[ax][ay - 1], p[ax - 1][ay - 1], ax, ay);
		get(p[ax - 1][by], p[ax][by + 1], p[ax - 1][by + 1], ax, by);
		get(p[bx + 1][ay], p[bx][ay - 1], p[bx + 1][ay - 1], bx, ay);
		get(p[bx + 1][by], p[bx][by + 1], p[bx + 1][by + 1], bx, by);
		get1(ax, ay, by); get1(bx, ay, by); get2(ay, ax, bx); get2(by, ax, bx);
		if(op == 1) update(ax, ay, bx, by);
		else
		{
			int d = read(); modify(ax, ay, bx, by, d);
		}
	}
	L(i, 1, n) get3(i, n);
	n -= 2; pown[0] = 1;
	L(i, 1, n * n) pown[i] = 1ll * pown[i - 1] * 12345 % mod;
	int ans = 0;
	L(i, 1, n)
		L(j, 1, n) ans = (ans + 1ll * a[i + 1][j + 1] % mod * pown[(i - 1) * n + j] % mod) % mod;
	cout << ans << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 41ms
memory: 13940kb

input:

100 3000
1 4 3 100 99
1 3 8 83 88
1 4 7 96 99
1 2 7 90 95
2 6 5 98 98 762240996
1 9 8 98 97
1 3 3 100 100
2 18 7 97 84 230446266
1 2 5 94 97
1 2 18 82 98
1 9 2 100 93
1 3 9 91 97
1 1 2 99 100
1 7 6 98 97
1 2 4 98 100
1 3 2 99 98
1 4 2 100 98
2 9 74 28 83 703323901
1 6 4 100 98
2 2 6 99 93 882702932
...

output:

535773693

result:

ok 1 number(s): "535773693"

Test #2:

score: 10
Accepted
time: 3489ms
memory: 426600kb

input:

3000 3000
2 40 215 2496 2298 67590963
2 100 211 2684 2855 670656770
2 417 399 2612 2930 826127245
2 116 779 2407 2596 977282152
2 512 366 2768 2949 737671139
2 191 594 2671 2978 404448620
2 3 11 2720 2633 516813112
2 95 294 2553 2820 112269230
2 284 58 2934 2754 225336228
2 306 53 2815 2984 49218367...

output:

343427775

result:

ok 1 number(s): "343427775"

Test #3:

score: 10
Accepted
time: 4565ms
memory: 427480kb

input:

3000 2000
1 853 610 2674 2431
1 24 415 2490 2881
1 19 150 2842 2973
1 597 79 2977 2459
1 307 408 2397 2498
1 292 316 2907 2931
1 7 42 2953 2988
1 36 30 2953 2947
1 55 438 2609 2992
1 97 204 2664 2771
1 607 254 2803 2450
1 59 159 2808 2908
1 58 12 2991 2945
1 287 400 2506 2619
1 105 143 2949 2987
1 2...

output:

743809971

result:

ok 1 number(s): "743809971"

Test #4:

score: 10
Accepted
time: 4481ms
memory: 427436kb

input:

3000 2000
1 646 55 2815 2224
1 47 78 2964 2995
1 48 7 2882 2841
1 9 8 2999 2998
1 128 36 2984 2892
1 14 5 2990 2981
1 52 81 2934 2963
1 231 317 2612 2698
1 33 7 2960 2934
1 111 165 2732 2786
1 9 2 2994 2987
1 131 224 2866 2959
1 19 49 2917 2947
1 46 44 2997 2995
1 1 14 2969 2982
1 69 49 2975 2955
1 ...

output:

517390609

result:

ok 1 number(s): "517390609"

Test #5:

score: 10
Accepted
time: 6850ms
memory: 427192kb

input:

3000 3000
1 6 5 2997 2996
1 14 362 2624 2972
1 657 108 2405 1856
1 20 27 2983 2990
1 245 236 2903 2894
1 184 100 2957 2873
1 61 47 2954 2940
1 39 89 2935 2985
1 43 49 2956 2962
1 132 138 2763 2769
1 4 4 2998 2998
1 16 59 2752 2795
1 30 24 2997 2991
1 143 11 2959 2827
1 57 44 2887 2874
1 40 17 2991 2...

output:

632994577

result:

ok 1 number(s): "632994577"

Test #6:

score: 10
Accepted
time: 6762ms
memory: 427072kb

input:

3000 3000
1 544 5 2907 2368
1 60 63 2978 2981
1 228 310 2881 2963
1 57 71 2958 2972
1 101 565 2467 2931
1 979 1004 2882 2907
1 37 3 2913 2879
1 418 427 2922 2931
1 30 62 2937 2969
1 83 104 2979 3000
1 4 18 2939 2953
1 67 203 2834 2970
1 357 882 1000 1525
1 34 10 2991 2967
1 8 4 2997 2993
1 2 4 2991 ...

output:

275056325

result:

ok 1 number(s): "275056325"

Test #7:

score: 10
Accepted
time: 3761ms
memory: 426596kb

input:

3000 2000
1 82 42 2883 2843
1 2 48 2939 2985
2 188 176 2376 2976 715286463
1 15 24 2984 2993
1 106 50 2811 2755
2 45 132 2745 2432 339749026
1 5 100 2779 2874
1 343 134 2478 2269
1 106 227 2820 2941
2 10 206 2947 2798 365598855
2 560 106 2582 2903 92795190
1 74 100 2960 2986
1 5 33 2944 2972
2 873 3...

output:

191562107

result:

ok 1 number(s): "191562107"

Test #8:

score: 10
Accepted
time: 3688ms
memory: 426616kb

input:

3000 2000
1 20 5 2990 2975
1 14 10 2999 2995
1 192 89 2950 2847
2 547 646 2654 2940 439095457
1 18 16 3000 2998
1 35 105 2754 2824
1 17 52 2942 2977
2 356 121 2384 2963 959830720
2 76 78 2412 1842 361763869
2 199 46 2624 2931 743439747
2 180 320 2981 2964 772483137
2 173 122 2732 2901 759079379
1 47...

output:

787136396

result:

ok 1 number(s): "787136396"

Test #9:

score: 10
Accepted
time: 5650ms
memory: 427956kb

input:

3000 3000
1 220 131 2785 2696
2 1443 1396 2159 2850 578335729
1 536 1184 1545 2193
1 26 23 2999 2996
1 43 56 2881 2894
1 29 4 2872 2847
2 69 155 2681 2931 88398671
1 66 44 2945 2923
1 53 512 2515 2974
2 402 58 2752 2782 641047796
2 458 36 2859 2756 694998888
2 145 192 2995 2973 483103477
1 117 315 2...

output:

973923858

result:

ok 1 number(s): "973923858"

Test #10:

score: 10
Accepted
time: 5771ms
memory: 426624kb

input:

3000 3000
2 7 47 2887 2544 535526356
2 160 639 2988 2995 343766215
1 122 40 2985 2903
2 62 240 2858 2177 841981272
1 169 18 2682 2531
1 61 286 2729 2954
1 180 27 2994 2841
1 238 330 2881 2973
2 57 188 2880 2914 203515190
1 28 61 2903 2936
2 102 269 2876 2397 681849386
1 3 53 2896 2946
1 101 56 2985 ...

output:

328382756

result:

ok 1 number(s): "328382756"