牛客网多校第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是不是空的. 现在给一个已经放过数的状态,求放数字的顺序.(要求字 ...
随机推荐
- uni-app开发经验分享四: 实现文字复制到选择器中
这里分享一个我经常用到的一个方法,主要是用来复制文字内容,具体代码如下: var that=this; if(!document){ uni.setClipboardData({ data:复制的值, ...
- 【分享】每个 Web 开发者在 2021 年必须拥有 15 个 VSCode 扩展
为什么VSCode如此受欢迎 Visual Studio Code在开发人员中迅速流行起来,它是最流行的开发环境,可定制性是其流行的原因之一. 因此,如果你正在使用VSCode,这里有一个扩展列表,你 ...
- 手写Netty之多路复用Select小案例
注意:本文只是将上文多路复用器Select.Poll.Epoll区别梳理中提出的概念与Netty中的步骤联系起来,方便后面回顾,代码中注释很多,对于大家来说如果不是怀有同样的目的,不一定有用. 单线程 ...
- 解决 minicom 不能接收键盘输入问题
今天突然minicom 不能接受键盘输入了.早上的时候在其他设备上不能识别usb转串口的设备,重新启动电脑后,恢复正常了.下午又出现minicom 不接收键盘输入. 百度了一下解决了. 解决方法 由于 ...
- 新编日语1234册/重排本/全册 pdf
网上找的资源链接大部分都失效了,无奈之下只好淘宝购买.顺便分享一下吧. 链接: https://pan.baidu.com/s/1v5-osHKrIPzlgpd8yNIP5Q 提取码: kexn
- In Search of an Understandable Consensus Algorithm" (https://raft.github.io/raft.pdf) by Diego Ongaro and John Ousterhout.
In Search of an Understandable Consensus Algorithm" (https://raft.github.io/raft.pdf) by Diego ...
- celery 动态配置定时任务
How to dynamically add or remove tasks to celerybeat? · Issue #3493 · celery/celery https://github.c ...
- LOJ10069 TREE
题目描述 原题来自:2012 年国家集训队互测 给你一个无向带权连通图,每条边是黑色或白色.让你求一棵最小权的恰好有 need 条白色边的生成树.题目保证有解. 输入格式 第一行 V,E,need 分 ...
- Typora使用与GItHhub图床配置
Typora使用 (windows) 1 快捷键 1.1 表格 快捷方式:CTRL+T ID name year 1 Oracle 10 2 Mysql 10 3 Postgresql 20 1.2 ...
- 基于navicat的数据库导入导出
1.右键当前数据库,选择转储SQL文件 选择导出sql的存放路径 2.新建统一命名的数据库,右键运行SQL文件 3,.选择要导入的SQL文件后如图