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的但是不太好写,由于题目的特殊要求每个矩形不会重贴所以只要这两个点 ...
随机推荐
- 20182335实验一《Linux基础与Java开发环境》
课程:<程序设计与数据结构> 班级: 1823 姓名: 李金泉 学号:20182335 实验教师:王志强 实验日期:2019年9月9日 必修/选修: 必修 1.实验内容 基于命令行和IDE ...
- MySQL中concat以及group_concat的使用
摘自:https://www.jianshu.com/p/43cb4c5d33c1 说明: 本文中使用的例子均在下面的数据库表tt2下执行: 一.concat()函数 1.功能:将多个字符串连接成一个 ...
- .net framework4.6项目的dll升级后,未找到方法“System.String.GetPathsOfAllDirectoriesAbove”解决
https://stackoverflow.com/questions/59276192/getpathsofalldirectoriesabove-cannot-be-evaluated-after ...
- sql 查询每天数据
一 表 内数据存的是 ‘2017-09-08 15:13:59’这样格式 表 customer_mate_follow 时间字段 created_at 1, SELECT ,) as day, C ...
- Oracle Mysql MSSql 三种数据库 随机查询 条 语句
1. Oracle,随机查询查询语句-20条 select * from ( select * from 表名 order by dbms_random.value ) where rownum ...
- 浅谈call apply bind的区别
这三个方法的用法非常相似,将函数绑定到上下文中,即用来改变函数中this的指向.举个例子: var zlw = { name: "zlw", sayHello: function ...
- SSLPinning简介,使用Xposed+JustTrustMe来突破SSL Pinning
0x00 前面 如果你是一干Web安全的,当你在测试目前大多数的手机APP应用程序时,你一定遇到过burpsuite无法抓到数据包的情况,开始你以为只是https的问题,但是当你使用了burpsuit ...
- python获取csv文本的某行或某列数据
#coding = 'utf-8' import csv # 使用list,只能读取列,而且是全文读取,csv.reader会自动把CSV内容生成数组 ''' df = csv.reader(open ...
- 应用安全 - 中间件 - Apache - Apache POI
CVE-2014-3529 Date2014 类型 注入XML外部实体访问外部实体资源或者读取任意文件 影响范围 Apache POI 3.10-FINAL及以前版本 复现 CVE-2016-5000 ...
- 远程连接Mysql报错 java.sql.SQLException:null,message from server ... is not allowed to connect
在MySQL命令行输入如下命令: use mysql; select host from user; update user set host ='%' where user ='root'; 然后重 ...