QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#233829#2788. HorsesCamillus#20 332ms23340kbC++203.9kb2023-11-01 00:33:432024-07-04 02:22:14

Judging History

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

  • [2024-07-04 02:22:14]
  • 评测
  • 测评结果:20
  • 用时:332ms
  • 内存:23340kb
  • [2023-11-01 00:33:43]
  • 提交

answer

#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] = lx;
			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) {
		if (l <= lx && rx <= r) {
			return tree[x];
		}

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

		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 INT32_MIN;
		}
		
		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 = 17; r >= 0 && j >= 0 && x[r] == 1; j--) {
				if (R - (1 << j) >= 0 && st1::get(R - (1 << j), R) == 1) {
					r -= (1 << j);
				}
			}

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

			cur *= x[r];

			if (cur > 1e18) {
				break;
			} else {
				q.emplace_back(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);

	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: 0
Wrong Answer

Test #1:

score: 17
Accepted
time: 2ms
memory: 11892kb

input:

1
2
3
0

output:

6

result:

ok single line: '6'

Test #2:

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

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
Wrong Answer
time: 0ms
memory: 5840kb

input:

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

output:

4000

result:

wrong answer 1st lines differ - expected: '7000', found: '4000'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 20
Accepted

Test #33:

score: 20
Accepted
time: 313ms
memory: 22920kb

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: 20
Accepted
time: 269ms
memory: 22992kb

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: 20
Accepted
time: 267ms
memory: 23280kb

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: 20
Accepted
time: 332ms
memory: 23340kb

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:

0%