QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#233866#2788. HorsesCamillus#17 1236ms43552kbC++203.7kb2023-11-01 01:54:392024-07-04 02:50:57

Judging History

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

  • [2024-07-04 02:50:57]
  • 评测
  • 测评结果:17
  • 用时:1236ms
  • 内存:43552kb
  • [2023-11-01 01:54:39]
  • 提交

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.lower_bound(make_pair(pos + 1, 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;

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

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

	Q.emplace(0, st0::get(0, n));

	for (int i = 0; i < n; i++) {
		updateX(i, _X[i]);
		st2::set(i, X[i]);
	}

	return calc();
}

详细

Subtask #1:

score: 17
Accepted

Test #1:

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

input:

1
2
3
0

output:

6

result:

ok single line: '6'

Test #2:

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

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: 2ms
memory: 12312kb

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: 1ms
memory: 11972kb

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

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: 2ms
memory: 12012kb

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: 2ms
memory: 12316kb

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

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: 2ms
memory: 11972kb

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

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: 2ms
memory: 11952kb

input:

2
2 5
9 7
0

output:

70

result:

ok single line: '70'

Test #12:

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

input:

1
1
1
0

output:

1

result:

ok single line: '1'

Test #13:

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

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

input:

1
10
10
0

output:

100

result:

ok single line: '100'

Test #15:

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

input:

2
1 4
7 2
0

output:

8

result:

ok single line: '8'

Test #16:

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

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: 0ms
memory: 11904kb

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: 1ms
memory: 11968kb

input:

4
1 2 4 8
8 4 2 1
0

output:

64

result:

ok single line: '64'

Test #19:

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

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: 1ms
memory: 12036kb

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
Runtime Error

Dependency #1:

100%
Accepted

Test #21:

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

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: 0ms
memory: 11940kb

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: -17
Runtime Error

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:

Unauthorized output

result:


Subtask #3:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 1236ms
memory: 43552kb

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
967631222
967631222
967631222
967631222
795463654
885679347
618832158
967631222
864166718
616649396
967631222
616649396
967631222
616649396
813424701
967631222
813424701
59958004
967631222
59958004
967631222
59958004
967631222
384797334
967631222
384797334
967631222
366790562
335...

result:

wrong answer 3rd lines differ - expected: '795463654', found: '967631222'

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%