codefroces 297E Mystic Carvings
problem:
一个圆上依次有1~2*n的数字。每个数字都有且只有另一个数字与他相连。选出三条线,使得每条线的两端之间隔的最少点(只包括被选择的6个点)的个数相等。
输入输出格式
输入格式:
The first line contains integer n(3<=n<=10^5) — the number of lines.
Each of the following n n n lines contains two integers ai,bi (1<=ai,bi<=2n), which means that there is a line carved on the ice connecting the ai –th and bi –th endpoint.
It's guaranteed that each endpoints touches exactly one line.
输出格式:
Print the number of ways to build the caves.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
输入输出样例
输入样例#1:
4
5 4
1 2
6 7
8 3
输出样例#1:
2
输入样例#2:
8
1 7
2 4
3 9
5 11
6 8
10 16
13 15
14 12
输出样例#2:
6
说明
The second sample corresponds to the figure in the problem statement.
六个点三条边有以下五种可能:

明显只有第1个和第4个可以。但是这2个情况不好求
可以求出总方案再减去不合法方案
此题有两种写fa♂:
第一种是树状数组
假设当前直线i a->b(a<b)
在直线左边的直线数为x,右边的直线数为y,与i相♂蕉的直线数为z
显然有x+y+z+1=n
第3种情况就是x*y
第2,5种是(x+y)*z
但是因为每个点都有边连出,且圆上无蕉♂点
所以z=b-a-1-2*x
第二种是主席树,了解一下
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long lol;
lol c[],n,m;
int a[],b[],p[];
lol ans1,ans2,ans;
void add(int x,int d)
{
while (x<=m)
{
c[x]+=d;
x+=(x&(-x));
}
}
int query(int x)
{
int s=;
while (x)
{
s+=c[x];
x-=(x&(-x));
}
return s;
}
int main()
{int i;
cin>>n;
m=*n;
for (i=;i<=n;i++)
{
scanf("%d%d",&a[i],&b[i]);
p[a[i]]=b[i];
p[b[i]]=a[i];
}
for (i=;i<=m;i++)
{
if (i<p[i]) continue;
int x=query(i)-query(p[i]-);
int z=i-p[i]--x*;
add(p[i],);
int y=n--x-z;
ans1+=x*y;
ans2+=(x+y)*z;
}
ans=n*(n-)*(n-)/;
cout<<ans-ans1-ans2/;
}
codefroces 297E Mystic Carvings的更多相关文章
- [Codeforces 297E]Mystic Carvings
Description 题库链接 题面链接 Solution 这里给出主席树的版本.主席树维护直线的一个端点在前 \(i\) 个端点中,另一个端点在区间内的个数. Code //It is made ...
- Codeforces Round #180 (Div. 1 + Div. 2)
A. Snow Footprints 如果只有L或者只有R,那么起点和终点都在边界上,否则在两者的边界. B. Sail 每次根据移动后的曼哈顿距离来判断是否移动. C. Parity Game 如果 ...
- Codefroces 1328E Tree Querie(dfs序)
Codefroces 1328E Tree Querie 题目 给出一棵1为根,n个节点的树,每次询问\(k_i\) 个节点,问是否存在这样一条路径: 从根出发,且每个节点在这条路径上或者距离路径的距 ...
- Codefroces 750D:New Year and Fireworks(BFS)
http://codeforces.com/contest/750/problem/D 题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数. 思路:n = 3 ...
- Codefroces 750C:New Year and Rating(思维)
http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打 ...
- codefroces 589A
time limit per testsecondsmemory limit per testmegabytesinputstandard inputoutputstandard outputPoly ...
- create mystic by Django
See the sumary below figure : We going to talk each step ...more detail
- Codefroces Gym 100781A(树上最长路径)
http://codeforces.com/gym/100781/attachments 题意:有N个点,M条边,问对两两之间的树添加一条边之后,让整棵大树最远的点对之间的距离最近,问这个最近距离是多 ...
- codefroces 911G Mass Change Queries
题意翻译 给出一个数列,有q个操作,每种操作是把区间[l,r]中等于x的数改成y.输出q步操作完的数列. 输入输出格式 输入格式: The first line contains one intege ...
随机推荐
- JAVA和Android的回调机制
本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17483273),请尊重他人的辛勤劳动成果,谢谢 以 前不理解什么叫回 ...
- 自己写编程语言-m语言
一直对技术有很强的兴趣,终于,决定要写自己的语言(m语言).那就先从最简单的开始:解释执行器. 一套完整的语言包含的肯定不止解释执行器了,还要有编译器和IDE,也就还要有语法高亮.智能提示等,不过还没 ...
- sql2008r2,以前好好可以用的,但装了vs2017后,连接不上了,服务也停了,结果手动也 启动不了, 无法加载或初始化请求的服务提供程
日志: 2017-12-14 12:33:17.53 服务器 A self-generated certificate was successfully loaded for encryption.2 ...
- 机器学习中的K-means算法的python实现
<机器学习实战>kMeans算法(K均值聚类算法) 机器学习中有两类的大问题,一个是分类,一个是聚类.分类是根据一些给定的已知类别标号的样本,训练某种学习机器,使它能够对未知类别的样本进行 ...
- C# 使用 GDI+ 画图
最近做一个微信公众号服务,有一些简单的图片处理功能.主要就是用户在页面操作,前端做一些立刻显示的效果,然后提交保存时后端真正修改原图. 我们的后端是 ASP.NET,也就是 C# 语言了,C# 本身处 ...
- C语言头文件引用
1,引用分为两种 firs:include<fileName.h> 引用系统头文件一般用<>. second:include"fileName.h" 引用自 ...
- 可空类型 Nullable<T>
Nullable<T> 内部实现了显示和隐式转换 显示转换: public static explicit operator T(T? value) { return value.Valu ...
- SpringCloud应用入库后乱码问题
一.现象 1.请求 2.入库后 二.解决过程 1.配置application.properties 2.代码配置 3.数据库(关键!!) 3.请求 三.验证过程 1.win10 - 本地验证通过 2. ...
- kafka---broker 保存消息
1 .存储方式 物理上把 topic 分成一个或多个 patition(对应 server.properties 中的 num.partitions=3 配置),每个 patition 物理上对应一个 ...
- python全栈开发-hashlib模块(数据加密)、suprocess模块、xml模块
一.hashlib模块 1.什么叫hash:hash是一种算法(3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法 ...