【BZOJ 2038】 [2009国家集训队]小Z的袜子(hose)
2016-03-10 19:02
393 查看
太神了!!
long long
long long
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> #define MAXN 1000000 #define INF 1000000000 #define MO 233333333 #define LL long long using namespace std; struct P { int L,R; int id; }team[50000+1]; LL a[50000+1]; LL num[50000+1]; LL ans[50000+1][2]; LL n,m; LL cnt; bool cmp(P a,P b) { if(a.L/cnt==b.L/cnt) return a.R<b.R; return a.L<b.L; } LL Gcd(LL x,LL y) { if(y==0) return x; return Gcd(y,x%y); } int main() { cin>>n>>m; for(LL i=1;i<=n;i++) scanf("%d",&a[i]); for(LL i=1;i<=m;i++) scanf("%d %d",&team[i].L,&team[i].R),team[i].id=i; cnt=sqrt(m); sort(team+1,team+m+1,cmp); LL L=1,R=1;num[a[1]]=1; LL ANS=1; for(LL i=1;i<=m;i++) { // cout<<team[i].L<<' '<<team[i].R<<endl; while(L<team[i].L) { ANS-=num[a[L]]*num[a[L]]; num[a[L]]--; ANS+=num[a[L]]*num[a[L]]; L++; } while(L>team[i].L) { L--; ANS-=num[a[L]]*num[a[L]]; num[a[L]]++; ANS+=num[a[L]]*num[a[L]]; } while(R<team[i].R) { R++; ANS-=num[a[R]]*num[a[R]]; num[a[R]]++; ANS+=num[a[R]]*num[a[R]]; } while(R>team[i].R) { ANS-=num[a[R]]*num[a[R]]; num[a[R]]--; ANS+=num[a[R]]*num[a[R]]; R--; } ans[team[i].id][0]=ANS-(R-L+1); ans[team[i].id][1]=(R-L+1)*(R-L+1-1); LL tmp=Gcd(ans[team[i].id][0],ans[team[i].id][1]); ans[team[i].id][0]/=tmp; ans[team[i].id][1]/=tmp; if(ans[team[i].id][0]==0) ans[team[i].id][1]=1; // cout<<'*'<<' '<<ans[team[i].id][0]<<' '<<ans[team[i].id][1]<<endl; } for(LL i=1;i<=m;i++) printf("%lld/%lld\n",ans[i][0],ans[i][1]); return 0; }
相关文章推荐
- 解决init: sys_prop: permission denied uid:1003 name:service.bootanim.exit问题
- 【BZOJ 3196】 Tyvj 1730 二逼平衡树
- 接下来的事
- 【BZOJ 1856】 [Scoi2010]字符串
- 【FZUOJ 2020】 组合
- 【BZOJ 1189】 [HNOI2007]紧急疏散evacuate
- 【BZOJ 3191】[JLOI2013]卡牌游戏
- 【BZOJ 1227】 [SDOI2009]虔诚的墓主人
- 【BZOJ 1088】 [SCOI2005]扫雷Mine
- 【BZOJ 1257】 [CQOI2007]余数之和sum
- 来吧,给自己提个醒,哭着复习一下当初没好好学习的内容。
- 博客开更!!
- 【BZOJ 1355】 [Baltic2009]Radio Transmission
- KMP模板
- 【BZOJ 1877】 [SDOI2009]晨跑
- 【BZOJ 2301】 单选错位
- 【BZOJ 1415】 [Noi2005]聪聪和可可
- iOS开发 提示框- UIAlertController(是UIAlertView和UIActionSheet的合二为一)
- cocos2d-x之物理引擎之碰撞监测
- CSS盒子模型