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......)这几天开始会抽时间刷的,每天几道 ...
随机推荐
- 【转】Mac访问Windows共享文件夹
相信大多数的用户用Windows访问Windows的共享文件夹是一件很容易的事,但是如果用Mac来访问Windows共享文件夹就会遇到很多的麻烦了,尤其是设置是比较有区别的吗,接下来的将用图文交大家怎 ...
- php防sql注入、xss
php自带的几个防止sql注入的函数http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2013/0318/12234.html addslashe ...
- cnBlogs_代码着色
一个程序员当然希望写出来的代码不仅质量上好,而且看上去也很好.以前在网络上看见别人写的代码,着色以及背景都好极了,很是羡慕,但就是不知道如何设置 --------------------------- ...
- [React] React Router: Named Components
In this lesson we'll learn how to render multiple component children from a single route. Define a n ...
- 字符串数组越界bug(2)
概述 数组下标从0開始,尽管从初学都已经知道,<陷阱与缺陷>重复强调,而在指尖运动中,就有那么几次不小心,让"精子"掉进这个"洞里"!其次,C语言字 ...
- Redmine backlogs 升级
刚装完1.0.3两天,1.0.4发布了,乘项目还没有开始,赶快升级.升级过程 1.设置环境变量: RAILS_ENV=production export RAILS_ENV 2. 获取最新代码: cd ...
- Java基础知识强化63:Arrays工具类之方法源码解析
1. Arrays工具类的sort方法: public static void sort(int[] a): 底层是快速排序,知道就可以了,用空看. 2. Arrays工具类的toString方法底层 ...
- Python字符串方法
capitalize() 把字符串的第一个字符改为大写 casefold() 把整个字符串的所有字符改为小写 center(width) 将字符串居中,并使用空格填充至长度 width 的新字符串 c ...
- jquery之onchange事件
$(function(){ $("#opreateHtml").window("close"); $("#deliveryGrid").da ...
- 什么是工程师文化?各位工程师是为什么活的?作为一个IT或互联网公司为什么要工程师文化?
为什么要工程师文化? 看看最近二十年来社会的发展,计算机和互联网已经渗透到了这个社会的每一个角落,各式各样的计算机技术成为了整个世界发展的强大引擎,各式各样的创新,无论是业务创新还是技术创新,都是依托 ...