QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#233812#2788. HorsesCamillus#0 170ms14104kbC++203.7kb2023-10-31 23:59:102024-07-04 02:22:09

Judging History

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

  • [2024-07-04 02:22:09]
  • 评测
  • 测评结果:0
  • 用时:170ms
  • 内存:14104kb
  • [2023-10-31 23:59:10]
  • 提交

answer

#include "horses.h"
#include "bits/stdc++.h"

using ll = long long;
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 << 17; 

namespace st0 {
	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 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;

	{
		ll cur = 1;

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

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

			cur *= x[r];

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

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

	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, y[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, val);

	return calc();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 17
Accepted
time: 1ms
memory: 3876kb

input:

1
2
3
0

output:

6

result:

ok single line: '6'

Test #2:

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

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: 3876kb

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

Test #33:

score: 0
Wrong Answer
time: 170ms
memory: 14104kb

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:

125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
125655169
...

result:

wrong answer 1st lines differ - expected: '967631222', found: '125655169'

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%