QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#444284#8527. Power Divisionsucup-team3564#TL 301ms265608kbC++204.3kb2024-06-15 18:05:082024-06-15 18:05:08

Judging History

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

  • [2024-06-15 18:05:08]
  • 评测
  • 测评结果:TL
  • 用时:301ms
  • 内存:265608kb
  • [2024-06-15 18:05:08]
  • 提交

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;
namespace HashMap{

const int N=1e6+5;
const int M=(1<<25);

ll key[N];
int head[M],nxt[N],tot=0,val[N];

void ins(ll x,int y){
	int w=(x&(M-1)),p=head[w],lst=0;
	while(p&&key[p]!=x)lst=p,p=nxt[p];

	if(!p){
		key[p=++tot]=x;
		if(lst)nxt[lst]=p;
		else head[w]=p;
	}
	val[p]=y;
}
int qval(ll x){
	int w=(x&(M-1)),p=head[w];
	while(p&&key[p]!=x)p=nxt[p];
	if(!p)return 0;
	return val[p];
}

};

using HashMap::ins;
using HashMap::qval;
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 = qval((s[j - 1] + pw[a[pos] + i]) % HOD);
				if (t) {
					if (t - 1 < pos) break;
					if (t - 1 <= r) add(f[t - 1], f[j - 1]);//, debug << "!\n";
					// debug << j << " " << t - 1 << endl;
				}
			}
		}
	} else {
		// F(i, pos + 1, r) mp[s[i]] = i;
		F(i, 1, lg32(r - l + 1)) {
			F(j, pos, r) {
				int t = qval((s[j] - pw[a[pos] + i] + HOD) % HOD);
				// if (pos == 30 && j == pos) {
				// 	debug << (s[j] - pw[a[pos]] + HOD) % HOD << endl;
				// 	debug << s[j - 1] << endl;
				// 	debug << i << " " << t << " " << mp[(s[j] - pw[a[pos]] + HOD) % HOD] << endl;
				// }
				if (t) {
					if (t > pos) break;
					if (t >= l) 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;
	ins(0, 1);
	F(i, 1, n) read(a[i]), ins(s[i] = (s[i - 1] + pw[a[i]]) % HOD, i + 1), info[0][i] = make_pair(a[i], i);
	// debug << a[29] << " " << a[30] << ' ' << pw[48] << endl;
	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: 3ms
memory: 24132kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

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

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

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

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

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

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

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: 4ms
memory: 47476kb

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: 12ms
memory: 60900kb

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: 0
Accepted
time: 49ms
memory: 120756kb

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:

842503795

result:

ok 1 number(s): "842503795"

Test #15:

score: 0
Accepted
time: 35ms
memory: 137640kb

input:

300000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

432100269

result:

ok 1 number(s): "432100269"

Test #16:

score: 0
Accepted
time: 115ms
memory: 265608kb

input:

300000
1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 10000...

output:

432100269

result:

ok 1 number(s): "432100269"

Test #17:

score: 0
Accepted
time: 66ms
memory: 124872kb

input:

299995
1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 1 1 1 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 1 1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 1 0 0 0 0 0 0 1 0 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 1 1 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 0 0...

output:

261818019

result:

ok 1 number(s): "261818019"

Test #18:

score: 0
Accepted
time: 88ms
memory: 240628kb

input:

299997
2 2 0 9 4 4 2 3 8 9 3 9 1 6 4 0 1 5 1 0 7 9 3 3 8 9 3 8 3 6 9 3 9 5 9 1 4 4 7 5 9 0 7 3 7 2 0 3 3 8 2 1 7 6 8 1 6 1 8 4 7 6 3 6 1 6 8 9 3 8 1 5 0 8 1 10 0 3 4 5 8 5 6 9 2 4 5 0 9 0 9 5 1 0 3 7 5 8 8 10 10 3 3 10 5 8 9 9 7 4 4 1 1 6 5 7 2 5 8 3 3 9 6 4 1 0 2 6 2 8 7 7 10 5 7 8 3 8 5 1 6 6 6 1 ...

output:

999738318

result:

ok 1 number(s): "999738318"

Test #19:

score: 0
Accepted
time: 115ms
memory: 239784kb

input:

299999
97 34 33 30 15 73 31 69 60 63 79 87 78 13 49 58 23 38 91 28 70 70 14 98 56 59 81 66 29 21 10 51 94 32 41 98 16 48 67 62 55 5 17 81 30 91 39 93 73 74 46 74 41 99 19 10 0 16 72 95 84 40 97 17 76 10 42 50 66 97 4 30 71 74 46 5 75 87 55 82 38 94 14 82 49 10 23 21 19 99 52 100 71 29 64 73 54 88 2 ...

output:

799664563

result:

ok 1 number(s): "799664563"

Test #20:

score: 0
Accepted
time: 204ms
memory: 236628kb

input:

299997
97 181 693 569 34 770 725 1 82 951 965 962 962 532 803 824 669 686 529 339 434 430 439 478 553 354 443 632 725 139 56 709 797 847 617 100 837 94 80 527 644 861 8 455 710 599 473 818 685 886 645 722 239 634 450 16 825 337 156 708 827 790 462 716 67 557 535 466 820 465 567 140 633 112 85 691 16...

output:

152812109

result:

ok 1 number(s): "152812109"

Test #21:

score: 0
Accepted
time: 242ms
memory: 240296kb

input:

300000
7938 3542 362 8246 5914 9327 9031 9802 6879 5983 1052 8554 8571 187 3412 4806 1991 9465 7940 8741 5792 7136 6654 7716 2896 4212 3357 6278 3398 5631 4759 6295 7385 5487 699 3015 422 4849 4933 3169 3194 7014 7605 9619 8126 4673 5020 842 9477 2925 857 1263 3326 729 4638 3383 7716 887 7821 2009 7...

output:

294967268

result:

ok 1 number(s): "294967268"

Test #22:

score: 0
Accepted
time: 264ms
memory: 234552kb

input:

300000
68003 20603 19535 98755 78166 31928 28492 76831 77102 95079 32154 12348 91482 11514 67510 4208 30189 31364 77353 60045 60124 58954 32468 38599 70247 18763 32984 76656 86646 79971 63986 68195 33578 90458 79520 92707 17642 7744 26043 12273 28374 63264 97058 36502 6212 70591 51401 76682 41512 18...

output:

32

result:

ok 1 number(s): "32"

Test #23:

score: 0
Accepted
time: 301ms
memory: 234844kb

input:

299995
704135 597658 946639 146393 887400 976091 33440 872707 692148 819088 785763 285388 604527 830260 851525 558807 997790 380755 251183 328941 129356 741341 530638 817968 603319 899844 731899 356842 867124 825330 645685 373685 70290 726706 995759 161401 398693 132928 535725 831104 643517 149954 7...

output:

1

result:

ok 1 number(s): "1"

Test #24:

score: 0
Accepted
time: 232ms
memory: 232768kb

input:

300000
999990 999988 999987 999987 999989 999988 999987 999987 999988 999988 999988 999988 999987 999987 999987 999987 999989 999989 999988 999988 999987 999987 999987 999987 999991 999989 999987 999987 999988 999988 999986 999986 999986 999986 999986 999986 999987 999987 999987 999985 999985 999985...

output:

907456874

result:

ok 1 number(s): "907456874"

Test #25:

score: 0
Accepted
time: 147ms
memory: 251532kb

input:

299998
1000000 999998 999997 999994 999993 999992 999990 999987 999986 999985 999984 999983 999981 999977 999976 999975 999974 999971 999969 999968 999966 999964 999963 999961 999960 999955 999953 999947 999946 999945 999944 999943 999940 999937 999936 999935 999934 999933 999930 999928 999927 99992...

output:

299998

result:

ok 1 number(s): "299998"

Test #26:

score: 0
Accepted
time: 148ms
memory: 251580kb

input:

300000
225118 225117 225116 225114 225114 225112 225111 225110 225108 225108 225105 225105 225105 225103 225103 225099 225099 225095 225094 225093 225091 225091 225091 225089 225089 225089 225088 225086 225086 225086 225084 225083 225081 225080 225077 225075 225075 225074 225073 225072 225071 225068...

output:

651536657

result:

ok 1 number(s): "651536657"

Test #27:

score: 0
Accepted
time: 159ms
memory: 243080kb

input:

300000
966603 966600 966600 966599 966596 966591 966588 966586 966586 966585 966583 966581 966580 966577 966577 966578 966578 966577 966576 966576 966581 966580 966580 966583 966583 966586 966589 966590 966592 966593 966592 966590 966588 966587 966585 966584 966581 966580 966578 966577 966577 966573...

output:

956228402

result:

ok 1 number(s): "956228402"

Test #28:

score: 0
Accepted
time: 142ms
memory: 241996kb

input:

300000
318513 318509 318504 318503 318499 318498 318496 318496 318490 318490 318487 318486 318482 318480 318480 318479 318478 318477 318477 318480 318483 318482 318479 318479 318478 318478 318475 318474 318472 318471 318470 318469 318467 318465 318461 318459 318457 318456 318450 318450 318450 318448...

output:

505865071

result:

ok 1 number(s): "505865071"

Test #29:

score: 0
Accepted
time: 161ms
memory: 240124kb

input:

299999
814266 814266 814265 814263 814262 814262 814264 814266 814265 814263 814263 814259 814258 814256 814256 814253 814251 814251 814249 814249 814248 814247 814246 814245 814244 814243 814243 814249 814250 814247 814247 814247 814241 814239 814236 814229 814229 814230 814229 814226 814226 814225...

output:

586808369

result:

ok 1 number(s): "586808369"

Test #30:

score: 0
Accepted
time: 176ms
memory: 234540kb

input:

299997
999997 999994 999993 999993 999995 999993 999992 999989 999989 999990 999991 999994 999992 999992 999992 999990 999986 999984 999984 999982 999981 999978 999978 999979 999980 999982 999981 999981 999982 999982 999983 999986 999982 999981 999981 999983 999984 999985 999986 999986 999987 999989...

output:

215177543

result:

ok 1 number(s): "215177543"

Test #31:

score: 0
Accepted
time: 250ms
memory: 239036kb

input:

300000
999997 999995 999995 999996 999997 999996 999996 999994 999994 999995 999995 999991 999990 999989 999988 999988 999992 999992 999991 999988 999987 999987 999985 999985 999986 999987 999987 999987 999990 999994 999994 999992 999992 999993 999995 999995 999992 999992 999993 999994 999993 999993...

output:

777454227

result:

ok 1 number(s): "777454227"

Test #32:

score: 0
Accepted
time: 225ms
memory: 234508kb

input:

299996
999994 999992 999990 999986 999984 999983 999983 999984 999984 999983 999982 999981 999981 999984 999982 999981 999981 999983 999982 999980 999980 999981 999983 999982 999979 999979 999980 999981 999983 999984 999985 999986 999986 999987 999986 999986 999983 999983 999984 999985 999986 999988...

output:

682333830

result:

ok 1 number(s): "682333830"

Test #33:

score: -100
Time Limit Exceeded

input:

300000
39 38 38 36 35 35 32 32 33 29 29 28 28 28 27 24 24 25 25 25 28 26 20 20 19 19 20 21 19 19 18 18 19 23 23 23 24 22 22 22 22 26 26 22 22 22 22 23 23 24 24 26 25 24 23 23 24 24 24 24 28 25 24 24 26 27 28 29 25 25 26 27 28 28 28 30 30 26 24 24 22 22 22 22 24 27 28 28 24 22 20 17 17 18 19 21 23 25...

output:


result: