日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

国家集训队 小Z的袜子

發布時間:2024/4/17 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 国家集训队 小Z的袜子 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

傳送門


自從“HH的項鏈”被樹狀數組干爆了之后,莫隊終于揚眉吐氣了一把。


很經典的莫隊模板題,好像沒什么好說的……

代碼有(十)些(分)冗長,將就著看吧……

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define LL long long using namespace std; struct zzz{LL l,r,pos; }que[50010]; int n,m,sq; bool cmp(zzz x,zzz y){if(x.l/sq != y.l/sq) return x.l/sq < y.l/sq;else return x.r < y.r; } LL read(){LL k=0; char c=getchar();for(;c<'0'||c>'9';) c=getchar();for(;c>='0'&&c<='9';c=getchar())k=(k<<3)+(k<<1)+c-48;return k; } LL a[50010],tong[50010]; struct hhh{LL fm,fz; }anss[50010]; LL gcd(LL x,LL y){return x%y==0? y:gcd(y,x%y); } int main(){n=read(),m=read(); sq=sqrt(n);for(int i=1;i<=n;i++) a[i]=read();for(int i=1;i<=m;i++)que[i].l=read(),que[i].r=read(), que[i].pos=i;sort(que+1,que+m+1,cmp);LL l=1,r=0,ans=0;for(int i=1;i<=m;i++){while(l<que[i].l){if(tong[a[l]]>0)ans-=tong[a[l]]*tong[a[l]];tong[a[l++]]--;if(tong[a[l-1]]>0)ans+=tong[a[l-1]]*tong[a[l-1]];}while(l>que[i].l){if(tong[a[l-1]]>0)ans-=tong[a[l-1]]*tong[a[l-1]];tong[a[--l]]++;if(tong[a[l]]>0)ans+=tong[a[l]]*tong[a[l]];}while(r<que[i].r){if(tong[a[r+1]]>0)ans-=tong[a[r+1]]*tong[a[r+1]];tong[a[++r]]++;if(tong[a[r]]>0)ans+=tong[a[r]]*tong[a[r]];}while(r>que[i].r){if(tong[a[r]]>0)ans-=tong[a[r]]*tong[a[r]];tong[a[r--]]--;if(tong[a[r-1]]>0)ans+=tong[a[r+1]]*tong[a[r+1]];}if(l==r||ans==r-l+1){anss[que[i].pos].fz=0; anss[que[i].pos].fm=1;continue;}LL g=gcd(ans-(r-l+1),(r-l+1)*(r-l));anss[que[i].pos].fz=(ans-(r-l+1))/g;anss[que[i].pos].fm=((r-l+1)*(r-l))/g;}for(int i=1;i<=m;i++)printf("%lld/%lld\n",anss[i].fz,anss[i].fm);return 0; }

轉載于:https://www.cnblogs.com/wxl-Ezio/p/9507912.html

總結

以上是生活随笔為你收集整理的国家集训队 小Z的袜子的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。