QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#233861#2788. HorsesCamillus#0 1248ms42924kbC++203.7kb2023-11-01 01:46:472024-07-04 02:50:52

Judging History

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

  • [2024-07-04 02:50:52]
  • 评测
  • 测评结果:0
  • 用时:1248ms
  • 内存:42924kb
  • [2023-11-01 01:46:47]
  • 提交

answer

#pragma GCC optimize("Ofast")
#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;

constexpr int maxn = 1 << 19; 

int X[maxn];
int Y[maxn];

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

	void set(int i) {
		int x = maxn + i - 1;
		tree[x] = i;

		while (x) {
			x = (x - 1) / 2;
			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 st2 {
	mint tree[maxn * 2 - 1];

	void set(int i, int v) {
		int x = maxn + i - 1;
		tree[x] = v;

		while (x) {
			x = (x - 1) / 2;
			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

constexpr i128 INF = 1ll * mint::mod * mint::mod;

set<pair<int, int>> Q;

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

	{
		i128 cur = 1;

		for (auto it = prev(Q.end()); ; it--) {
			int r = it->first;

			cur *= X[r];

			if (cur > INF) {
				break;
			} else {
				q.emplace_back(*it);
			}

			if (it == Q.begin()) {
				break;
			}
		}
	}

	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 updateX(int pos, int val) {	
	if (X[pos] == val) {
		return calc();
	}

	if (X[pos] == 1 && pos != 0) {
		auto it = prev(Q.lower_bound(make_pair(pos, 0)));

		int r = (next(it) == Q.end() ? n : next(it)->first);
		
		int l1 = pos;
		int l2 = it->first;

		Q.erase(it);

		Q.emplace(l1, st0::get(l1, r));
		Q.emplace(l2, st0::get(l2, l1));
	} else if (val == 1 && pos != 0) {
		auto it = Q.lower_bound(make_pair(pos, 0));

		int i1 = it->second;
		int i2 = prev(it)->second;

		int i = (Y[i1] > Y[i2] ? i1 : i2);

		int l = prev(it)->first;

		Q.erase(prev(it));
		Q.erase(it);

		Q.emplace(l, i);
	}

	X[pos] = val;

	st2::set(pos, val);

	return calc();
}

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

	auto it = Q.upper_bound(make_pair(pos, 0));

	int R = (it == Q.end() ? n : it->first);

	it = prev(it);

	Q.emplace(it->first, st0::get(it->first, R));
	Q.erase(it);

	return calc();
}

int init(int N, int _X[], int _Y[]) {
	n = N;

	Q.emplace(0, max_element(_Y, _Y + n) - _Y);

	for (int i = 0; i < n; i++) {
		X[i] = 1;
	}

	for (int i = 0; i < n; i++) {
		updateX(i, _X[i]);
		Y[i] = _Y[i];
	}

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

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

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

input:

1
2
3
0

output:

6

result:

ok single line: '6'

Test #2:

score: -17
Wrong Answer
time: 1ms
memory: 5880kb

input:

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

output:

6

result:

wrong answer 1st lines differ - expected: '10000', found: '6'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 1248ms
memory: 42924kb

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:

2
2
795463654
885679347
618832158
501991144
795463654
885679347
618832158
501991144
864166718
864166718
864166718
864166718
864166718
813424701
813424701
813424701
813424701
813424701
815547130
815547130
815547130
815547130
815547130
715585103
715585103
715585103
715585103
715585103
335613627
335613...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%