QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454444#8527. Power DivisionskarunaWA 8ms14048kbC++202.7kb2024-06-24 21:52:502024-06-24 21:52:50

Judging History

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

  • [2024-06-24 21:52:50]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:14048kb
  • [2024-06-24 21:52:50]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ff first
#define ss second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int SZ = 1010101;

const int P1 = 998244353;
const int P2 = 1e9 + 7;

int n, a[SZ], pw[2][SZ];
int ans = 0;

int cnt[SZ];
vector<int> V[SZ];

void solve(int s, int e) {
	if (e - 1 == s) {
		V[e - 1].push_back(s);
		return;
	}
	int m = (s + e) / 2;
	solve(s, m);
	solve(m, e);

	vector<pii> L, R;
	vector<int> mxL, mxR;

	int m1 = 0, m2 = 0, mx = 0;
	for (int i = m; i < e; i++) {
		m1 = (m1 + pw[0][a[i]]) % P1;
		m2 = (m2 + pw[1][a[i]]) % P2;

		R.push_back({m1, m2});

		mx = max(mx, a[i]);
		++cnt[a[i]];

		int p = a[i];
		while (cnt[p] >= 2) {
			cnt[p + 1] += 1;
			cnt[p] -= 2;
			mx = max(mx, ++p);
		}
		mxR.push_back(mx);
	}

	for (int i = m; i < e; i++) {
		--cnt[a[i]];
		
		int p = a[i];
		while (cnt[p] <= -2) {
			cnt[p + 1] -= 1;
			cnt[p] += 2;
		}
	}

	m1 = m2 = mx = 0;
	for (int i = m; i > s; i--) {
		m1 = (m1 + pw[0][a[i - 1]]) % P1;
		m2 = (m2 + pw[1][a[i - 1]]) % P2;

		L.push_back({m1, m2});

		mx = max(mx, a[i - 1]);
		++cnt[a[i - 1]];

		int p = a[i - 1];
		while (cnt[p] >= 2) {
			cnt[p + 1] += 1;
			cnt[p] -= 2;
			mx = max(mx, ++p);
		}
		mxL.push_back(mx);
	}
	for (int i = m; i > s; i--) {
		--cnt[a[i - 1]];

		int p = a[i - 1];
		while (cnt[p] <= -2) {
			cnt[p + 1] -= 1;
			cnt[p] += 2;
		}
	}

	map<pii, int> st;
	for (int i = 0; i < L.size(); i++) st[L[i]] = m - 1 - i;
	for (int i = 0; i < R.size(); i++) {
		int t1 = (pw[0][mxR[i] + 1] + P1 - R[i].ff) % P1;
		int t2 = (pw[1][mxR[i] + 1] + P2 - R[i].ss) % P2;

		if (st.find({t1, t2}) != st.end()) {
			V[m + i].push_back(st[{t1, t2}]);
		}
	}

	st.clear();
	for (int i = 0; i < R.size(); i++) st[R[i]] = m + i;
	for (int i = 0; i < L.size(); i++) {
		int t1 = (pw[0][mxL[i] + 1] + P1 - L[i].ff) % P1;
		int t2 = (pw[1][mxL[i] + 1] + P2 - L[i].ss) % P2;

		if (st.find({t1, t2}) != st.end()) {
			V[st[{t1, t2}]].push_back(m - i - 1);
		}
	}
}

int dp[SZ];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	pw[0][0] = 1;
	pw[1][0] = 1;
	for (int i = 1; i < SZ; i++) {
		pw[0][i] = 1ll * pw[0][i - 1] * 2 % P1;
		pw[1][i] = 1ll * pw[1][i - 1] * 2 % P2;
	}
	solve(0, n);

	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		sort(V[i].begin(), V[i].end());
		V[i].erase(unique(V[i].begin(), V[i].end()), V[i].end());

		for (int x : V[i]) {
			dp[i + 1] = (dp[i + 1] + dp[x]) % P2;
		}
	}
	cout << dp[n] << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 13764kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

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

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

7
3 4 3 5 6 3 4

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

input:

10
8 6 5 6 7 8 6 8 9 9

output:

4

result:

ok 1 number(s): "4"

Test #9:

score: -100
Wrong Answer
time: 8ms
memory: 13840kb

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:

1354752

result:

wrong answer 1st numbers differ - expected: '11332014', found: '1354752'