QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#17113 | #1780. Intact Intervals | _silhouette_# | WA | 8ms | 12448kb | C++ | 1.4kb | 2022-01-03 20:03:07 | 2022-05-04 13:21:37 |
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)
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: 2ms
memory: 11868kb
input:
2 10 9 9 10
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 1ms
memory: 11896kb
input:
5 3 6 9 10 6 3 10 6 9 6
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 0ms
memory: 11944kb
input:
10 10 10 0 4 0 5 3 8 5 3 3 0 8 5 0 4 3 10 5 10
output:
9
result:
ok single line: '9'
Test #4:
score: 0
Accepted
time: 2ms
memory: 11916kb
input:
100 53 74 39 7 86 14 54 63 86 33 1 33 94 28 65 93 79 52 3 22 53 20 69 59 29 8 42 7 18 33 27 72 10 19 65 30 29 1 57 39 41 6 9 5 92 15 99 22 72 18 81 7 51 82 57 28 4 27 65 99 55 8 57 76 61 13 19 89 9 79 76 95 11 68 9 52 79 24 99 52 65 30 34 77 64 99 10 30 41 12 91 90 13 24 76 41 26 84 51 22 99 89 24 5...
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 4ms
memory: 11920kb
input:
100 1 8 7 6 4 6 8 10 9 10 7 8 8 9 7 5 7 8 7 10 10 0 2 5 6 6 5 4 1 8 3 1 8 0 3 2 0 8 0 8 6 0 1 2 2 2 0 10 5 0 6 4 2 8 8 10 5 1 1 5 8 9 9 0 6 7 3 0 3 6 5 8 4 9 2 9 2 8 3 4 5 0 3 10 6 9 7 0 10 9 9 8 5 10 0 1 8 2 2 10 4 0 3 8 2 6 5 6 10 4 10 8 3 8 4 8 6 0 1 0 2 7 0 5 1 6 9 0 7 2 0 1 5 5 7 6 0 9 10 4 0 2...
output:
13
result:
ok single line: '13'
Test #6:
score: 0
Accepted
time: 2ms
memory: 11904kb
input:
100 1 2 0 0 2 1 1 1 1 1 0 0 2 0 1 2 1 0 0 2 1 2 0 2 0 0 1 2 2 2 0 0 0 1 1 1 1 0 0 0 2 2 2 2 0 2 1 2 2 1 2 1 1 1 1 2 2 0 1 0 0 0 0 1 0 1 2 0 2 2 2 1 1 2 1 1 0 1 2 2 0 2 2 1 2 1 1 1 1 2 0 1 1 2 0 1 0 2 2 0 0 1 1 1 1 2 2 1 0 0 2 2 0 0 1 0 2 2 1 0 1 2 2 0 1 1 1 2 1 0 0 2 2 0 1 1 1 0 1 1 2 1 2 2 2 1 2 2 ...
output:
1075
result:
ok single line: '1075'
Test #7:
score: 0
Accepted
time: 3ms
memory: 12416kb
input:
10000 2140 5310 9949 84 2706 4404 6310 8451 6995 8883 4817 8214 1668 4724 1674 839 2900 7773 8536 3712 3056 4683 405 1826 9937 5284 9614 8701 4235 8394 4678 6904 3425 2458 2343 6893 5819 5207 370 9231 3018 2552 1381 4495 8465 2312 6937 907 3333 4236 8006 6939 4945 1667 1528 5043 5298 2278 3634 6824 ...
output:
4
result:
ok single line: '4'
Test #8:
score: 0
Accepted
time: 8ms
memory: 12448kb
input:
10000 82 19 42 67 24 91 33 53 56 16 30 88 22 26 13 99 93 98 62 6 18 34 75 91 91 39 16 56 68 67 36 90 86 39 10 20 37 52 56 4 69 18 97 82 48 35 21 7 24 42 95 99 66 47 1 37 42 90 86 47 36 82 67 27 11 58 62 10 29 10 87 12 73 62 64 27 58 39 36 98 43 25 76 37 96 39 65 64 61 45 65 80 23 56 95 49 45 69 70 5...
output:
117
result:
ok single line: '117'
Test #9:
score: -100
Wrong Answer
time: 3ms
memory: 11968kb
input:
10000 0 1 0 1 2 2 2 2 2 0 1 0 0 1 1 2 0 2 1 0 1 2 2 1 1 1 2 0 2 2 0 0 2 2 1 0 2 1 2 2 2 0 2 1 2 1 2 0 2 2 0 1 0 1 0 1 0 0 0 1 1 0 1 2 0 1 0 2 0 1 2 0 1 2 1 0 1 2 2 0 2 1 1 1 0 2 1 0 2 1 2 0 2 0 0 0 1 0 1 1 2 2 2 0 0 1 2 2 0 1 1 0 2 1 2 1 1 0 2 1 2 0 0 2 1 1 2 1 0 2 1 0 2 2 1 2 1 0 0 0 1 2 1 2 0 2 2 ...
output:
676871116
result:
wrong answer 1st lines differ - expected: '661070230', found: '676871116'