QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375466#8527. Power Divisionsucup-team1209#WA 26ms47008kbC++201.9kb2024-04-03 11:09:272024-04-03 11:09:27

Judging History

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

  • [2024-04-03 11:09:27]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:47008kb
  • [2024-04-03 11:09:27]
  • 提交

answer

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using ll = long long;
const ll mod = 986854057502126921;
const int N = 300005;
const int M = 1e6 + 100;
int n;
ll pw[M];
ll a[N], s[N];
std::unordered_map<ll, int> map(N * 2);

int st[20][N];
int max(int x, int y) {
	return a[x] < a[y] ? x : y;
}
int qmax(int l, int r) {
	const int lg = std::__lg(r - l + 1);
	return max(st[lg][l], st[lg][r - (1 << lg) + 1]);
}
std::vector<int> e[N];

const int V = 19;
void solve(int l, int r) {
	if(l > r) return ;
	int m = qmax(l, r);
	const int vm = a[m];
	solve(l, m - 1);
	solve(m + 1, r);
	if(m - l < r - m) {
		for(int i = l;i <= m;++i) {
			for(int p = vm;p < vm + V;++p) {
				ll sum = s[i - 1] + pw[p];
				if(sum >= mod) sum -= mod;
				auto iter = map.find(sum);
				if(iter != map.end()) {
					if(int p = iter -> second;m <= p && p <= r) {
						e[p].push_back(i - 1);
					}
				}
			}
		}
	} else {
		for(int i = m;i <= r;++i) {
			for(int p = vm;p < vm + V;++p) {
				ll sum = s[i] - pw[p];
				if(sum < 0) sum += mod;
				auto iter = map.find(sum);
				if(iter != map.end()) {
					if(int p = iter -> second;l - 1 <= p && p < m) {
						e[i].push_back(p);
					}
				}
			}
		}
	}
}
void pengbo() {
	const int mod = 1e9 + 7;
	std::vector<int> dp(n + 1);
	dp[0] = 1;
	for(int i = 1;i <= n;++i) {
		for(int z : e[i]) {
			dp[i] = (dp[i] + dp[z]) % mod;
		}
	}
	cout << dp[n] << '\n';
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	*pw = 1;
	for(int i = 1;i < M;++i) {
		pw[i] = pw[i - 1] * 2 % mod;
	}
	cin >> n;
	map[0] = 0;
	for(int i = 1;i <= n;++i) {
		st[0][i] = i;
		cin >> a[i];
		s[i] = (s[i - 1] + pw[a[i]]) % mod;
		map[s[i]] = i;
	}
	for(int i = 1;i < 20;++i) {
		for(int j = 1;j + (1 << i) - 1 <= n;++j) {
			st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
		}
	}
	solve(1, n);
	pengbo();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 24144kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

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

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

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

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: 6ms
memory: 31288kb

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: 3ms
memory: 32284kb

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: 8ms
memory: 34576kb

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: 8ms
memory: 40956kb

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: -100
Wrong Answer
time: 26ms
memory: 47008kb

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:

234697236

result:

wrong answer 1st numbers differ - expected: '592751350', found: '234697236'