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的更多相关文章

  1. [Codeforces 297E]Mystic Carvings

    Description 题库链接 题面链接 Solution 这里给出主席树的版本.主席树维护直线的一个端点在前 \(i\) 个端点中,另一个端点在区间内的个数. Code //It is made ...

  2. Codeforces Round #180 (Div. 1 + Div. 2)

    A. Snow Footprints 如果只有L或者只有R,那么起点和终点都在边界上,否则在两者的边界. B. Sail 每次根据移动后的曼哈顿距离来判断是否移动. C. Parity Game 如果 ...

  3. Codefroces 1328E Tree Querie(dfs序)

    Codefroces 1328E Tree Querie 题目 给出一棵1为根,n个节点的树,每次询问\(k_i\) 个节点,问是否存在这样一条路径: 从根出发,且每个节点在这条路径上或者距离路径的距 ...

  4. Codefroces 750D:New Year and Fireworks(BFS)

    http://codeforces.com/contest/750/problem/D 题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数. 思路:n = 3 ...

  5. Codefroces 750C:New Year and Rating(思维)

    http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打 ...

  6. codefroces 589A

    time limit per testsecondsmemory limit per testmegabytesinputstandard inputoutputstandard outputPoly ...

  7. create mystic by Django

    See the sumary below figure : We going to talk each step ...more detail

  8. Codefroces Gym 100781A(树上最长路径)

    http://codeforces.com/gym/100781/attachments 题意:有N个点,M条边,问对两两之间的树添加一条边之后,让整棵大树最远的点对之间的距离最近,问这个最近距离是多 ...

  9. codefroces 911G Mass Change Queries

    题意翻译 给出一个数列,有q个操作,每种操作是把区间[l,r]中等于x的数改成y.输出q步操作完的数列. 输入输出格式 输入格式: The first line contains one intege ...

随机推荐

  1. Leetcode 12——Integer to Roman

    12.Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be withi ...

  2. I know 项目Alpha冲刺随笔集

    Alpha冲刺 Day 1 Alpha冲刺 Day 2 Alpha冲刺 Day 3 Alpha冲刺 Day 4 Alpha冲刺 Day 5 Alpha冲刺 Day 6 Alpha冲刺 Day 7 Al ...

  3. Python处理图片缩略图

    CPU 密集型任务和 IO 密集型任务分别选择多进程multiprocessing.Pool.map 和多线程库multiprocessing.dummy.Pool.map import os imp ...

  4. itchat 微信的使用

    #coding=utf8 import itchat # 自动回复 # 封装好的装饰器,当接收到的消息是Text,即文字消息 @itchat.msg_register('Text') def text ...

  5. Struts2之配置文件中Action的详细配置

    在Struts2之配置一文中,我们知道一个struts配置文件可以分为三部分:常量配置    包含其他配置文件的配置    Action配置  . 这其中 常量配置  和 包含其他配置文件的配置  二 ...

  6. ThinkPad安装deepin操作系统报错解决方法

    目前deepin操作系统,软件也比较多,所以想在自己的thinkpad t430笔记本上安装.但是安装时报错,具体错误忘了看了.反复试了好几次都不行,最后在网上查了,讲bios设置调整之后可以正常安装 ...

  7. postcss的安装与使用

    我是经过公司另外一个同事推荐的这个 他是一个资深的大哥哥  我觉得我确实需要跟多的学习和成长 而且我觉得我应该听他的话 多学学新知识 最近一直在做适配的网站 会出现很多媒体查询 我发现用这个写媒体查询 ...

  8. 关于读取Sql Server数据库时间前端处理问题

    var time = this.CreateTime; this.CreateTime = new Date(time.replace("T", " ")).F ...

  9. c++中模板是什么?为什么要定义模板?

    一.c++中模板是什么? 首先: int Max(int x, int y) { return x > y ? x : y; } float Max(float a,float b) { ret ...

  10. java double相加

    public class DoubleUtil { private static final int DEF_DIV_SCALE = 10; /** * 相加 * * @param d1 * @par ...