QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#124312#2788. Horsesvalerikk#17 292ms62440kbC++172.2kb2023-07-14 16:47:272024-07-04 00:39:55

Judging History

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

  • [2024-07-04 00:39:55]
  • 评测
  • 测评结果:17
  • 用时:292ms
  • 内存:62440kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-14 16:47:27]
  • 提交

answer

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

using namespace std;

namespace {

typedef long long ll;

const int N = 5e5 + 7;
const ll md = 1e9 + 7;
const ll INF = 1e18;

ll mul(ll a, ll b) {
	return a <= INF / b ? a * b : INF;
}

int n;
int x[N], y[N];

struct node {
	ll pref, suf, prod, prodmd, ans;
	bool neut;
};

node merge(const node &l, const node &r) {
	if (l.neut) {
		return r;
	}
	if (r.neut) {
		return l;
	}
	node ret;
	ret.prod = mul(l.prod, r.prod);
	ret.prodmd = l.prodmd * r.prodmd % md;
	ret.pref = max(l.pref, mul(r.pref, l.prod));
	ret.suf = max(r.suf, mul(l.suf, r.prod));
	ret.ans = max({l.ans, r.ans, mul(l.suf, r.pref)});
	ret.neut = 0;
	return ret;
}

node t[4 * N];

void build(int v, int tl, int tr) {
	if (tr - tl == 1) {
		t[v].pref = mul(x[tl], y[tl]);
		t[v].suf = x[tl];
		t[v].prod = x[tl];
		t[v].prodmd = x[tl];
		t[v].ans = mul(x[tl], y[tl]);
		t[v].neut = 0;
		return;
	}
	int tm = (tl + tr) / 2;
	build(2 * v, tl, tm);
	build(2 * v + 1, tm, tr);
	t[v] = merge(t[2 * v], t[2 * v + 1]);
}

void upd(int v, int tl, int tr, int pos) {
	if (tr - tl == 1) {
		t[v].pref = mul(x[tl], y[tl]);
		t[v].suf = x[tl];
		t[v].prod = x[tl];
		t[v].prodmd = x[tl];
		t[v].ans = mul(x[tl], y[tl]);
		return;		
	}
	int tm = (tl + tr) / 2;
	if (pos < tm) {
		upd(2 * v, tl, tm, pos);
	} else {
		upd(2 * v + 1, tm, tr, pos);
	}
	t[v] = merge(t[2 * v], t[2 * v + 1]);
}

node get(int v, int tl, int tr, int l, int r) {
	if (tl >= r || tr <= l) {
		return {1, 1, 1, 1, 1, 1};
	}
	if (tl >= l && tr <= r) {
		return t[v];
	}
	int tm = (tl + tr) / 2;
	return merge(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm, tr, l, r));
}	

ll getans() {
	int l = -1, r = n;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		if (get(1, 0, n, mid, n).prod == INF) {
			l = mid;
		} else {
			r = mid;
		}
	}
	return get(1, 0, n, r, n).ans % md * get(1, 0, n, 0, r).prodmd % md;
}

}

int init(int grdn, int grdx[], int grdy[]) {
	n = grdn;
	for (int i = 0; i < n; ++i) {
		x[i] = grdx[i];
		y[i] = grdy[i];
	}
	build(1, 0, n);
	return getans();
}

int updateX(int pos, int val) {
	x[pos] = val;
	upd(1, 0, n, pos);
	return getans();
}

int updateY(int pos, int val) {
	y[pos] = val;
	upd(1, 0, n, pos);
	return getans();
}

詳細信息

Subtask #1:

score: 17
Accepted

Test #1:

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

input:

1
2
3
0

output:

6

result:

ok single line: '6'

Test #2:

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

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

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

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

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

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

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

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

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

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

input:

2
2 5
9 7
0

output:

70

result:

ok single line: '70'

Test #12:

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

input:

1
1
1
0

output:

1

result:

ok single line: '1'

Test #13:

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

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

input:

1
10
10
0

output:

100

result:

ok single line: '100'

Test #15:

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

input:

2
1 4
7 2
0

output:

8

result:

ok single line: '8'

Test #16:

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

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

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

input:

4
1 2 4 8
8 4 2 1
0

output:

64

result:

ok single line: '64'

Test #19:

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

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

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

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
4900000

result:

wrong answer 6th lines differ - expected: '75803567', found: '4900000'

Subtask #3:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 292ms
memory: 62440kb

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
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
770467851
...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%