QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#417136#8410. Splatanie ciągów [A]luanmenglei0 97ms12320kbC++173.7kb2024-05-22 14:57:142024-05-22 14:57:15

Judging History

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

  • [2024-05-22 14:57:15]
  • 评测
  • 测评结果:0
  • 用时:97ms
  • 内存:12320kb
  • [2024-05-22 14:57:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace SOL {

using i64 = long long;
void debug(const char *msg, ...) {
#ifdef CLESIP
    va_list arg;
    static char pbString[512];
    va_start(arg,msg);
    vsprintf(pbString,msg,arg);
    cerr << "[DEBUG] " << pbString << "\n";
    va_end(arg);
#endif    
}
template<typename T, typename L>
bool chkmax(T &x, L y) { if (x < y) return x = y, true; return false; }
template<typename T, typename L>
bool chkmin(T &x, L y) { if (y < x) return x = y, true; return false; }

const int N = 3e5 + 10;
const i64 P = 1e9 + 7;
const i64 inv2 = (P + 1) / 2;
int n, m, arr[N], b[N];
i64 ans[N * 2], sum[3][N];
vector<array<int, 2>> vec;

void mod(i64 &x, i64 y) {
	x += y;
	if (x >= P)
		x -= P;
}

i64 calc_val(int t) {
	i64 tmp = min(t - 1, m);
	return tmp * (2 * m - tmp + 1) / 2 % P;
}

void calc(int x) {
	vector<int> pt;
	pt.push_back(0);
	for (auto [l, r] : vec) {
		int pos = l + x;
		while (pos <= r)
			pt.push_back(pos), pos += x;
	}
	int cnt = pt.size() - 1;
	pt.push_back(n + 1);
	for (int i = 1; i <= cnt; i ++) {
		i64 coef = pt[i + 1] - pt[i];
		sum[0][i] = sum[0][i - 1], sum[1][i] = sum[1][i - 1], sum[2][i] = sum[2][i - 1];
		mod(sum[0][i], coef);
		mod(sum[1][i], coef * i % P);
		mod(sum[2][i], coef * i % P * i % P);
	}
	int j = 0, lst = 0;
	for (int t = 0; t < (int) vec.size(); t ++) {
		auto [l, r] = vec[t];
		vector<int> cur;
		cur.push_back(0);
		int pos = r - x;
		while (pos >= l)
			cur.push_back(pos), pos -= x;
		while (j <= cnt && pt[j] <= r)
			j ++;
		int tot = cur.size() - 1;
		cur.push_back(lst);
		for (int i = 1; i <= tot && i <= m; i ++) {
			i64 coef = cur[i] - cur[i + 1];
			// 0 add
			{
				i64 other = pt[j] - r - 1;
				mod(ans[x], coef * other % P * calc_val(i));
			}
			if (i < m) {
				int to = min(cnt, j + m - i - 1);
				i64 sum0 = (sum[0][to] - sum[0][j - 1] + P) % P;
				i64 sum1 = (sum[1][to] - sum[1][j - 1] + 2 * P - sum0 * (j - 1) % P) % P;
				i64 sum2 = (sum[2][to] - sum[2][j - 1] - sum0 * (j - 1) % P * (j - 1) % P - sum1 * 2 % P * (j - 1) % P + 3 * P) % P;
				i64 c0 = coef;
				i64 c1 = c0 * i % P;
				i64 c2 = c1 * i % P; 
				i64 val = (
					(2 * m + 1) * sum1 % P * c0 % P
					+ (2 * m + 1) * sum0 % P * c1 % P
					- sum2 * c0 % P
					- c2 * sum0 % P
					- 2 * sum1 % P * c1 % P
					+ 3 * P
				) % P * inv2 % P;
				mod(ans[x], val);
			}
		}
		// in block
		i64 coef = l - lst - 1;
		for (int i = 1; l + i * x <= r; i ++) {
			int L = l + i * x, R = min(r, l + i * x + x - 1);
			mod(ans[x], 1ll * (R - L + 1) * 
					calc_val(i) % P * coef % P);
		}
		lst = r - x;
	}
}

void work() {
	for (int i = 1; i <= n; i ++)
		cin >> arr[i];
	for (int i = 1; i < n; i ++)
		b[i] = (arr[i] < arr[i + 1]);
	for (int i = 1; i < n; i ++) {
		int j = i;
		while (j + 1 < n && b[j + 1] == b[j])
			j += 1;
		vec.push_back({ i, j });
		i = j;
	}
	for (auto [_l, _r] : vec) {
		int len = _r - _l;
		for (int x = 1; x < len; x ++) {
			for (int j = 1 + x, i = 1; j <= len; j += x, i ++) {
				int l = j, r = min(len, j + x - 1);
				mod(ans[x], 1ll * (1ll * (r - l + 1) * (m - l + 1 + m - r + 1) / 2 % P) * 
					calc_val(i) % P);			
			}
		}
	}
	for (int x = 1; x < n; x ++) {
		vector<array<int, 2>> nxt;
		for (auto [l, r] : vec)
			if (r - l >= x)
				nxt.push_back({ l, r });
		swap(nxt, vec);
		calc(x);
	}
}

void solve() {
	cin >> n >> m;
	work();
	swap(n, m);
	work();
	ans[0] = (1ll * n * (n + 1) / 2 % P) * (1ll * m * (m + 1) / 2 % P) % P;
	cout << 0 << " ";
	for (int i = 0; i < n + m - 1; i ++)
		cout << (ans[i] - ans[i + 1] + P) % P << " \n"[i + 1 == n + m];
}

}
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	SOL::solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 1
Accepted
time: 1ms
memory: 7684kb

input:

1 1
1
2

output:

0 1 

result:

ok single line: '0 1 '

Test #2:

score: 0
Accepted
time: 1ms
memory: 7784kb

input:

2 1
2 3
1

output:

0 3 0 

result:

ok single line: '0 3 0 '

Test #3:

score: 0
Accepted
time: 1ms
memory: 7780kb

input:

1 3
1
4 2 3

output:

0 6 0 0 

result:

ok single line: '0 6 0 0 '

Test #4:

score: 0
Accepted
time: 1ms
memory: 5644kb

input:

3 4
4 6 7
2 1 3 5

output:

0 60 0 0 0 0 0 

result:

ok single line: '0 60 0 0 0 0 0 '

Test #5:

score: -1
Wrong Answer
time: 1ms
memory: 5680kb

input:

10 10
13 18 7 4 15 1 10 12 5 8
17 20 14 3 16 9 6 2 19 11

output:

0 2509 516 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

wrong answer 1st lines differ - expected: '0 2741 284 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 2509 516 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #2:

score: 0
Wrong Answer

Test #10:

score: 0
Wrong Answer
time: 1ms
memory: 5656kb

input:

30 30
21 60 56 26 50 1 4 52 51 58 34 13 54 59 7 28 33 46 18 39 43 37 32 36 19 25 30 16 38 55
45 23 48 40 2 17 29 27 57 53 12 6 49 15 3 31 9 5 20 44 47 24 11 22 10 42 41 35 8 14

output:

0 125596 82439 8190 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

wrong answer 1st lines differ - expected: '0 149064 63399 3762 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 125596 82439 8190 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 1ms
memory: 5712kb

input:

100 100
3 185 115 158 149 111 166 94 76 141 167 193 49 11 95 99 97 89 191 98 32 8 20 170 179 63 190 50 4 16 70 75 169 125 178 198 5 71 30 12 128 6 107 62 90 116 39 173 133 31 139 162 144 195 28 160 23 53 55 78 182 153 114 157 46 92 188 43 177 192 124 150 79 146 80 102 7 77 18 82 165 17 15 197 119 14...

output:

0 15010057 8715165 1540667 236611 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 1st lines differ - expected: '0 16086875 8174944 1124681 116...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 15010057 8715165 1540667 236... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #4:

score: 0
Wrong Answer

Test #32:

score: 0
Wrong Answer
time: 0ms
memory: 5652kb

input:

300 300
97 322 293 313 283 13 27 353 474 32 562 75 10 317 136 482 81 309 584 138 437 48 159 339 334 356 526 357 1 352 235 242 456 461 219 66 436 565 559 284 112 20 111 23 384 51 514 134 462 124 400 261 216 76 171 202 239 238 333 179 545 527 407 539 418 588 248 440 427 376 549 15 411 355 299 365 9 12...

output:

0 233277326 647046521 120273727 37924919 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

wrong answer 1st lines differ - expected: '0 264114717 638832402 11062902...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 233277326 647046521 12027372... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #5:

score: 0
Wrong Answer

Test #43:

score: 0
Wrong Answer
time: 0ms
memory: 5772kb

input:

2000 2000
762 3148 1563 2539 1799 983 3993 1082 2912 3178 1908 2990 16 886 2973 823 913 243 357 850 2486 1588 2649 1893 1634 3691 150 996 3789 2922 2393 577 2316 924 3674 3636 910 2406 1483 1212 579 2442 1875 918 2039 928 2009 920 462 3898 1764 1592 1220 3893 1602 772 3485 1640 1940 2409 994 3201 62...

output:

0 116475537 148778315 746008670 367264786 622444678 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 1st lines differ - expected: '0 782741918 598044376 61117703...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 116475537 148778315 74600867... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #6:

score: 0
Wrong Answer

Test #55:

score: 0
Wrong Answer
time: 3ms
memory: 5776kb

input:

8000 8000
7244 4104 4116 4733 1865 12849 14465 11794 1095 7219 5206 2781 11617 6866 9595 11983 14469 13258 2346 10847 5429 3414 4293 15825 10314 9643 14412 9550 6406 7816 13719 15736 5333 15692 12756 4329 2709 5284 5261 1707 11238 4301 13797 2131 12768 7126 9864 3229 3785 4314 8719 1117 646 8153 111...

output:

0 310562093 577670025 159935278 163917577 40826560 755918689 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

wrong answer 1st lines differ - expected: '0 854868357 558678044 54893504...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 310562093 577670025 15993527... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #7:

score: 0
Wrong Answer

Test #68:

score: 0
Wrong Answer
time: 24ms
memory: 6832kb

input:

70000 70000
65040 83209 46810 43228 58294 97341 24577 26778 64585 34392 121492 59033 52566 63751 20036 135689 72762 109553 67967 51787 107523 120416 95354 49900 60667 110736 115814 16626 34683 37257 119483 91814 68147 131865 33293 114111 65264 122197 57479 111482 75492 84033 133075 73321 7539 47697 ...

output:

0 148894834 362913660 838073098 603684792 37703201 215030216 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

wrong answer 1st lines differ - expected: '0 729425865 587558587 73831827...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 148894834 362913660 83807309... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #8:

score: 0
Wrong Answer

Test #82:

score: 0
Wrong Answer
time: 47ms
memory: 8268kb

input:

150000 150000
58983 100778 109945 294477 253435 1447 4311 110912 171122 212851 165373 102223 98625 274188 43059 196284 13184 232675 189091 37409 150201 227081 221065 161136 37343 47901 56955 197030 149843 137335 85230 291418 55155 84454 284046 96806 7342 94155 189355 60618 87506 281679 180207 125356...

output:

0 204582422 782793403 937585797 935141032 743298956 859373189 357118338 855800565 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 1st lines differ - expected: '0 786272003 734025130 94449638...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 204582422 782793403 93758579... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #9:

score: 0
Wrong Answer

Test #97:

score: 0
Wrong Answer
time: 70ms
memory: 12320kb

input:

230000 230000
53349 24839 147164 179787 169500 138524 104308 71283 404918 183895 337401 419461 119619 389931 304997 360563 177306 435849 94845 192364 358356 159738 442086 88126 354608 167743 320160 221916 402274 207329 178240 316555 328700 13950 214332 286314 232082 56917 406912 123163 219788 153687...

output:

0 34421904 125573602 789597711 425339323 405079823 662381646 619737302 902818405 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

wrong answer 1st lines differ - expected: '0 63850664 776309140 993968860...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 34421904 125573602 789597711... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #10:

score: 0
Wrong Answer

Test #112:

score: 0
Wrong Answer
time: 97ms
memory: 11392kb

input:

300000 300000
416773 186118 31247 38672 389294 339767 320108 250609 228574 232436 344414 316497 334835 318936 3172 393368 210300 145194 50617 423649 504469 6918 54400 485308 99748 556889 171790 488017 290307 560629 126324 57741 457051 257487 336091 524134 571207 573790 18672 361275 414336 343166 314...

output:

0 564030291 317373774 547339338 936327121 768180118 319719645 497251857 455376955 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 1st lines differ - expected: '0 912421684 449987593 33461579...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 564030291 317373774 54733933... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '