AcWing 241. 楼兰图腾 (树状数组)打卡
题目:https://www.acwing.com/problem/content/description/243/
题意:给你n个点,问你 V 和 ^的图腾有多少个
思路:比如V 其实就是找当前点左边比自己大的点的个数,右边比自己大的个数,然后乘法原理组合一下,^也是一样的道理
#include<bits/stdc++.h>
#define maxn 200005
#define mod 1000000007
using namespace std;
typedef long long ll;
ll c[maxn];
ll l1[maxn],r1[maxn];
ll l2[maxn],r2[maxn];
ll a[maxn],n;
ll lowbit(ll x){
return x&(-x);
}
void add(ll x,ll y){
while(x<=n){
c[x]+=y;
x+=lowbit(x);
}
}
ll sum(ll x){
ll num=;
while(x){
num+=c[x];
x-=lowbit(x);
}
return num;
}
int main(){
scanf("%lld",&n);
for(int i=;i<=n;i++) scanf("%lld",&a[i]);
for(int i=;i<=n;i++){
l1[i]=sum(a[i]);
l2[i]=i-l1[i]-;
add(a[i],);
}
memset(c,,sizeof(c));
for(int i=n;i>=;i--){
r1[i]=sum(a[i]);
r2[i]=n-i-r1[i];
add(a[i],);
}
ll num1=,num2=;
for(int i=;i<=n;i++){
num2+=l1[i]*r1[i];
num1+=l2[i]*r2[i];
}
printf("%lld %lld",num1,num2);
}
AcWing 241. 楼兰图腾 (树状数组)打卡的更多相关文章
- AcWing 241.楼兰图腾 (树状数组,逆序对)
题意:在二维坐标轴上给你一些点,求出所有由三个点构成的v和∧图案的个数. 题解:因为给出的点是按横坐标的顺序给出的,所以我们可以先遍历然后求出某个点左边比它高和低的点的个数(这个过程简直和用树状数组求 ...
- AcWing 241 楼兰图腾 (树状数组)
在完成了分配任务之后,西部314来到了楼兰古城的西部. 相传很久以前这片土地上(比楼兰古城还早)生活着两个部落,一个部落崇拜尖刀('V'),一个部落崇拜铁锹('∧'),他们分别用V和∧的形状来代表各自 ...
- Luogu4528 CTSC2008 图腾 树状数组、容斥
传送门 设$f_i$表示$i$排列的数量,其中$x$表示不确定 那么$$ans=f_{1324}-f_{1432}-f_{1243}=(f_{1x2x}-f_{1423})-(f_{14xx}-f_{ ...
- [POI2011]MET-Meteors 整体二分_树状数组_卡常
线段树肯定会 TLE 的,必须要用树状数组. Code: // luogu-judger-enable-o2 #include <cstdio> #include <algorith ...
- AcWing 241. 楼兰图腾
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; typedef long long ll; ll ans,l ...
- 【BZOJ3295】【块状链表+树状数组】动态逆序对
Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依次删除m个元素,你的任务是在每次删除一个元素之前统计 ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...
- CodeForces–830B--模拟,树状数组||线段树
B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- AcWing 244. 谜一样的牛 (树状数组+二分)打卡
题目:https://www.acwing.com/problem/content/245/ 题意:有n只牛,现在他们按一种顺序排好,现在知道每只牛前面有几只牛比自己低,牛的身高是1-n,现在求每只牛 ...
随机推荐
- 用闭包解决 js 循环中函数变量暂存问题
需求:有一个数组,根据数组的值渲染对应的数字div,单击对应的div 在控制台打印对应的数字.如点击1,控制台打印1. 问题: 不管点击哪个值 打出来都是4 代码如下 <!DOCTYPE htm ...
- shallow update not allowed
! [remote rejected] master -> master (shallow update not allowed) https://stackoverflow.com/quest ...
- PHP-Redis扩展安装(四)
PHP-Redis扩展安装(四) 安装环境链接:http://pan.baidu.com/s/1i4IbJox Memecached 服务器安装(一) memcached php扩展(二) redis ...
- mysql null 值查询问题
我在开发公司内部的一个项目时遇到一个问题:select student_quality_id from STUDENT_QUALITY where mark_status=0 and batch_st ...
- 12. Jmeter-断言
jmeter-断言介绍与使用 性能测试中较少用到断言.断言会增加脚本执行时间,但是接口测试中断言是必备的.什么是断言?其实就是功能测试中常说的预期结果和实际结果是否相等. 响应断言 JSON Asse ...
- TypeError: write() argument must be str, not bytes报错
TypeError: write() argument must be str, not bytes 之前文件打开的语句是: with open('C:/result.pk','w') as fp: ...
- 2019PhpStrom注册码(破解)+汉化(中文)
PhpStrom破解使用 IDEA激活码: https://app.yinxiang.com/fx/bd2158ab-fea3-4382-966f-eaf54f5a4de7 phpStorm使用说明 ...
- 为什么要使用MQ和到底什么时候要使用MQ
一.缘起 一切脱离业务的架构设计与新技术引入都是耍流氓. 引入一个技术之前,首先应该解答的问题是,这个技术解决什么问题. 就像微服务分层架构之前,应该首先回答,为什么要引入微服务,微服务究竟解决什 ...
- BCrypt密码加密
快速入门 (1)我们从官网下载源码 BCrypt 官网 http://www.mindrot.org/projects/jBCrypt/ (2)新建工程,将源码类BCrypt拷贝到工程 (3)新建测试 ...
- 超強的Linux指令解釋網站《explainshell.com》,學Linux必備!
ExplainShell 官方網站:http://explainshell.com/ 原始碼下載:https://github.com/idank/explainshell 用瀏覽器打該explain ...