分析

对于每一个点只要维护它前面/后面的一小一大组合的数量

对于这个可以维护两个树状数组

然后从前往后/从后往前分别扫一遍相乘即可

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define int long long
const int mod = ;
#define add(x,y) x=(x+y)%mod
#define del(x,y) (x-y+mod)%mod
inline int lb(int x){return x&(-x);}
int a[],b[],sum1[],sum2[],h[],n,m;
inline void add_a(int x,int k){while(x<=m)add(a[x],k),x+=lb(x);return;}
inline void add_b(int x,int k){while(x<=m)add(b[x],k),x+=lb(x);return;}
inline int q_a(int x){int res=;while(x)add(res,a[x]),x-=lb(x);return res;}
inline int q_b(int x){int res=;while(x)add(res,b[x]),x-=lb(x);return res;}
signed main(){
int i,j,k;
scanf("%lld",&n);
for(i=;i<=n;i++){
scanf("%lld",&h[i]);
m=max(m,h[i]);
}
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(i=;i<=n;i++){
add_a(h[i],);
add_b(h[i],del(q_a(m),q_a(h[i])));
sum1[i]=q_b(h[i]-);
}
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(i=n;i>;i--){
add_a(h[i],);
add_b(h[i],del(q_a(m),q_a(h[i])));
sum2[i]=q_b(h[i]-);
}
int ans=;
for(i=;i<=n;i++)
ans=(ans+1ll*sum1[i]*sum2[i]%mod)%mod;
cout<<ans<<"\n";
return ;
}

牛客提高D3t2 点与面的更多相关文章

  1. 牛客提高集训营6 C 树(树链剖分)

    题目链接 为了纪(zhuang)念(bi)写完这个树剖单独写一篇.感觉还好,也就6k嘛. 完整比赛题解:https://www.cnblogs.com/SovietPower/p/9826829.ht ...

  2. 牛客提高R5 A.同余方程

    题意 题目链接 Sol 设\(solve(x, y)\)表示\(i \in [0, x], j \in [0, y]\)满足题目要求的方案数 首先容斥一下,\(ans = solve(r_1, r_2 ...

  3. 牛客提高D6t3 分班问题

    分析 就就就是推柿子 看官方题解吧/px 代码 #include<iostream> #include<cstdio> #include<cstring> #inc ...

  4. 牛客提高D6t2 破碎的序列

    分析 我们不难发现对于偶数的情况只要相邻两个数不相等即可 而对于奇数的情况只要中间恰好隔一个数的两个数不相等即可 于是我们又dp[i][0/1]表示考虑到第i位,这一位和它后面离它最近的一个确定的数是 ...

  5. 牛客提高D6t1 积木大赛

    分析 每次修改用二位差分记录一下 之后对于三维分别统计即可 代码 #include<iostream> #include<cstdio> #include<cstring ...

  6. 牛客提高D5t1 deco的abs

    分析 傻子题? 对d取模后随便贪心即可 代码 #include<iostream> #include<cstdio> #include<cstring> #incl ...

  7. 牛客提高D4t3 清新题

    分析 树上从下往上线性基合并即可 并不需要启发式/xyx 代码 #include<iostream> #include<cstdio> #include<cstring& ...

  8. 牛客提高D4t2 卖羊驼

    分析 不难想到dp[i][j]表示前i个数分了j组的最大值 我们发现这个dp状态有决策单调性 g[i][j]表示对于第i个数它的第j位最近出现的位置 每次一定从这些点转移 预处理即可 似乎还可以做到1 ...

  9. 牛客提高D4t1 麻将

    分析 我们对于每一个点记录他所在的这一行以它为右端点向前最多有几个连续的1 之后我们考虑每一列 对每一列的点按照之前求出的值从小到大排序 一次考虑每一个宽度 而高度也可以很容易的求出 每次取最大值即可 ...

随机推荐

  1. 接口框架 python+unittest+request+HTMLTestRunner

    request的各种方法主要用来处理客户端浏览器提交的请求中的各项参数和选项.如POST,GET最常用的两种请求 官方文档:http://docs.python-requests.org/en/mas ...

  2. Kotlin学习(2)函数

    函数声明: fun plus(a:Int,b:String):Boolean{ //fun 函数名(参数名:参数类型,参数名:参数类型):返回值类型 println(a) return true // ...

  3. React Hooks实现异步请求实例—useReducer、useContext和useEffect代替Redux方案

    本文是学习了2018年新鲜出炉的React Hooks提案之后,针对异步请求数据写的一个案例.注意,本文假设了:1.你已经初步了解hooks的含义了,如果不了解还请移步官方文档.(其实有过翻译的想法, ...

  4. 问题 H: 小k的简单问题

    问题 H: 小k的简单问题 时间限制: 1 Sec  内存限制: 128 MB提交: 107  解决: 57[提交] [状态] [命题人:jsu_admin] 题目描述 地图上有n个村庄,小k每个月需 ...

  5. C# <T>泛型的使用

    在定义泛型类时,可以对客户端代码能够在实例化类时用于类型参数的类型种类施加限制.如果客户端代码尝试使用某个约束所不允许的类型来实例化类,则会产生编译时错误.这些限制称为约束.约束是使用 where 上 ...

  6. C# DataTable与实体的相互转换

    using System; using System.Collections.Generic; using System.Data; using System.Reflection; namespac ...

  7. k3 cloud工程量清单调整后工程量为零行设置为黄色

    #引入clr运行库 import clr #添加对cloud插件开发的常用组件的引用 clr.AddReference('Kingdee.BOS') clr.AddReference('Kingdee ...

  8. 微信小程序的短信接口

    使用聚合数据 (网址)  https://www.juhe.cn/docs? 注册部分略! 这是登录部分的. 一: 二.我的接口

  9. linux grep 设置高亮显示

    [root@eric ~]# vi /etc/profile alias grep='grep --color=auto' [root@eric ~]# source /etc/profile

  10. linux ssh 服务优化

    linux 默认管理员 root,port 端口号是 22,为了安全,我们要改掉默认的管理员和端口 配置文件/etc/ssh/sshd_config [root@oldboy ~]# vi /etc/ ...