QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#233844#2788. HorsesCamillus#37 871ms24732kbC++204.3kb2023-11-01 00:54:112024-07-04 02:22:30

Judging History

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

  • [2024-07-04 02:22:30]
  • 评测
  • 测评结果:37
  • 用时:871ms
  • 内存:24732kb
  • [2023-11-01 00:54:11]
  • 提交

answer

#pragma GCC optimize("O3")
#include "horses.h"
#include "bits/stdc++.h"

using ll = long long;
using i128 = __int128;
using namespace std;

struct mint {
	static constexpr int mod = 1e9 + 7;

	int data = 0;

	mint() = default;
	mint(int data) : data(data) {}

	mint operator+(const mint &other) const {
		int res = data + other.data;
		if (res >= mod) {
			res -= mod;
		}
		return res;
	}

	mint operator-(const mint &other) const {
		int res = data + mod - other.data;
		if (res >= mod) {
			res -= mod;
		}
		return res;
	}

	mint operator*(const mint &other) const {
		return mint(1ll * data * other.data % mod);
	}
};

int n;
vector<int> X, Y;

constexpr int maxn = 1 << 19; 

namespace st0 {
	int tree[maxn * 2 - 1];

	void set(int i, int x = 0, int lx = 0, int rx = maxn) {
		if (rx - lx == 1) {
			tree[x] = i;
			return;
		}

		int mx = (lx + rx) / 2;

		if (i < mx) {
			set(i, x * 2 + 1, lx, mx);
		} else {
			set(i, x * 2 + 2, mx, rx);
		}

		if (Y[tree[x * 2 + 1]] > Y[tree[x * 2 + 2]]) {
			tree[x] = tree[x * 2 + 1];
		} else {
			tree[x] = tree[x * 2 + 2];
		}
	}

	int get(int l, int r, int x = 0, int lx = 0, int rx = maxn) {
		// int res = n;
		// for (int i = l; i < r; i++) {
		// 	if (Y[res] < Y[i]) {
		// 		res = i;
		// 	}
		// }
		// return res;
		if (l <= lx && rx <= r) {
			return tree[x];
		}

		if (l >= rx || lx >= r) {
			return n;
		}

		int mx = (lx + rx) / 2;

		int i = get(l, r, x * 2 + 1, lx, mx);
		int j = get(l, r, x * 2 + 2, mx, rx);

		if (Y[i] > Y[j]) {
			return i;
		} else {
			return j;
		}
	}
} // namespace st0

namespace st1 {
	int tree[maxn * 2 - 1];

	void set(int i, int v, int x = 0, int lx = 0, int rx = maxn) {
		if (rx - lx == 1) {
			tree[x] = v;
			return;
		}

		int mx = (lx + rx) / 2;

		if (i < mx) {
			set(i, v, x * 2 + 1, lx, mx);
		} else {
			set(i, v, x * 2 + 2, mx, rx);
		}

		tree[x] = max(tree[x * 2 + 1], tree[x * 2 + 2]);
	}

	int get(int l, int r, int x = 0, int lx = 0, int rx = maxn) {
		if (l <= lx && rx <= r) {
			return tree[x];
		}

		if (l >= rx || lx >= r) {
			return 1;
		}
		
		return max(
			get(l, r, x * 2 + 1, lx, (lx + rx) / 2),
			get(l, r, x * 2 + 2, (lx + rx) / 2, rx)
		);
	}
} // namespace st1

namespace st2 {
	mint tree[maxn * 2 - 1];

	void set(int i, int v, int x = 0, int lx = 0, int rx = maxn) {
		if (rx - lx == 1) {
			tree[x] = v;
			return;
		}

		int mx = (lx + rx) / 2;
		
		if (i < mx) {
			set(i, v, x * 2 + 1, lx, mx);
		} else {
			set(i, v, x * 2 + 2, mx, rx);
		}

		tree[x] = tree[x * 2 + 1] * tree[x * 2 + 2];
	}

	mint get(int l, int r, int x = 0, int lx = 0, int rx = maxn) {
		if (l <= lx && rx <= r) {
			return tree[x];
		}

		if (l >= rx || lx >= r) {
			return 1;
		}

		return get(l, r, x * 2 + 1, lx, (lx + rx) / 2) * get(l, r, x * 2 + 2, (lx + rx) / 2, rx);
	}
} // namespace st2

int calc() {
	vector<pair<int, int>> q;

	{
		i128 cur = 1;

		for (int r = n - 1; r >= 0;) {
			int R = r + 1;

			for (int j = 19; r >= 0 && j >= 0 && X[r] == 1; j--) {
				if (R - (1 << j) >= 0 && st1::get(r - (1 << j) + 1, R) == 1) {
					r -= (1 << j);
				}
			}

			if (r == -1) {
				r = 0;
			}

			// if (X[r] == 1) {
			// 	int LL = 0;
			// 	int RR = r;

			// 	while (RR - LL > 1) {
			// 		int M = (LL + RR) / 2;
					
			// 		if (st1::get(M, R) == 1) {
			// 			RR = M;
			// 		} else {
			// 			LL = M;
			// 		}
			// 	}

			// 	r = LL;
			// }

			cur *= X[r];

			if (cur > 1e18) {
				break;
			} else {
				q.emplace_back(r, st0::get(r, R));
			}

			r--;
		}
	}

	reverse(q.begin(), q.end());

	vector<pair<i128, int>> v;
	for (i128 cur = 1; auto [a, b] : q) {
		cur *= X[a];
		v.emplace_back(cur * Y[b], b);
	}

	int pos = max_element(v.begin(), v.end())->second;

	return (st2::get(0, pos + 1) * Y[pos]).data;
}

int init(int N, int _X[], int _Y[]) {
	n = N;
	
	X = vector<int>(_X, _X + n);
	Y = vector<int>(_Y, _Y + n);
	Y.push_back(0);

	for (int i = 0; i < n; i++) {
		st0::set(i);

		st1::set(i, X[i]);
		st2::set(i, X[i]);
	}

	return calc();
}

int updateX(int pos, int val) {	
	X[pos] = val;

	st1::set(pos, val);
	st2::set(pos, val);

	return calc();
}

int updateY(int pos, int val) {
	Y[pos] = val;
	
	st0::set(pos);

	return calc();
}

詳細信息

Subtask #1:

score: 17
Accepted

Test #1:

score: 17
Accepted
time: 3ms
memory: 14076kb

input:

1
2
3
0

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 3ms
memory: 14384kb

input:

10
2 1 1 5 2 1 1 10 5 1
3 5 7 9 4 1 4 10 10 9
0

output:

10000

result:

ok single line: '10000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 14016kb

input:

10
10 10 10 1 1 1 1 1 1 1
2 3 4 2 7 6 5 4 3 2
0

output:

7000

result:

ok single line: '7000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 14380kb

input:

10
9 1 1 1 1 1 1 1 1 2
4 1 1 1 1 1 1 1 1 2
0

output:

36

result:

ok single line: '36'

Test #5:

score: 0
Accepted
time: 0ms
memory: 14032kb

input:

10
1 1 1 1 1 1 1 1 1 1
1 2 3 4 5 6 7 8 9 10
0

output:

10

result:

ok single line: '10'

Test #6:

score: 0
Accepted
time: 0ms
memory: 14308kb

input:

10
1 1 1 1 1 1 1 1 1 1
10 9 8 7 6 5 4 3 2 1
0

output:

10

result:

ok single line: '10'

Test #7:

score: 0
Accepted
time: 0ms
memory: 14256kb

input:

10
10 10 10 1 1 1 1 1 1 1
10 10 2 3 4 5 6 7 8 9
0

output:

9000

result:

ok single line: '9000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 14036kb

input:

10
10 10 10 1 1 1 1 1 1 1
10 10 9 8 7 6 5 4 3 2
0

output:

9000

result:

ok single line: '9000'

Test #9:

score: 0
Accepted
time: 0ms
memory: 14272kb

input:

10
1 1 1 1 2 2 1 1 1 1
8 8 8 8 1 1 2 2 2 2
0

output:

8

result:

ok single line: '8'

Test #10:

score: 0
Accepted
time: 0ms
memory: 14076kb

input:

10
1 1 1 1 1 1 1 1 1 1
1 2 3 4 5 9 8 7 6 1
0

output:

9

result:

ok single line: '9'

Test #11:

score: 0
Accepted
time: 0ms
memory: 13956kb

input:

2
2 5
9 7
0

output:

70

result:

ok single line: '70'

Test #12:

score: 0
Accepted
time: 0ms
memory: 14388kb

input:

1
1
1
0

output:

1

result:

ok single line: '1'

Test #13:

score: 0
Accepted
time: 0ms
memory: 14312kb

input:

7
7 1 1 6 2 3 2
7 6 5 4 3 7 1
0

output:

1764

result:

ok single line: '1764'

Test #14:

score: 0
Accepted
time: 0ms
memory: 13956kb

input:

1
10
10
0

output:

100

result:

ok single line: '100'

Test #15:

score: 0
Accepted
time: 2ms
memory: 14312kb

input:

2
1 4
7 2
0

output:

8

result:

ok single line: '8'

Test #16:

score: 0
Accepted
time: 2ms
memory: 14288kb

input:

10
1 10 1 10 1 1 10 1 1 1
7 3 10 10 4 10 1 4 5 10
0

output:

10000

result:

ok single line: '10000'

Test #17:

score: 0
Accepted
time: 3ms
memory: 14380kb

input:

6
1 1 1 1 1 1
1 1 1 1 1 1
0

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 3ms
memory: 14276kb

input:

4
1 2 4 8
8 4 2 1
0

output:

64

result:

ok single line: '64'

Test #19:

score: 0
Accepted
time: 3ms
memory: 14008kb

input:

6
1 2 2 3 1 1
7 1 1 2 1 1
0

output:

24

result:

ok single line: '24'

Test #20:

score: 0
Accepted
time: 3ms
memory: 14308kb

input:

10
2 1 1 5 2 1 1 10 5 1
3 5 7 9 4 1 4 10 7 9
0

output:

9000

result:

ok single line: '9000'

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #21:

score: 17
Accepted
time: 0ms
memory: 14136kb

input:

10
10 10 10 10 10 10 1 1 1 1
1 1 1 1 9 5 4 7 3 2
5
1 5 1
2 5 123456789
1 5 1
1 8 987654321
1 9 777777777

output:

7000000
900000
678813585
678813585
294225928
75803567

result:

ok 6 lines

Test #22:

score: 0
Accepted
time: 2ms
memory: 14024kb

input:

10
3 2 7 5 11 13 107 23 51 3
1 1 1 1 1000000000 1 1 1 1 1
16
1 1 1
1 2 1
1 0 1
1 8 1
1 7 1
1 9 1
1 1 25
1 8 123456789
1 4 1
1 6 1
1 3 1
1 5 1
1 5 12345
1 6 123456
1 7 1234567
2 4 3

output:

999983837
999991922
999998852
999999622
999999622
999999622
999999622
999990382
539408243
49037113
617280725
123456145
999999832
851238418
489396978
354709175
354709175

result:

ok 17 lines

Test #23:

score: 0
Accepted
time: 7ms
memory: 14052kb

input:

1000
179278145 423054674 671968267 409599985 828900464 393298292 569389961 360810107 205374067 618910650 76768983 62623743 225944805 498579132 917750714 600860488 642568763 21949846 852642376 283772010 299085842 669257630 544180666 249770466 320727298 612199337 15873453 726595389 219129403 876893450...

output:

394559852
394559852
394559852
394559852
868802752
868802752
868802752
868802752
165967503
244287754
244287754
270995710
270995710
270995710
247981131
247981131
237849527
24662481
24662481
451435926
989677577
989677577
704081481
704081481
704081481
704081481
704081481
631761803
631761803
631761803
80...

result:

ok 1001 lines

Test #24:

score: 0
Accepted
time: 0ms
memory: 14036kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

858314903
362189740
362189740
362189740
362189740
362189740
347762296
347762296
347762296
347762296
347762296
347762296
297139175
297139175
56337247
56337247
56337247
919555391
919555391
223551221
223551221
223551221
674943421
674943421
674943421
674943421
674943421
160231649
160231649
242692758
242...

result:

ok 1001 lines

Test #25:

score: 0
Accepted
time: 6ms
memory: 14092kb

input:

1000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...

output:

426490853
426490853
426490853
426490853
224787023
224787023
110744712
110744712
110744712
682644373
841322190
841322190
594096835
973115198
7681374
712091041
712091041
712091041
712091041
712091041
712091041
712091041
326844140
326844140
163422070
326844140
326844140
326844140
163422070
163422070
16...

result:

ok 1001 lines

Test #26:

score: 0
Accepted
time: 0ms
memory: 14052kb

input:

1000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...

output:

426490853
224787023
110744712
110744712
110744712
110744712
110744712
110744712
110744712
110744712
841322190
188193663
188193663
973115198
973115198
486557599
486557599
486557599
501920347
501920347
214011381
214011381
214011381
214011381
214011381
214011381
214011381
214011381
540855521
81711035
8...

result:

ok 1001 lines

Test #27:

score: -17
Wrong Answer
time: 36ms
memory: 14040kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1
111838200
2
2
2
4
4
8
8
8
8
8
8
8
8
8
8
16
16
16
16
16
32
64
128
256
256
256
256
128
256
256
512
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
485985717
485985717
485985717
4...

result:

wrong answer 3rd lines differ - expected: '111838200', found: '2'

Subtask #3:

score: 20
Accepted

Test #33:

score: 20
Accepted
time: 871ms
memory: 24352kb

input:

500000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...

output:

967631222
967631222
795463654
885679347
618832158
618832158
618832158
618832158
618832158
582471866
864166718
864166718
864166718
864166718
864166718
813424701
813424701
813424701
813424701
813424701
815547130
815547130
815547130
815547130
815547130
715585103
715585103
715585103
715585103
715585103
...

result:

ok 100001 lines

Test #34:

score: 0
Accepted
time: 274ms
memory: 24668kb

input:

500000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000...

output:

764523385
560650427
560650427
711685442
711685442
711685442
630166054
630166054
630166054
604940491
56866480
384893091
501798659
560422885
560422885
18199764
63591615
212319888
212319888
39499230
828983454
828983454
634555752
4896305
181214713
231675794
231675794
966365836
181367397
181367397
987190...

result:

ok 100001 lines

Test #35:

score: 0
Accepted
time: 336ms
memory: 23308kb

input:

500000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...

output:

967631222
192947708
884245369
884245369
884245369
884245369
884245369
649885822
981487169
321173457
159089267
159089267
159089267
747556995
964496384
964496384
964496384
928334020
928334020
928334020
928334020
459124375
459124375
404955269
251629123
80789828
80789828
463250667
463250667
120836466
57...

result:

ok 100001 lines

Test #36:

score: 0
Accepted
time: 595ms
memory: 24732kb

input:

500000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...

output:

628833504
223286077
463897870
972304401
127408916
377483838
722400213
221924185
818717195
473021697
502484429
318341012
230123148
522240493
607202268
818940989
569566927
384659940
448632730
578079312
667605482
963648869
939506632
965323855
498894254
695643284
699407581
168605135
70361400
795950777
1...

result:

ok 100001 lines

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%