QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#448005#8527. Power DivisionsPurslaneWA 1ms3912kbC++141.8kb2024-06-19 08:06:112024-06-19 08:06:11

Judging History

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

  • [2024-06-19 08:06:11]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3912kb
  • [2024-06-19 08:06:11]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ffor(i,a,b) for(int i=(a);i<=(b);i++)
#define roff(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const int MAXN=3e5+50,kMOD=1e9+7,MOD=(1ull<<61)-1;
int n,a[MAXN],dp[MAXN],c[MAXN],sum[MAXN],lst[MAXN],fst[MAXN],pre[MAXN],suf[MAXN];
mt19937 myrand(time(NULL));
int calc(int l,int r) {
	if(l==0) return sum[r];
	return (sum[r]-sum[l-1])%MOD;	
}
void cdq(int l,int r) {
	if(l>r) return ;
	if(l==r) return dp[l]=(dp[l]+dp[l-1])%kMOD,void();
	int mid=l+r>>1;
	cdq(l,mid);
	set<int> st;
	int tval=0; pre[mid+1]=0;
	roff(i,mid,l) {
		int pos=a[i];
		while(1) {
			if(st.find(pos)!=st.end()) st.erase(pos),tval=(tval-c[pos])%MOD,pos++;
			else break ;
		}
		st.insert(pos),tval=(tval+c[pos])%MOD,pre[i]=tval,lst[i]=*st.begin(),fst[i]=*st.rbegin();
	}
	st.clear(),tval=0;
	ffor(i,mid+1,r) {
		int pos=a[i];
		while(1) {
			if(st.find(pos)!=st.end()) st.erase(pos),tval=(tval-c[pos])%MOD,pos++;
			else break ;
		}
		st.insert(pos),tval=(tval+c[pos])%MOD,suf[i]=tval,lst[i]=*st.begin(),fst[i]=*st.rbegin();
	}
	map<int,int> addr,addl;
	//l>=r
	ffor(i,l,mid) {
		int sum=((calc(lst[i],fst[i])+c[lst[i]]-pre[i])%MOD+MOD)%MOD;
		addr[sum]=(addr[sum]+dp[i-1])%kMOD,addl[pre[i]]=(addl[pre[i]]+dp[i-1])%MOD;
	}
	//l<r
	ffor(i,mid+1,r) {
		dp[i]=(dp[i]+addr[suf[i]])%MOD;
		if(fst[i]!=lst[i]) {
			int sum=((calc(lst[i],fst[i])+c[lst[i]]-suf[i])%MOD+MOD)%MOD;
			dp[i]=(dp[i]+addl[sum])%MOD;
		}
	}
	cdq(mid+1,r);
	return ;
}
signed main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n; ffor(i,1,n) cin>>a[i];
	ffor(i,0,n+20) c[i]=(1ull*myrand()*myrand()%MOD+MOD)%MOD;
	sum[0]=c[0]; ffor(i,1,n+20) sum[i]=(sum[i-1]+c[i])%MOD;
	dp[0]=1;
	cdq(1,n);
	cout<<dp[n];
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3708kb

input:

5
2 0 0 1 1

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3912kb

input:

1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

3
2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3768kb

input:

4
3 2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5
3 4 4 2 4

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

7
3 4 3 5 6 3 4

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 1ms
memory: 3868kb

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

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:

11328594

result:

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