QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#20789 | #2468. Izbori | JohnAlfnov | 15 | 262ms | 87072kb | C++20 | 3.3kb | 2022-02-18 15:21:18 | 2022-05-03 11:27:43 |
Judging History
answer
#include<bits/stdc++.h>
#define HaojiaShi
#ifdef HaojiaShi
#define DX 16777220
#else
#define DX 167
#endif
using namespace std;
namespace file_read{
namespace input_file_io{
char ib[1<<25],*ip1=ib,*ip2=ib;
inline char gc(){
#ifdef HaojiaShi
return (ip1==ip2&&(ip2=(ip1=ib)+fread(ib,1,1<<24,stdin)),ip1==ip2?EOF:*ip1++);
#else
return getchar();
#endif
}
inline int read(){
int x=0,f=1;
char c=gc();
while(c<'0'||c>'9'){
if(c=='-')f=-1;
c=gc();
}
while(c>='0'&&c<='9'){
x=(x<<3)+(x<<1)+(c-'0');
c=gc();
}
return x*f;
}
};
using namespace input_file_io;
};
using namespace file_read;
long long s1[DX+5],s2[DX+5];
int l1[DX+5],l2[DX+5];
void pushdown1(int l,int r,int o){
if(!l1[o])return;
int mid=(l+r)>>1;
l1[o<<1]+=l1[o];
l1[o<<1|1]+=l1[o];
s1[o<<1]+=1ll*(mid-l+1)*l1[o];
s1[o<<1|1]+=1ll*(r-mid)*l1[o];
l1[o]=0;
}
void pushdown2(int l,int r,int o){
if(!l2[o])return;
int mid=(l+r)>>1;
l2[o<<1]+=l2[o];
l2[o<<1|1]+=l2[o];
s2[o<<1]+=-1ll*(l+mid)*(mid-l+1)/2*l2[o];
s2[o<<1|1]+=-1ll*(mid+1+r)*(r-mid)/2*l2[o];
l2[o]=0;
}
void add1(int l,int r,int o,int ll,int rr,int x){
if(l>=ll&&r<=rr){
l1[o]+=x;
s1[o]+=1ll*(r-l+1)*x;
return;
}
pushdown1(l,r,o);
int mid=(l+r)>>1;
if(mid>=ll)add1(l,mid,o<<1,ll,rr,x);
if(mid<rr)add1(mid+1,r,o<<1|1,ll,rr,x);
s1[o]=s1[o<<1]+s1[o<<1|1];
}
void add2(int l,int r,int o,int ll,int rr,int x){
if(l>=ll&&r<=rr){
l2[o]+=x;
s2[o]+=-1ll*(l+r)*(r-l+1)/2*x;
return;
}
pushdown2(l,r,o);
int mid=(l+r)>>1;
if(mid>=ll)add2(l,mid,o<<1,ll,rr,x);
if(mid<rr)add2(mid+1,r,o<<1|1,ll,rr,x);
s2[o]=s2[o<<1]+s2[o<<1|1];
}
long long query1(int l,int r,int o,int ll,int rr){
if(l>=ll&&r<=rr)return s1[o];
pushdown1(l,r,o);
int mid=(l+r)>>1;
long long ans=0;
if(mid>=ll)ans+=query1(l,mid,o<<1,ll,rr);
if(mid<rr)ans+=query1(mid+1,r,o<<1|1,ll,rr);
return ans;
}
long long query2(int l,int r,int o,int ll,int rr){
if(l>=ll&&r<=rr)return s2[o];
pushdown2(l,r,o);
int mid=(l+r)>>1;
long long ans=0;
if(mid>=ll)ans+=query2(l,mid,o<<1,ll,rr);
if(mid<rr)ans+=query2(mid+1,r,o<<1|1,ll,rr);
return ans;
}
int a[3000005];
vector<int>g[3000005];
int LL,RR,PY;
long long ans;
void add(int l,int r){
if(l>r)return;
l+=PY,r+=PY;
if(LL<l)ans+=(r-l+1)*query1(LL,RR,1,LL,l-1);
ans+=query2(LL,RR,1,l,r);
ans+=r*query1(LL,RR,1,l,r);
add1(LL,RR,1,l,r,1);
add2(LL,RR,1,l,r,1);
}
void del(int l,int r){
if(l>r)return;
l+=PY,r+=PY;
add1(LL,RR,1,l,r,-1);
add2(LL,RR,1,l,r,-1);
}
int main(){
int n=read();
for(int i=1;i<=n;++i){
a[i]=read();
g[a[i]].emplace_back(i);
}
PY=n+1,LL=1,RR=n+n+1;
ans=0;
for(int i=1;i<=n;++i)if(g[i].size()){
int s;
g[i].emplace_back(n+1);
s=0;
add(s=(1-g[i][0]),0);
for(int j=0;j<(signed)g[i].size()-1;++j){
int L=g[i][j],R=g[i][j+1];
++s;
add(s,s);
if(L+1<R){
add(s-(R-L-1),s-1);
s-=R-L-1;
}
}
s=0;
del(s=(1-g[i][0]),0);
for(int j=0;j<(signed)g[i].size()-1;++j){
int L=g[i][j],R=g[i][j+1];
++s;
del(s,s);
if(L+1<R){
del(s-(R-L-1),s-1);
s-=R-L-1;
}
}
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
10 942147545 450336559 589072061 942414770 141868244 766117816 508242564 347873370 140196153 821766606
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #7:
score: 0
Runtime Error
input:
921 524767688 509815977 594114825 991570522 991979961 544018125 777680993 983750838 95962635 531067495 150617691 492786314 158077719 497465369 741403989 459469418 977138578 151552739 702032898 475129961 244853392 202522013 917454821 365887956 487159109 141392137 134488324 185031598 38901169 31318575...
output:
result:
Subtask #3:
score: 15
Accepted
Test #18:
score: 15
Accepted
time: 167ms
memory: 75124kb
input:
132639 1 2 1 2 2 2 2 2 2 1 2 2 2 1 2 2 1 2 1 1 2 1 1 1 2 1 2 2 2 2 1 1 2 2 1 2 1 2 2 1 2 1 2 2 1 2 1 1 1 2 1 2 1 2 2 1 1 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 1 1 1 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 2 1 2 2 2 2 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 1 1 1 2 1 1 2 1 2 1 1 1 2 1 2 2 1 2 1 1 2...
output:
8783382170
result:
ok single line: '8783382170'
Test #19:
score: 0
Accepted
time: 211ms
memory: 75556kb
input:
173817 1 1 1 2 2 2 2 1 1 1 2 2 1 1 2 2 1 1 1 1 2 1 1 2 2 1 2 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 1 1 1 1 1 2 1 2 2 1 2 2 1 1 1 2 1 1 1 1 2 1 2 1 1 2 1 1 1 2 1 1 2 1 1 1 2 1 2 1 1 2 2 1 2 2 2 1 1 2 1 2 1 2 1 2 1 1 2 1 1 1 1 1 2 1 1 2 2 2 1 1 1 1 2 2 1 1 1 2 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 1 1 1 2 2 2 2 2 1...
output:
15075709853
result:
ok single line: '15075709853'
Test #20:
score: 0
Accepted
time: 126ms
memory: 74796kb
input:
101140 1 1 2 1 2 1 2 1 2 2 2 1 2 2 2 2 1 2 2 1 1 1 2 2 2 2 2 1 1 1 2 1 2 2 2 1 2 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 1 2 2 2 1 2 1 2 1 2 2 1 1 1 1 2 1 2 2 1 1 1 1 1 1 2 1 2 1 1 1 1 1 2 2 1 1 1 2 1 1 2 1 1 1 1 1 2 2 2 1 2 1 1 1 1 1 1 1 2 1 1 1 2 2 1 2 1 2 2 2 1 1 1 1 1 2 2 2 1 1 1 1 2 2 2 2 2 2 1 1 1 2 2 2...
output:
5098687920
result:
ok single line: '5098687920'
Test #21:
score: 0
Accepted
time: 223ms
memory: 75688kb
input:
181968 2 1 2 1 2 2 1 2 2 2 1 1 1 1 2 1 2 2 1 1 2 2 2 2 1 1 1 1 1 2 1 1 2 2 2 2 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 1 2 1 2 2 2 1 1 2 2 1 2 2 1 2 2 1 2 1 2 2 1 2 1 2 1 2 2 1 1 2 2 2 2 1 2 1 1 1 2 1 2 1 2 2 2 2 1 1 2 2 1 2 1 1 2 1 1 2 2 2 2 2 1 2 2 1 2 2 2 1 2 2 1 2 1 1 2 2 1 2 1 1 2 1 1 1 1 2 1 2 1 1...
output:
16531060131
result:
ok single line: '16531060131'
Test #22:
score: 0
Accepted
time: 231ms
memory: 75676kb
input:
188622 2 2 1 2 1 2 1 2 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 2 1 1 1 1 2 1 1 1 1 1 2 2 2 2 1 1 2 1 2 1 1 1 1 2 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 1 1 2 1 1 2 2 1 1 2 1 2 2 1 1 1 1 1 1 1 1 2 2 1 2 2 2 1 2 1 2 1 1 1 2 2 1 2 1 2 2 2 1 1 2 1 2...
output:
17753612469
result:
ok single line: '17753612469'
Test #23:
score: 0
Accepted
time: 262ms
memory: 75824kb
input:
200000 2 1 2 1 2 1 2 2 2 1 2 2 1 1 1 2 1 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 1 1 2 1 2 1 1 1 2 2 2 2 1 2 2 2 2 1 1 1 2 1 2 1 1 1 2 2 1 2 2 1 1 1 2 2 2 1 1 2 2 2 1 2 2 1 1 2 1 2 2 1 2 2 2 2 1 2 2 2 1 2 1 1 1 2 2 1 1 1 2 2 2 1 2 2 1 1 1 2 1 1 2 1 1 1 2 2 1 2 1 1 2 1 2 2 2 2 1 2 2 2 1 1 1 2 2 1 2 2...
output:
19966666586
result:
ok single line: '19966666586'
Test #24:
score: 0
Accepted
time: 241ms
memory: 75828kb
input:
200000 2 2 1 2 2 1 2 2 1 2 2 2 2 2 2 1 1 1 1 2 1 2 2 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 2 2 2 1 2 1 2 2 2 1 1 2 1 2 1 2 1 1 2 2 2 1 2 2 1 2 2 1 1 2 1 2 1 1 1 2 1 2 2 1 1 1 2 1 2 2 1 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 1 1 2 1 1 2 2 1 2 1 2 1 2 2 1 2 2 2 1 1 2 2 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 2 1 2 2 1 2 2 2 1...
output:
19954274756
result:
ok single line: '19954274756'
Test #25:
score: 0
Accepted
time: 244ms
memory: 76028kb
input:
200000 1 2 1 2 2 2 2 1 1 1 2 1 2 2 2 1 2 1 2 1 1 1 2 2 1 2 2 1 1 1 1 1 1 1 2 2 1 1 2 1 1 1 2 1 1 1 2 1 2 2 2 1 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 1 1 2 2 1 1 1 2 2 2 2 2 1 2 2 1 2 1 1 2 1 2 1 2 2 1 1 2 2 2 2 1 2 2 1 2 2 2 1 2 1 1 2 2 1 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 1 1 1 1 2 1 1 2 1 1 2 1 1 1 2 1 1 1...
output:
19965178643
result:
ok single line: '19965178643'
Test #26:
score: 0
Accepted
time: 250ms
memory: 75972kb
input:
200000 1 1 1 2 1 1 1 2 2 2 2 1 2 1 2 1 1 2 1 1 2 2 2 2 2 2 1 1 1 2 1 1 2 2 2 1 1 2 2 1 2 2 1 1 2 2 2 2 2 2 2 1 1 1 2 1 1 1 2 1 1 2 1 1 1 1 2 2 2 2 1 1 1 1 1 2 1 2 1 2 1 2 2 2 1 2 1 2 1 1 2 2 2 1 2 2 2 2 2 2 1 2 2 2 1 1 1 1 2 1 1 1 2 2 2 2 1 1 2 2 2 2 1 1 2 1 2 1 2 1 2 1 1 1 2 2 1 1 2 2 1 2 2 2 1 1 2...
output:
19958231053
result:
ok single line: '19958231053'
Test #27:
score: 0
Accepted
time: 243ms
memory: 75624kb
input:
200000 2 1 2 2 2 2 2 1 1 1 1 1 1 2 1 2 1 1 1 1 2 1 1 2 1 2 1 2 2 1 2 2 1 1 1 1 2 2 2 2 1 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 1 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 1 1 1 2 1 1 1 2 1 2 1 1 1 1 2 1 1 1 2 2 1 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 2 2 2 2 1 2 1 2 2...
output:
19940557707
result:
ok single line: '19940557707'
Test #28:
score: 0
Accepted
time: 186ms
memory: 87072kb
input:
200000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
output:
20000100000
result:
ok single line: '20000100000'
Subtask #4:
score: 0
Runtime Error
Test #29:
score: 0
Runtime Error
input:
200000 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369607912 369...