QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#17112 | #1780. Intact Intervals | _silhouette_# | WA | 1ms | 11900kb | C++ | 1.4kb | 2022-01-03 19:58:06 | 2022-05-04 13:21:33 |
Judging History
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;
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);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 11900kb
input:
2 10 9 9 10
output:
0
result:
ok single line: '0'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 11848kb
input:
5 3 6 9 10 6 3 10 6 9 6
output:
1
result:
wrong answer 1st lines differ - expected: '4', found: '1'