https://www.nowcoder.com/acm/contest/143/I

vc-dimension

题解:分三种情况,组合数学算一下,其中一种要用树状数组维护

技巧(来自UESTC):1.循环技巧i主j滑

2.树状数组:一个数列从左到右分别维护某个元素左边比它大num的与右边比他大的num时,从上往下扫, 对每个点的x坐标离散化累加1到X轴上,然后就会发现sum(p[i].x-1)就是左边比它大的,i-1-sum(p[i])就是右边比它大的。 注意y相同的点,需要一起更新(我已开始一个一个更新,根本写不出来)

orz太屌了

坑点:我循环写错了+公式里i,j写反了,wa了20发

比赛时x,y轴都看反了orz

#define _CRT_SECURE_NO_WARNINGS
#include<cmath>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<stack>
#include<vector>
#include<string.h>
#include<queue>
#include<string>
#include<set>
using namespace std;
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a))
#define eps 1e-6
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
const int maxn = 3e5 + ;
const int inf = 1e7 + ;//0x7fffffff; //无限大
const int MOD = ;
typedef long long ll;
const int mod = ;
int power(int a, int b) {
int c = ; a %= mod;
while (b) {
if (b & ) c = 1ll * c*a%mod;
a = 1ll * a*a%mod; b >>= ;
}
return c;
} struct node {
int x, y;
void sc() { scanf("%d%d", &x, &y); }
}p[maxn]; int n;
bool cmp(node a, node b) {
return a.x > b.x;
} bool cmpy(node a, node b) {
return a.y < b.y;
} int f[maxn];
int idx;
void add(int x, int y) { for (; x <= idx; x += lowbit(x)) f[x] += y; }
int sum(int x) { int ans = ; for (; x; x -= lowbit(x)) ans += f[x]; return ans; } int main() {
int div2 = power(, mod - );
cin >> n;
rep(i, , n) {
p[i].sc();
}
int ans = n;
ans += 1ll*n * (n - )%mod*div2 % mod;
if (ans >= mod)ans -= mod; else if (ans < )ans += mod;
sort(p + , p + + n, cmpy);
idx = ;
for (int i = , j; i <= n; i = j + ) {
for (j = i ; j < n&&p[i].y == p[j+].y; j++);
++idx;
rep(k, i, j)p[k].y = idx;
ans -=1ll* (j - i)*(j - i + )%mod*div2%mod;
if (ans >= mod)ans -= mod; else if (ans < )ans += mod;
}
mmm(f, );
sort(p + , p + + n, cmp);
for (int i = , j; i <= n; i = j + ) {
for (j = i ; j < n&&p[i].x == p[j+].x; j++);
rep(k, i, j) {
int t1 = sum(p[k].y - ); int t2 = i - - sum(p[k].y);
ans += 1ll * t1*t2%mod;
if (ans >= mod)ans -= mod; else if (ans < )ans += mod;
}
rep(k, i, j)add(p[k].y, );
}
cout << ans << endl;
cin >> n;
return ;
} /* */

一开始无脑分别前后维护

#define _CRT_SECURE_NO_WARNINGS
#include<cmath>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<stack>
#include<vector>
#include<string.h>
#include<queue>
#include<string>
#include<set>
using namespace std;
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a))
#define eps 1e-6
#define pb push_back
const int maxn = 1e5 + ;
const int inf = 1e7 + ;//0x7fffffff; //无限大
const int MOD = ;
typedef long long ll;
const long long mod = ;
int power(int a,int b){
int c=; a%=mod;
while (b) {
if (b&) c=1ll*c*a%mod;
a=1ll*a*a%mod; b>>=;
}
return c;
} ll div2 = power(, mod - );
struct node {
int x, y;
int id;
void sc() { scanf("%d%d", &x, &y); }
}P[maxn]; ll n;
bool cmp(node a, node b) {
if (a.x != b.x)
return a.x < b.x;
else return a.y < b.y;
}
bool cmpx(node a, node b) {
if (a.x != b.x)
return a.x > b.x;
else return a.y < b.y;
} bool cmpy(node a, node b) {
return a.y < b.y;
}
int cnt[maxn];
ll l[maxn], r[maxn];
int d[maxn];
int lowbit(int x) { return x & (-x); }
int fr[maxn], bk[maxn];
void add(int x, int v) {//a[x]+=v;
while (x <= maxn) {
d[x] += v;
x += lowbit(x);
} }
int query(int x) {
int res = ;
while (x) {
res += d[x];
x -= lowbit(x);
}
return res;
} int main() {
cin >> n;
rep(i, , n) {
P[i].sc();
P[i].id = i;
}
sort(P + , P + n + , cmp); int idx = ;
int now = ;
rep(i, , n) {
if (P[i].x != now) {
cnt[++idx]++;
now = P[i].x;
}
else {
cnt[idx]++;
}
}
ll ans = n;
ll tmp = n * (n - ) %mod*div2;
rep(i, , idx)if (cnt[i] > ) { tmp = (tmp - cnt[i] * (cnt[i] - ) % mod *div2) % mod; }
ans = (ans + tmp) % mod;
//维护每个点左右比它高的点
sort(P + , P + n + , cmpy);
idx = ;
now = ;
rep(i, , n) {
if (P[i].y != now) {
P[i].y = ++idx;
now = P[i].y;
}
else {
P[i].y = idx;
}
}
sort(P + , P + n + , cmp);
now = ;
rep(i, , n)
{
if (P[i].x != P[i - ].x)fr[i] =now= i - ;
else fr[i] = now;
}
now = ;
per(i, n, )
{
if (P[i].x != P[i + ].x)bk[i] = now = i + ;
else bk[i] = now;
}
rep(i, , n) {
if(P[i].x!=P[i-].x)l[i] =ll( i--query(P[i].y));
else {
if (P[i].y >= P[fr[i]].y || P[i].y >= P[bk[i]].y)l[i] = ;
else l[i] = l[i - ];
}
add(P[i].y, );
}
mmm(d, );
//sort(P + 1, P + n + 1, cmpx);
int first = ;
per(i, n, ) {
if (P[i].x != P[i + ].x)r[i] = ll(n-i - query(P[i].y)),first=;
else {
if (P[i].y >= P[fr[i]].y || P[i].y >= P[bk[i]].y)r[i] = ;
else {
if (first)
{
first = ;
r[i] = ll(n - i -- query(P[i].y));
}
else r[i] = r[i + ];
}
}
add(P[i].y, );
}
tmp = ;
rep(i, , n) {
tmp = (tmp + l[i] * r[i] % mod) % mod;
}
ans = (ans + tmp) % mod;
cout << ans<<endl; //sort(P + 1, P + n + 1, cmp);
rep(i, , n) {
//cout << l[i] << ' ' << r[i] << endl;
}
cin >> n;
} /* */

【魔改】树状数组 牛客多校第五场I vcd 几何+阅读理解的更多相关文章

  1. 牛客多校第五场 F take

    链接:https://www.nowcoder.com/acm/contest/143/F来源:牛客网 题目描述 Kanade has n boxes , the i-th box has p[i] ...

  2. 2018牛客多校第五场 H.subseq

    题意: 给出a数组的排列.求出字典序第k小的b数组的排列,满足1<=bi<=n,bi<bi+1,a[b[i]]<a[b[i+1]],m>0. 题解: 用树状数组倒着求出以 ...

  3. 牛客多校第五场 F take 期望转化成单独事件概率(模板) 树状数组

    链接:https://www.nowcoder.com/acm/contest/143/F来源:牛客网 Kanade has n boxes , the i-th box has p[i] proba ...

  4. 牛客多校第五场-D-inv

    链接:https://www.nowcoder.com/acm/contest/143/D来源:牛客网 题目描述 Kanade has an even number n and a permutati ...

  5. 牛客多校第五场 J:Plan

    链接:https://www.nowcoder.com/acm/contest/143/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

  6. 牛客多校第五场 E room 二分图匹配 KM算法模板

    链接:https://www.nowcoder.com/acm/contest/143/E来源:牛客网 Nowcoder University has 4n students and n dormit ...

  7. 2019牛客多校第五场 F maximum clique 1 状压dp+最大独立集

    maximum clique 1 题意 给出一个集合s,求每个子集的最大独立集的权值和(权值是独立集的点个数) 分析 n比较小,一股浓浓的暴力枚举每一个子集的感觉,但是暴力枚举模拟肯定会T,那么想一想 ...

  8. 2019牛客多校第五场H - subsequence 2 拓扑

    H - subsequence 2 题意 要你使用前\(m\)个小写字母构造一个长度为\(n\)的字符串 有\(m*(m-1)/2\)个限制条件: \(c_{1} .c_{2}. len\):表示除去 ...

  9. 牛客多校第七场H Pair 数位dp理解

    Pair 题意 给出A B C,问x取值[1,A]和y取值[1,B]存在多少组pair<x,y>满足以下最小一种条件,\(x \& y >c\),\(x\) xor \(y& ...

随机推荐

  1. React Native 设置RGBA背景色

    React Native 设置RGBA背景色: 可以先用Mac自带吸色工具,获取RGB值,然后设置背景如下: backgroundColor: 'rgba(52, 52, 52, 0.8)', 透明度 ...

  2. easyui confirm提示框 调整显示位置

    方法一: $.messager.confirm("确认对话框","该客户已经存在!确定:查看该客户 ", function(r){ if(r){ alert(& ...

  3. 用VS2012建立core2.1网站项目后引用Microsoft.AspNetCore.Session不了

    做个.NET CORE的新项目,和往常一样,VS2017新建CORE项目(CORE2.1),NUGET引入session,结果引入不了,说什么版本不对应的,把SESSION降了一个版本,可以安装上了, ...

  4. 苹果App Store审核指南中文翻译(更新至140227)

    前言 感谢您付出宝贵的才华与时间来开发iOS应用程程序.从职业与报酬的角度而言,这对于成千上万的开发员来说一直都是一项值得投入的事业,我们希望帮助您加入这个成功的组织.我们发布了<App Sto ...

  5. 如何取消Visual Studio Browser Link

    VS2013.2015新建MVC网站并浏览后,页面默认自动启用Browser Link功能 解决方法,只需要在web.config中添加配置节点即可 <appSettings> <a ...

  6. 【发布iCore3&iCore4ADM资料】

    资料包说明: 1.解压资料包,里面有两个文件夹,iCore3和iCore4. iCore3文件夹里包含源代码及AD模块的详细资料. iCore4文件夹里仅有源代码,AD模块的详细资料参考iCore3里 ...

  7. js 上一步 下一步 操作

    <a id="syb" href="#" style="display: block;" class="btn button ...

  8. Oracle Grid 11.2.0.4 安装是出现"INS-30510: Insufficient number of ASM disks selected."

    最新文章:Virson's Blog 错误的原因是由于磁盘数和冗余层级不匹配: 如果创建用来存放OCR和VOTEDISK的ASM磁盘组,那么External.Normal.High三种冗余级别对应的F ...

  9. 【转】JS获取浏览器可视区域的尺寸

    from: http://www.xiaoboy.com/detail/1341545044.html 所谓可视区域是指能看得见的区域,即在浏览器中能看到页面的区域(高度与宽度).刚刚使用 docum ...

  10. 【转】燃烧吧,TestMice!

    ...当我们几个人碰面的时候,就感觉应该做点测试业内的实事. 记得当时的17站出了一些QTP辅件,给了我一些灵感.2008年做了一整年的QTP企业级实施,从方案到最后的收尾支持,得到最大的教训就是,当 ...