Bzoj 1145
coc youyl
posted @ 2015年7月02日 20:19
in bzoj
, 979 阅读
题目分类:树状数组,乱搞
题意:
给出1-n的一个排列,球形如1324的形状的数量减去形如的1243形状的数量和形如1432的形状的数量的和。
题解:
f[1324]-f[1243]-f[1432]=(f[1x2x]-f[1423])-(f[12xx]-f[1234])-(f[14xx]-f[1423])=f[1x2x]+f[1234]+(-f[1xxx]+f[13xx])
f[1x2x]要用排除法
f[13xx]需要反过来推
具体参见程序
程序:
#include<cstdio> #include<cstring> using namespace std; struct fenwick { long long a[220000]; inline void init() { memset(a,0,sizeof(a)); } inline void edit(long long x,long long y) { while (x<=200000) { a[x]+=y; x+=(x&(-x)); } } inline long long query(long long x) { long long ss=0; while (x>0) { ss+=a[x]; x-=(x&(-x)); }return ss; } }sgt; const long long modminusone=16777215; long long n,b[220000],l[220000],r[220000]; inline long long _1xxx() { long long ss=0; sgt.init(); for (long long i=1;i<=n;i++) { long long t=n-i-r[i]; ss+=(t*(t-1)*(t-2)/6)&modminusone; ss&=modminusone; } return ss; } inline long long _1x2x() { long long ss=0; sgt.init(); for (long long i=1;i<=n;i++) { ss+=(((l[i]*(i-1)-(l[i]-1)*l[i]/2-sgt.query(b[i]))*(n-i-r[i]))&modminusone); ss&=modminusone; sgt.edit(b[i],i); } return ss; } inline long long _13xx() { long long ss=0; sgt.init(); for (long long i=n;i>=1;i--) { ss+=(((sgt.query(b[i])-r[i]*(r[i]+1)/2)*(n-i-r[i]))&modminusone); ss&=modminusone; sgt.edit(b[i],b[i]); }return ss; } inline long long _1234() { long long ss=0; sgt.init(); for (long long i=1;i<=n;i++) { ss+=((sgt.query(b[i])*(n-i-r[i]))&modminusone); ss&=modminusone; sgt.edit(b[i],l[i]); } return ss; } int main() { scanf("%lld",&n); for (long long i=1;i<=n;i++) { scanf("%lld",&b[i]); } for (long long i=1;i<=n;i++) { l[i]=sgt.query(b[i]); r[i]=b[i]-1-l[i]; sgt.edit(b[i],1); } printf("%lld\n",(_1234()+_1x2x()+_13xx()-_1xxx())&modminusone); return 0; }
2022年8月30日 00:48
Government of the People’s Republic of Bangladesh, Directorate of Primary Education (DPE), is going to announce PSC Result 2022 in student wide on 30th December 2022 for all divisional Grade 5 exam result with Ebtedayee Result 2022 for annual final terminal examinations, The Primary School Certificate Examination Result 2022 will be announced for both of General and Madhrsah students in division wise to all education board known as Prathomik Somaponi Result 2022. Madrasah Board Result The DPE has successfully conducted the class 5th grade PSC and Ebtedayee Examination tests from 17th to 24th November 2022 under all education boards of Dhaka, Chittagong, Comilla, Rajshahi, Sylhet, Barisal, Jessore, Dinajpur and Madrasah Board, and the DPE Grade-5 exams are successfully conducted at all 7,194 centers across the country.