bzoj1145
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1145
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>
#include<bitset>
#include<vector>
#include<functional>
#include<deque>
#include<cctype>
#include<climits>
#include<complex>
//#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj using namespace std; typedef long long LL;
typedef double DB;
typedef pair<int,int> PII;
typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a))
#define mmcy(a,b) memcpy(a,b,sizeof(a))
#define re(i,a,b) for(i=a;i<=b;i++)
#define red(i,a,b) for(i=a;i>=b;i--)
#define fi first
#define se second
#define m_p(a,b) make_pair(a,b)
#define SF scanf
#define PF printf
#define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;}
template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;}
template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} const DB EPS=1e-;
inline int sgn(DB x){if(abs(x)<EPS)return ;return(x>)?:-;}
const DB Pi=acos(-1.0); inline int gint()
{
int res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
}
inline LL gll()
{
LL res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
} const int maxN=;
const LL Mod=; int N;
int a[maxN+];
LL l[maxN+],r[maxN+];
LL ans; LL tree[maxN+];
#define lowbit(a) (a&(-a))
inline void update(int a,LL v){for(;a<=N;a+=lowbit(a))tree[a]=(tree[a]+v)%Mod;}
inline LL ask(int a){LL res=;for(;a>=;a-=lowbit(a))res=(res+tree[a])%Mod;return res;} LL g[maxN+]; /*
f(1324)-f(1243)-f(1432)
=f(1x2x)-f(1423)-f(12xx)+f(1234)-f(14xx)+f(1423)
=f(1x2x)+f(1234)-f(12xx)-f(14xx)
=f(1x2x)+f(1234)-[f(1xxx)-f(13xx)]
=f(1x2x)+f(13xx)+f(1234)-f(1xxx)
*/ int main()
{
freopen("bzoj1145.in","r",stdin);
freopen("bzoj1145.out","w",stdout);
int i;
N=gint();
re(i,,N)a[i]=gint();
mmst(tree,);re(i,,N)l[i]=ask(a[i]-),update(a[i],);
mmst(tree,);red(i,N,)r[i]=ask(a[i]-),update(a[i],);
ans=; //+f(1x2x)
re(i,,N)g[i]=(LL(l[i])*LL(l[i]-)/+LL(l[i])*LL(i--l[i]))%Mod;
mmst(tree,);
re(i,,N)
{
g[i]=(g[i]-ask(a[i]-))%Mod;
update(a[i],i-);
}
re(i,,N)ans=(ans+g[i]*LL(N-i-r[i]))%Mod; //+f(13xx)
mmst(tree,);
red(i,N,)
{
LL t=LL(N-i-r[i]);
LL p=(ask(a[i]-)-r[i]*(r[i]-)/)%Mod;
ans=(ans+p*t)%Mod;
update(a[i],a[i]-);
} //+f(1234)
re(i,,N)g[i]=l[i];
mmst(tree,);re(i,,N)update(a[i],g[i]),g[i]=ask(a[i]-);
mmst(tree,);re(i,,N)update(a[i],g[i]),g[i]=ask(a[i]-);
re(i,,N)ans=(ans+g[i])%Mod; //-f(1xxx)
re(i,,N)
{
LL t=LL(N-i-r[i]);
ans=(ans-t*(t-)*(t-)/)%Mod;
} ans=(ans%Mod+Mod)%Mod;
cout<<ans<<endl;
return ;
}
bzoj1145的更多相关文章
- bzoj1145[CTSC2008]图腾
传送门 虽然是远古时期的ctsc,但是果然还是ctsc啊 前置芝士:树状数组 这个题最开始的思路很好想,由于之前写过一个类似处理的题,所以这个题我一开始就想到了思路. 首先,我们可以尝试讲图腾表示为x ...
- [bzoj1145]图腾
如果将关系用一个数字来表示(相等表示不确定),那么题目相当于要计算$1324-1243-1432$=$(1323-1423)-(1233-1234)-(1322-1423)$=$1323+1234-( ...
- [转载]hzwer的bzoj题单
counter: 664BZOJ1601 BZOJ1003 BZOJ1002 BZOJ1192 BZOJ1303 BZOJ1270 BZOJ3039 BZOJ1191 BZOJ1059 BZOJ120 ...
- BZOJ刷题列表【转载于hzwer】
沿着黄学长的步伐~~ 红色为已刷,黑色为未刷,看我多久能搞完吧... Update on 7.26 :之前咕了好久...(足见博主的flag是多么emmm......)这几天开始会抽时间刷的,每天几道 ...
随机推荐
- 《python源代码剖析》笔记 python中的Dict对象
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 1.PyDictObject对象 --> C++ STL中的map是基于RB-tre ...
- Mybatis高级映射、动态SQL及获得自增主键
一.动态SQL 相信大家在用mybatis操作数据库时时都会碰到一个问题,假如现在我们有一个关于作者的list authorList,需要根据authorList里已有的作者信息在数据库中查询相应作者 ...
- [React Testing] The Redux Store - Multiple Actions
When using Redux, we can test that our application state changes are working by testing that dispatc ...
- C++11 : variadic templates(可变参数模板)
Introduction: Before the possibilities of the new C++ language standard, C++11, the use of templat ...
- WPF之Binding的使用
引出: 在WPF中Binding可以比作数据的桥梁,桥梁的两端分别是Binding的源(Source)和目标(Target).一般情况下,Binding源是逻辑层对象,Binding目标是UI层的控件 ...
- Linux 数据 CD 刻录
http://www.cyberciti.biz/tips/linux-burning-multi-session-cds-on-linux.html #mkisofs -dvd-video -inp ...
- Sass函数--数字函数
数字函数简介 Sass 中的数字函数提要针对数字方面提供一系列的函数功能: percentage($value):将一个不带单位的数转换成百分比值: round($value):将数值四舍五入,转换成 ...
- C语言学习笔记---谭浩强
前段时间有机会去面试了一次,真是备受“打击”(其实是启发),总的来说就是让我意识到了学习工具和学习技术的区别.所以最近在看一些数据结构和算法,操作系统,python中的并行编程与异步编程等东西.然而数 ...
- asp.net 面试基础题
WebSite和WebApplication的区别1)当改变后台代码时,WebApplication需重启浏览器或者重新生成解决方案,而WebSite则不用:2)WebSite没有Solution,没 ...
- 掌众android面试题
1,android动画分类? http://www.cnblogs.com/angeldevil/archive/2011/12/02/2271096.html 2,android service启动 ...