牛客网多校第5场 I vcd 【树状数组+离散化处理】【非原创】
题目:戳这里
学习博客:戳这里
作者:阿狸是狐狸啦
n个点,一个点集S是好的,当且仅当对于他的每个子集T,存在一个右边无限延长的矩形,使的这个矩形包含了T,但是和S-T没有交集。
求有多少个这种集合。
画图找规律可得
当我们求的集合中的点只有一个时,肯定满足要求 。
当有两个点且这两个点y坐标不相等也满足要求。
当有三个点组成一个小于号形状的集合S时,这个集合S的子集T一定与S-T无交集,当组成一个大于号时。我们取大于号左边的两个端点组成的T集合一定与右边的那个端点有交集。
当有四个点组成的S点集他一定存在一个子集T和S-T有交集。
所以我们计算小于等于三个点的情况就行了。
一的情况直接是n。
二的情况总的情况减去y坐标相等的点的情况就行了。
三的情况就是数一下有多少个小于号的情况,树状数组维护一下就行了。
附ac代码:
1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 #include <queue>
5 #include <stack>
6 #include <iostream>
7 using namespace std;
8 typedef long long ll;
9 const int maxn = 2 * 1e5 + 10;
10 const ll mod = 998244353;
11 struct nod
12 {
13 ll x;
14 ll y;
15 }coo[maxn];
16 ll cnt[maxn];
17 ll c[maxn<<2];
18 ll y[maxn];
19 ll n;
20 bool cmp(nod a, nod b)
21 {
22 return a.x > b.x;
23 }
24 ll pmul(ll a, ll b)
25 {
26 ll res = 0;
27 while(b)
28 {
29 if(b&1)
30 res = (res + a) % mod;
31 b >>= 1;
32 a = (a + a) % mod;
33 }
34 return res;
35 }
36 ll pmod(ll a, ll b)
37 {
38 ll res = 1;
39 while(b)
40 {
41 if(b&1)
42 res = pmul(res, a) % mod;
43 b >>= 1;
44 a = pmul(a, a) % mod;
45 }
46 return res;
47 }
48 ll gets(int x)
49 {
50 ll ans = 0;
51 while(x)
52 {
53 ans = (ans + c[x]) % mod;
54 x -= x & (-x);
55 }
56 return ans;
57 }
58 void updat(int x, ll ad)
59 {
60 while(x <= n)
61 {
62 c[x] = (c[x] + ad) % mod;
63 x += x & (-x);
64 }
65 }
66 int main() {
67
68 scanf("%d", &n);
69 for(ll i = 1; i <= n; ++i)
70 {
71 scanf("%d %d", &coo[i].x, &coo[i].y);
72 y[i] = coo[i].y;
73 }
74 sort(y + 1, y + 1 + n);
75 for(ll i = 1; i <= n; ++i)//这一步很有意思,把1e9的范围离散化到了1e5
76 {
77 ll u = lower_bound(y + 1, y + 1 + n, coo[i].y) - y;
78 coo[i].y = u;
79 ++cnt[u];
80 // printf("%d u\n", u);
81 }
82 sort(coo + 1, coo + 1 + n, cmp);
83 ll ans = n + n * (n - 1) / 2;
84 ans %= mod;
85 for(ll i = 1; i <= n; ++i)
86 {
87 ll u = cnt[i];
88 if(u)
89 ans = (ans - u * (u - 1) / 2) % mod;
90 }
91 ll up = 0, dw = 0;
92 ll now = 1;
93 for(ll i = 1; i <= n; ++i)
94 {
95 up = (gets(n) - gets(coo[i].y)) % mod;
96 dw = gets(coo[i].y - 1) % mod;
97 ans = (ans + up * dw % mod) % mod;
98 for(;coo[i].x != coo[i + 1].x && now <= i; ++now)
99 {
100 updat(coo[now].y, 1ll);
101 }
102 }
103 printf("%lld\n", ans % mod);
104 return 0;
105 }
牛客网多校第5场 I vcd 【树状数组+离散化处理】【非原创】的更多相关文章
- 牛客网多校训练第一场 I - Substring(后缀数组 + 重复处理)
链接: https://www.nowcoder.com/acm/contest/139/I 题意: 给出一个n(1≤n≤5e4)个字符的字符串s(si ∈ {a,b,c}),求最多可以从n*(n+1 ...
- 牛客多校第3场 J 思维+树状数组+二分
牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...
- 牛客网多校第3场C-shuffle card 平衡树或stl(rope)
链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there ...
- 牛客网多校第3场Esort string (kmp)
链接:https://www.nowcoder.com/acm/contest/141/E 来源:牛客网 题目描述 Eddy likes to play with string which is a ...
- 牛客网多校赛第九场A-circulant matrix【数论】
链接:https://www.nowcoder.com/acm/contest/147/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 牛客网多校训练第二场D Kth Minimum Clique
链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, fi ...
- 牛客网多校第5场 H subseq 【树状数组+离散化】
题目:戳这里 学习博客:戳这里 题意:给n个数为a1~an,找到字典序第k小的序列,输出该序列所有数所在位置. 解题思路:先把所有序列预处理出来,方法是设一个数组为dp,dp[i]表示以i为开头的序列 ...
- 牛客练习赛33 D tokitsukaze and Inverse Number (树状数组求逆序对,结论)
链接:https://ac.nowcoder.com/acm/contest/308/D 来源:牛客网 tokitsukaze and Inverse Number 时间限制:C/C++ 1秒,其他语 ...
- 牛客网多校第4场 J Hash Function 【思维+并查集建边】
题目链接:戳这里 学习博客:戳这里 题意: 有n个空位,给一个数x,如果x%n位数空的,就把x放上去,如果不是空的,就看(x+1)%n是不是空的. 现在给一个已经放过数的状态,求放数字的顺序.(要求字 ...
随机推荐
- Goby资产扫描工具安装及报错处理
官网: https://cn.gobies.org/index.html 产品介绍: 帮企业梳理资产暴露攻击面,新一代网络安全技术,通过为目标建立完整的资产数据库,实现快速的安全应急. 已有功能: 扫 ...
- 使用call、apply、bind继承及三者区别
js里的继承方法有很多,比如:使用原型链的组合继承.es6的Class.寄生继承以及使用call.apply.bind继承.再说继承之前,我们先简单了解下它们的区别. 一.区别: 同:三者都是改变函数 ...
- SEO大杀器rendertron安装
前段时间做SEO的优化,使用的是GoogleChrome/rendertron,发现这个安装部署的时候还是会有一些要注意的地方,做个记录 为什么要使用rendertron 目前很多网站都是使用 vue ...
- vue3.0 composition API
一.Setup函数 1.创建时间:组件创建之前被调用,优先与created被调用,this指向的实例为window,created所指向的实例为proxy 2.this指向:不会指向组件实例 3.参数 ...
- MariaDB(selec的使用)
--查询基本使用 -- 查询所有列 --select * from 表名 select * from students; --一定条件查询 select * from students whe ...
- 找出10000内的素数 CSP
"Problem: To print in ascending order all primes less than 10000. Use an array of processes, SI ...
- Jenkins部署web项目到Tomcat(热部署)
使用这个方式的话需要tomcat中有初始时Manage这个项目,本质上是通过http://ip:port/manager/html这个地址的上传接口进行上传,进行热部署(需要远程tomcat 必须开启 ...
- centos7+python3+selenium+chrome
一.安装GUI图形化界面 (1)安装GUI图形化界面 yum groupinstall "GNOME Desktop" "Graphical Administration ...
- xftp 提示无法显示远程文件夹
在用xftp远程服务器,打开文件夹的时候一直提示"无法显示远程文件夹" 解决方案: 1.网上大多解决方案是文件->属性->选项->将使用被动模式选项去掉即可 2. ...
- 信息: TLD skipped. URI: http://java.sun.com/jstl/* is already defined解决方法
整合Spring MVC由于用到jstl,所以假如jstl便签用的jar包,启动tomcat时控制台出现了如下的输出: standard.jar与jstl.jar一起使用,但是jstl 1.2版本的就 ...