QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#444177#8527. Power Divisionsucup-team3564#WA 6ms34492kbC++203.5kb2024-06-15 17:37:392024-06-15 17:37:40

Judging History

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

  • [2024-06-15 17:37:40]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:34492kb
  • [2024-06-15 17:37:39]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\033[32m[" << __LINE__ << "]\033[0m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = - f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
#define u128 unsigned __int128
#define u64 ull
int lg32(int x) {return 31 ^ __builtin_clz(x);}
constexpr ll pow(ll a, ll x, ll p, ll res = 1) {
	for(;x;x >>= 1, a = (u128) a * a % p)
		if(x & 1) res = (u128) res * a % p;
	return res;
}
constexpr bool checkprime(ll p) {
	if(p == 1) return 0;
	ll d = __builtin_ctzll(p - 1), s = (p - 1) >> d;
	for(ll a : {2, 3, 5, 7, 11, 13, 82, 373}) {
		if(a % p == 0)
			continue;
		ll x = pow(a, s, p), y = 0;
		for(int i = 0;i < d;++i, x = y) {
			y = (u128) x * x % p;
			if(y == 1 && x != 1 && x != p - 1) return 0;
		}
		if(x != 1) return 0;
	}
	return 1;
}
constexpr ll gen_prime(ll L, ll R) {
	// gen prime in [L, R)
	u64 x = 1128471;
	for(char c : __TIME__  __TIMESTAMP__) {
		x += c, x ^= x << 13, x ^= x >> 7, x ^= x << 17;
	}
	for(;;) {
		x ^= x << 13, x ^= x >> 7, x ^= x << 17;
		ll y = L + x % (R - L);
		if(checkprime(y))
			return y;
	}
	return 0;
}
const int N = 1e6 + 1000, MOD = 1e9 + 7;
inline int& add(int &x, ll y) {return x = (x + y) % MOD;}
const ll HOD = gen_prime(1e17, 1e18);
int n, a[N], f[N];
pair <int, int> info[20][N];
ll pw[N], s[N];
pair <int, int> query(int l, int r) {
	int k = lg32(r - l + 1);
	return max(info[k][l], info[k][r - (1 << k) + 1]);
}
unordered_map <ll, int> mp;
void solve(int l, int r) {
	if (l > r) return;
	int pos = query(l, r).second;
	// debug << l << " " << r << " " << pos << endl;
	solve(l, pos - 1);
	add(f[pos], f[pos - 1]);
	if (pos - l < r - pos) {
		// F(i, pos + 1, r) mp[s[i]] = i;
		F(i, 1, lg32(r - l + 1)) {
			DF(j, pos, l) {
				int t = mp[(s[j - 1] + pw[a[pos] + i]) % HOD];
				if (t) {
					if (t - 1 < pos) break;
					add(f[t - 1], f[j - 1]);//, debug << "!\n";
				}
			}
		}
	} else {
		// F(i, pos + 1, r) mp[s[i]] = i;
		F(i, 1, lg32(r - l + 1)) {
			F(j, pos, r) {
				int t = mp[(s[j] - pw[a[pos] + i] + HOD) % HOD];
				if (t) {
					if (t > pos) break;
					add(f[j], f[t - 1]);//, debug << t << " " << j << endl;
				}
			}
		}
	}
	solve(pos + 1, r);
}
signed main() {
	read(n);
	pw[0] = 1;
	F(i, 1, 1e6 + 100) pw[i] = 2 * pw[i - 1] % HOD;
	mp[0] = 1;
	F(i, 1, n) read(a[i]), mp[s[i] = (s[i - 1] + pw[a[i]]) % MOD] = i + 1, info[0][i] = make_pair(a[i], i);
	F(i, 1, lg32(n))
		F(j, 1, n - (1 << i) + 1)
			info[i][j] = max(info[i - 1][j], info[i - 1][j + (1 << (i - 1))]);
	f[0] = 1;
	solve(1, n);
	// F(i, 1, n) cout << f[i] << " "; cout << endl;
	cout << f[n];
	return 0;
}
/* why?
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 5ms
memory: 19996kb

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

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

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

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

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:

347261270

result:

wrong answer 1st numbers differ - expected: '506782981', found: '347261270'