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 ...
随机推荐
- CSS的盒子模型有哪些,区别是什么
1)盒模型: 内容(content).填充(padding).边界(margin). 边框(border) 2)有两种, IE 盒子模型.标准 W3C 盒子模型:IE的content部分包含了 b ...
- java编程思想笔记(1)
java编程思想笔记(1) 一,对象的创建和生命周期 对象的数据位于何处?怎样控制对象的生命周期? 在堆(heap)的内存池中动态地创建对象. java完全采用了动态内存分配方式. 二,垃圾回收器 自 ...
- Leetcode 28——Implement strStr()
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...
- 【Alpha版本】冲刺阶段 - Day5 - 破浪
今日进展 袁逸灏:解决音乐播放问题以及跳转问题.(5h) 刘伟康:大致检查了测试规范,参考了其他 alpha 阶段的博客.(1h) 刘先润:解决了敌车与障碍物溢出边界的代码问题,给用户车辆增加了火焰喷 ...
- Django 测试驱动开发
第一章 1.编写functional_tests.py from selenium import webdriver browser = webdriver.Firefox() browser.get ...
- 使用 HttpClient 请求 Web Api
1.获取 post 请求 body 内容 [HttpPost] public string GetId() { //如果方法参数里面有 [FromBody],则需要重新调整内容指针,再进行读取. // ...
- aws - shadow 影子使用
参考链接: https://github.com/aws/aws-iot-device-sdk-java 一.设备注册 二.设备主题
- global文件中的application_start方法中做: 定时器
<%@ Application Language="C#" %> <%@ import Namespace="System.Data" %&g ...
- spring5——Aop的实现原理(动态代理)
spring框架的核心之一AOP,面向切面编程是一种编程思想.我对于面向切面编程的理解是:可以让我们动态的控制程序的执行流程及执行结果.spring框架对AOP的实现是为了使业务逻辑之间实现分离,分离 ...
- Python入门之ATM+购物车代码版思维导图
该项目结合了ATM模版和购物车需求,整个思维导图用Python代码实现,使用思维导图可以清晰明了的看清整个框架: 过程中,用到了Python的知识有Python常用模块,Python常用内置包,log ...