QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#473598#8527. Power DivisionsGenshinImpactsFaultTL 1477ms53252kbC++142.6kb2024-07-12 11:09:452024-07-12 11:09:45

Judging History

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

  • [2024-07-12 11:09:45]
  • 评测
  • 测评结果:TL
  • 用时:1477ms
  • 内存:53252kb
  • [2024-07-12 11:09:45]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
typedef long long ll;
const int N = 1000040;
const int mod = 1e9 + 7;
const int mod1 = 1e9 + 7, mod2 = 1e9 + 9;
int n, a[N];
int ba1[N], ba2[N];
int sum1[N], sum2[N];
int st[N][19], lg[N];
int f[N];
vector<int> t[N];
int stal[N], topl;
int star[N], topr;
map<ll, int> ma;

int find_max(int l, int r) {
	int k = lg[r - l + 1];
	int x = st[l][k], y = st[r - (1 << k) + 1][k];
	return max(a[x], a[y]);
}
void solve(int l, int r) {
	if(l >= r) {
		t[r].push_back(l - 1);
		return ;
	}
	int mid = (l + r) >> 1;
	solve(l, mid), solve(mid + 1, r);
	int mx = 0;
	for(int i = mid; i >= l; i--) {
		mx = max(mx, a[i]);
		for(int j = 1; j <= 18; j++) {
			int s1 = (sum1[i - 1] + ba1[mx + j]) % mod1;
			int s2 = (sum2[i - 1] + ba2[mx + j]) % mod2;
			if(ma.find(1ll * s1 * mod2 + s2) == ma.end()) continue;
			int x = ma[1ll * s1 * mod2 + s2];
			if(x <= mid || x > r) continue;
			int tmp = find_max(i, x);
			if(tmp != mx) continue;
			t[x].push_back(i - 1);
		}
	}
	mx = 0;
	for(int i = mid + 1; i <= r; i++) {
		mx = max(mx, a[i]);
		for(int j = 1; j <= 18; j++) {
			int s1 = (sum1[i] - ba1[mx + j] + mod1) % mod1;
			int s2 = (sum2[i] - ba2[mx + j] + mod2) % mod2;
			if(ma.find(1ll * s1 * mod2 + s2) == ma.end()) continue;
			int x = ma[1ll * s1 * mod2 + s2];
			if(x >= mid || x < l - 1) continue;
			int tmp = find_max(x + 1, i);
			if(tmp != mx) continue;
			t[i].push_back(x);
		}
	}
}
int main() {
	// freopen("K.in", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(nullptr);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	lg[0] = -1;
	for(int i = 1; i <= n; i++) lg[i] = lg[i >> 1] + 1;
	for(int i = 1; i <= n; i++) st[i][0] = i;
	for(int j = 1; (1 << j) <= n; j++)
		for(int i = 1; i + (1 << j) - 1 <= n; i++) {
			if(a[st[i][j - 1]] > a[st[i + (1 << (j - 1))][j - 1]])
				st[i][j] = st[i][j - 1];
			else st[i][j] = st[i + (1 << (j - 1))][j - 1];
		}
	ba1[0] = ba2[0] = 1;
	for(int i = 1; i <= 1000020; i++) {
		ba1[i] = 1ll * ba1[i - 1] * 2 % mod1;
		ba2[i] = 1ll * ba2[i - 1] * 2 % mod2;
	}
	for(int i = 1; i <= n; i++) {
		sum1[i] = (sum1[i - 1] + ba1[a[i]]) % mod1;
		sum2[i] = (sum2[i - 1] + ba2[a[i]]) % mod2;
	}
	for(int i = 0; i <= n; i++) {
		ma[1ll * sum1[i] * mod2 + sum2[i]] = i;
	}
	solve(1, n);
	f[0] = 1;
	for(int i = 1; i <= n; i++) {
		sort(t[i].begin(), t[i].end());
		t[i].resize(unique(t[i].begin(), t[i].end()) - t[i].begin());
		// for(auto v : t[i]) cout << v + 1 << " " << i << "\n";
		for(auto v : t[i]) f[i] = (f[i] + f[v]) % mod;
	}
	cout << f[n] << "\n";
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 6ms
memory: 44624kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 6ms
memory: 36824kb

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 7ms
memory: 42616kb

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 12ms
memory: 42552kb

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 3ms
memory: 42492kb

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 3ms
memory: 42552kb

input:

7
3 4 3 5 6 3 4

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 4ms
memory: 42484kb

input:

10
8 6 5 6 7 8 6 8 9 9

output:

4

result:

ok 1 number(s): "4"

Test #9:

score: 0
Accepted
time: 11ms
memory: 42556kb

input:

96
5 1 0 2 5 5 2 4 2 4 4 2 3 4 0 2 1 4 3 1 2 0 2 2 3 2 4 5 3 5 2 0 2 2 5 3 0 4 5 3 5 4 4 3 1 2 0 5 4 5 0 2 3 2 4 0 0 4 2 0 2 5 3 3 1 5 5 1 1 1 0 5 0 3 0 2 1 1 0 5 0 3 3 4 4 5 3 0 2 2 0 5 4 5 0 5

output:

11332014

result:

ok 1 number(s): "11332014"

Test #10:

score: 0
Accepted
time: 6ms
memory: 42544kb

input:

480
2 0 4 4 1 0 0 3 1 1 4 2 5 5 4 2 1 2 4 4 1 3 4 3 0 5 2 0 2 5 1 0 5 0 0 5 5 0 2 5 2 2 3 1 4 3 5 4 5 2 4 4 4 4 1 4 0 3 4 3 4 1 0 4 3 4 5 4 3 5 0 2 2 0 1 5 4 4 2 0 3 3 3 4 3 0 5 5 3 1 5 1 0 1 0 4 3 0 5 1 4 1 4 3 0 1 3 5 0 3 3 1 0 4 1 1 2 0 1 2 0 3 5 2 0 5 5 5 5 3 5 1 0 2 5 2 2 0 2 0 2 3 5 1 2 1 5 4 ...

output:

506782981

result:

ok 1 number(s): "506782981"

Test #11:

score: 0
Accepted
time: 23ms
memory: 42768kb

input:

2400
0 2 2 0 5 4 3 2 3 2 5 4 5 4 4 5 2 2 4 2 2 0 1 0 5 0 4 4 0 0 5 0 4 0 1 3 4 5 0 3 1 0 4 0 2 5 0 3 3 3 3 1 0 5 5 3 1 3 5 2 4 0 5 0 4 5 4 2 2 1 5 2 2 4 1 0 5 1 5 0 1 2 0 0 3 5 4 0 0 1 1 1 4 2 0 5 1 3 3 5 0 4 4 1 5 5 3 4 4 4 0 2 4 0 5 1 3 1 5 0 5 5 1 3 0 3 1 2 0 1 1 3 5 2 3 4 0 3 0 5 4 0 4 3 5 0 5 2...

output:

586570528

result:

ok 1 number(s): "586570528"

Test #12:

score: 0
Accepted
time: 178ms
memory: 45976kb

input:

12000
2 2 1 2 0 2 5 3 2 0 1 3 2 5 4 0 0 5 3 2 0 2 3 4 3 2 1 4 3 0 3 5 4 1 0 2 4 1 3 2 3 5 0 3 0 0 4 0 4 5 1 0 4 1 1 1 5 4 3 0 3 5 4 5 2 5 0 1 2 3 5 5 2 5 4 2 0 4 4 3 0 0 2 5 0 3 4 2 5 4 2 1 4 5 1 1 2 3 0 3 3 3 3 4 0 5 3 4 0 3 0 2 0 0 2 0 3 4 2 2 0 1 0 5 3 0 2 0 2 2 1 0 5 3 5 4 5 5 0 4 0 4 1 4 4 3 2 ...

output:

201653965

result:

ok 1 number(s): "201653965"

Test #13:

score: 0
Accepted
time: 1477ms
memory: 53252kb

input:

60000
2 5 0 3 2 3 5 3 5 5 4 1 1 5 3 0 1 1 2 5 5 5 0 3 2 0 3 2 3 3 0 0 1 4 3 1 4 2 3 3 0 5 1 0 1 1 5 5 4 0 5 4 1 3 1 3 5 3 2 4 4 4 5 4 3 2 3 2 4 5 2 0 4 5 1 2 0 4 0 5 1 3 4 1 2 4 1 1 3 3 0 1 1 3 0 0 2 3 3 2 1 4 1 2 4 3 3 5 2 5 3 4 3 0 2 1 1 1 5 1 2 4 2 3 1 2 1 0 2 0 1 1 5 5 3 4 2 5 2 4 5 3 0 5 1 4 2 ...

output:

592751350

result:

ok 1 number(s): "592751350"

Test #14:

score: -100
Time Limit Exceeded

input:

300000
0 5 1 5 5 4 5 3 0 5 0 5 1 4 1 2 2 2 3 0 1 5 4 0 3 1 4 5 2 1 0 3 2 1 2 5 0 2 4 5 0 1 2 1 1 0 0 5 3 0 0 3 4 5 0 2 1 1 1 2 5 1 4 3 1 0 2 0 0 4 3 3 2 5 3 3 1 5 2 0 2 4 3 1 0 3 4 1 3 3 1 0 0 1 1 1 3 1 2 3 5 3 3 2 0 3 0 0 5 5 0 0 0 0 1 4 3 3 4 3 4 5 3 3 5 1 1 4 2 2 1 3 2 1 1 0 0 5 5 0 0 3 2 4 5 5 2...

output:


result: