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 ...
随机推荐
- MySQL数据库操作类(PHP实现,支持连贯操作)
<?php /** * Author: suvan * CreateTime: 2018/2/27 * description: 数据库操作类(仅对接MySQL数据库,主要利用MySQLi函数) ...
- JavaScript(第二十六天)【表单处理】
为了分担服务器处理表单的压力,JavaScript提供了一些解决方案,从而大大打破了处处依赖服务器的局面. 一.表单介绍 在HTML中,表单是由<form>元素来表示的,而在JavaS ...
- 201621123043 《Java程序设计》第2周学习总结
1.本周学习总结 使用jdk文档查阅函数功能及代码 用switch语句是在每个case中可能在第一行是sc.nextLine;来给回车赋值: 在使用循环的时候要注意循环返回的条件,否则陷入死循环可能会 ...
- JVM启动参数
JVM参数的含义 实例见实例分析 参数名称 含义 默认值 -Xms 初始堆大小 物理内存的1/64(<1GB) 默认(MinHeapFreeRatio参数可以调整)空余堆内存小于40%时,J ...
- 《高级软件测试》JIRA使用手册(一)JIRA基本情况
JIRA 官方网站为:https://www.atlassian.com/software/jira 中文代理网站为:https://www.jira.cn 现版本:v7.3.0 Atlassian公 ...
- JVM笔记7-内存分配与回收策略
1.对象优先在Eden分配 大多数情况下,对象在新生代Eden区中分配.当Eden区中没有足够空间分配时,虚拟机将发起一次Minor GC.虚拟机提供了-XX:PrintGCDetails 这个收集器 ...
- postcss的安装与使用
我是经过公司另外一个同事推荐的这个 他是一个资深的大哥哥 我觉得我确实需要跟多的学习和成长 而且我觉得我应该听他的话 多学学新知识 最近一直在做适配的网站 会出现很多媒体查询 我发现用这个写媒体查询 ...
- 关于读取Sql Server数据库时间前端处理问题
var time = this.CreateTime; this.CreateTime = new Date(time.replace("T", " ")).F ...
- linux下执行java类(运行java定时器)
假如有一个定时器TimerTest.java import java.io.IOException; import java.util.Timer; public class TimerTest { ...
- 新概念英语(1-25)Mrs. Smith's Kitchen
What colour is the electric cooker? Mrs. Smith's Kitchen is small. There is a refrigerator in the ki ...