QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#17111#1780. Intact Intervals_silhouette_#WA 0ms11960kbC++141.4kb2022-01-03 19:53:022022-05-04 13:21:31

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-04 13:21:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11960kb
  • [2022-01-03 19:53:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int Max_N=1e6,Mod=998244353,MOD=1e9+7;
int n,a[Max_N+5],b[Max_N+5],c[Max_N+5],s[Max_N+5];
long long p[Max_N+5];
map<int,int> vis;
int Read(){
	int num=0; char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';num=num*10+ch-'0',ch=getchar());
	return num;
}
long long Rand(){
	return (rand()*1000000ll+rand()*100000ll+rand())%100000000+1;
}
long long Mul(int x,int y){
	long long ans=1;
	for(;y;y>>=1,x=1ll*x*x%Mod)
	 if(y&1) ans=ans*x%Mod;
	return ans;
}
int main(){
	srand(123456);
	n=Read();
	for(int i=1;i<=n;i++) a[i]=Read();
	for(int i=1;i<=n;i++) b[i]=Read();
	for(int i=1;i<=n;i++) c[i]=a[i];
	sort(c+1,c+n+1);
	int cnt=unique(c+1,c+n+1)-c-1;
	for(int i=1;i<=n;i++)
	 a[i]=lower_bound(c+1,c+cnt+1,a[i])-c,
	 b[i]=lower_bound(c+1,c+cnt+1,b[i])-c;
	for(int i=0;i<=cnt;i++) p[i]=Rand();
	for(int i=1;i<=cnt;i++) s[i]=n;
	long long H=0;
	for(int i=1;i<=cnt;i++) H=(H+1ll*s[i]*p[i]%Mod)%Mod; 
	++vis[H];
	for(int i=1;i<=n;i++){
		H=(H-1ll*s[a[i]]*p[a[i]]%Mod+Mod)%Mod;
		H=(H-1ll*s[b[i]]*p[b[i]]%Mod+Mod)%Mod;
		++s[a[i]],--s[b[i]];
		H=(H+1ll*s[a[i]]*p[a[i]]%Mod+Mod)%Mod;
		H=(H+1ll*s[b[i]]*p[b[i]]%Mod+Mod)%Mod;
		++vis[H];
	}
	long long ans=0;
	for(map<int,int>::iterator It=vis.begin();It!=vis.end();++It)
	 if((*It).second>=2) ans=(ans+Mul(2,(*It).second)-1-(*It).second+Mod)%Mod;
	printf("%lld\n",(ans-1+Mod)%Mod); 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11960kb

input:

2
10 9
9 10

output:

0

result:

ok single line: '0'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 11864kb

input:

5
3 6 9 10 6
3 10 6 9 6

output:

10

result:

wrong answer 1st lines differ - expected: '4', found: '10'