Codeforces 961 容斥叉积判共线 树状数组递增思想题
A
B
C
D
给你N个点 问你能不能有两条直线穿过这N个点
首先假设这N个点是可以被两条直线穿过的 所以两条直线就把这N个点划分成两个集合
我们取1 2 3三个点这样必定会有两个点在一个集合内 check一下 如果不满足输出NO
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int n;
struct Point
{
ll x, y;
Point operator - (const Point& p) const
{
return {x - p.x, y - p.y};
}
} p[];
inline bool cross(Point a, Point b)
{
return a.y * b.x == a.x * b.y;
}
inline bool collinear(int x, int y, int z)
{
return cross(p[x] - p[y], p[x] - p[z]);
}
int check(int x, int y)
{
vector<int> todo;
for (int i = ; i <= n; i++)
{
if (!collinear(x, y, i))
{
todo.pb(i);
}
}
if (todo.size() <= )
{
return ;
}
int now1, now2;
now1 = todo[], now2 = todo[];
for (auto i : todo)
{
if (!collinear(now1, now2, i))
{
return ;
}
}
return ;
}
int main()
{
cin >> n;
for (int i = ; i <= n; i++)
{
scanf("%lld %lld", &p[i].x, &p[i].y);
}
if (n <= )
{
cout << "YES" << endl;
return ;
}
int flag = ;
flag |= check(, );
flag |= check(, );
flag |= check(, );
if (flag)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return ;
}
E
给你N个系列的电视剧 第i个系列有ai集 问你a[i]>=j&&a[j]>=i 这样的对数有多少对
考察一个递增思想 我们i从1循环到N 删去树状数组里集数为i的 这样下一次求的时候数组里就都是满足条件的了(开始的时候因为条件ai>=1 所以update(i,1))
(ai=min(ai,n) ai大于N的时候直接可以赋成N)
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll n;
ll num[];
ll t[];
vector<int> number[];
int lowbit(int x)
{
return x & (-x);
}
void update(int x, ll p)
{
while (x <= n)
{
t[x] += p;
x += lowbit(x);
}
return;
}
ll sum(int k)
{
ll ans = ;
while (k > )
{
ans += t[k];
k -= lowbit(k);
}
return ans;
}
int main()
{
cin >> n;
for (int i = ; i <= n; i++)
{
scanf("%lld", &num[i]);
num[i] = min(num[i], n);
number[num[i]].pb(i);
update(i, );
}
ll anser = ;
for (int i = ; i <= n; i++)
{
anser += sum(num[i]);
for (auto j : number[i])
{
update(j, -);
}
}
for (int i = ; i <= n; i++)
{
if (num[i] >= i)
{
anser--;
}
}
cout << anser / << endl;
return ;
}
Codeforces 961 容斥叉积判共线 树状数组递增思想题的更多相关文章
- poj 3321:Apple Tree(树状数组,提高题)
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18623 Accepted: 5629 Descr ...
- hdu 1541/poj 2352:Stars(树状数组,经典题)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- Codeforces 703D Mishka and Interesting sum(树状数组+扫描线)
[题目链接] http://codeforces.com/contest/703/problem/D [题目大意] 给出一个数列以及m个询问,每个询问要求求出[L,R]区间内出现次数为偶数的数的异或和 ...
- CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组
题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点 ...
- Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化
D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...
- CodeForces 380C Sereja and Brackets(扫描线+树状数组)
[题目链接] http://codeforces.com/problemset/problem/380/C [题目大意] 给出一个括号序列,求区间内左右括号匹配的个数. [题解] 我们发现对于每个右括 ...
- Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】
任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...
- Codeforces 703D Mishka and Interesting sum 离线+树状数组
链接 Codeforces 703D Mishka and Interesting sum 题意 求区间内数字出现次数为偶数的数的异或和 思路 区间内直接异或的话得到的是出现次数为奇数的异或和,要得到 ...
- codeforces 869 E. The Untended Antiquity(树状数组)
题目链接:http://codeforces.com/contest/869/problem/E 题解:这题是挺好想到solution的但是不太好写,由于题目的特殊要求每个矩形不会重贴所以只要这两个点 ...
随机推荐
- k8s中pod内dns无法解析的问题
用k8s创建了pod,然后进入pod后,发现在pod中无法解析www.baidu.com,也就是出现了无法解析外面的域名的问题.经过高人指点,做个小总结.操作如下. 一,将CoreDNS 的Confi ...
- 图的普里姆(Prim)算法求最小生成树
关于图的最小生成树算法------普里姆算法 首先我们先初始化一张图: 设置两个数据结构来分别代表我们需要存储的数据: lowcost[i]:表示以i为终点的边的最小权值,当lowcost[i]=0说 ...
- gitblit 数据迁移(复制)
gitblit 数据迁移 完全拷贝方式: 将原服务器上的gitblit的安装目录.数据目录等相关目录拷到另一台服务器上即可,这样启动方式和使用端口及数据和原服务上的一模一样.(因为gitblit是不用 ...
- POJ 1625 Censored ( Trie图 && DP && 高精度 )
题意 : 给出 n 个单词组成的字符集 以及 p 个非法串,问你用字符集里面的单词构造长度为 m 的单词的方案数有多少种? 分析 :先构造出 Trie 图方便进行状态转移,这与在 POJ 2278 中 ...
- java7和java8新特性
以下来至网址: http://blog.csdn.net/samjustin1/article/details/52268004 Java7 新特性 1.switch中可以使用字符串了 String ...
- Openstack 实现技术分解 (3) 开发工具 — VIM & dotfiles
目录 目录 前文列表 扩展阅读 前言 插件管理 Vundle 主题 Solarized 浏览项目目录结构 Nerdtree Symbol 窗口 Tagbar 文件模糊查询 CtrlP 代码补全 You ...
- Unity ZTest 深度测试 & ZWrite 深度写入
初学Shader,一开始对于渲染队列,ZTest 和 ZWrite一头雾水,经过多方查阅和实验,有了一些自己的理解.发此文与初学Shader的朋友分享,也算是为自己做个笔记.不对或不足之处欢迎指正. ...
- vimiumC的下载、配置与节点个性化
vimium是chrome的一款扩展程序,正如其名:vim+chromium,它能让你在浏览网页时双手不离开键盘,是提上网高效率的神器. 最近在使用中,非常便捷高效,但关于节点的个性化资料比较少,自己 ...
- 【MM系列】SAP MM模块-打开前面物料账期的方法
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]在SAP里查看数据的方法 前言部 ...
- CF 686D. Kay and Snowflake
给你一个树N个点,再给出Q个询问,问以x为根的子树中,重心是哪个?2≤n≤300000,1≤q≤30000 Sol:从下到上,根据性质做一下.1:如果某个点x,其子树y的大小超过总结点个数一半,则重心 ...