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......)这几天开始会抽时间刷的,每天几道 ...
随机推荐
- 行内人解读开发一个App需要多少钱?
对于很多互联网的创业者来说,评估前期的创业成本是很重要的.在这几年的创业大潮中,伴随着“互联网+”和“互联网思维”的普及,很多创业项目选择了开发app作为创业项目的载体.在我接触到的很多创业者,找Ap ...
- Ubuntu 下配置Samba 实现Linux和windows之间文件共享
一 Samba 的安装: sudo apt-get insall sambasudo apt-get install smbfs 二 在Ubuntu中创建共享目录: mkdir /home/shar ...
- StackPanel 弹出菜单 ContextMenu
<StackPanel x:Name="stackpanel_zonghe" Margin="0,10,0,0" Background="Tra ...
- mysql中的unique
distinct可以把重复的行去掉,查询时候用select distinct * from ...; unique在MySQL中是完整性约束里的一种,如果某列的值需要是唯一的那么就添加UNIQUE约束 ...
- cURL中的超时设置
访问HTTP方式很多,可以使用curl, socket, file_get_contents() 等方法. 在访问http时,需要考虑超时的问题. CURL访问HTTP: CURL 是常用的访问HTT ...
- javascript中闭包的真正作用
参考阮一峰的文章:http://javascript.ruanyifeng.com/grammar/function.html#toc23 1. 读取函数内部变量,封装一些私有属性 function ...
- hibernate 一对多双向关联 详解
一.解析: 1. 一对多双向关联也就是说,在加载班级时,能够知道这个班级所有的学生. 同时,在加载学生时,也能够知道这个学生所在的班级. 2.我们知道,一对多关联映射和多对一关联映射是一样的,都是在 ...
- hdu2795Billboard(线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=2795 单点更新,树存储的为某一行内剩余的长度 // File Name: hdu2795.cpp // Auth ...
- Ignatius and the Princess III --undo
Ignatius and the Princess III Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (J ...
- 高性能Java Web 页面静态化技术
package com.yancms.util; import java.io.*; import org.apache.commons.httpclient.*; import org.apache ...