ZR7.17
7.17
F
认真读题吧
A
算法一:
\(c = ab,x = a + b + c\)
所以
\(x = a + b + ab\)
\(=(b + 1)a + b\)
所以我们枚举\(b\)
\(O(1)\)check了
但是这样是\(O(x)\)的
之后我们由
\(x = a + b + ab\)可得
\(ab<=x\)
由于\(a,b\)本质相同
所以\(min(a,b)<=\sqrt{x}\)
所以我们枚举到\(\sqrt{x}\)就好了
算法二:
我们由\(x = a + b + ab\)可得
\(x + 1 = (a + 1) (b + 1)\)
C
我们发现我们直接括号匹配,求左括号在左,右括号在右的答案就好了.
D
我们设
\(40\)分:
\(f_{l,r}\)表示\(l,r\)表示\(l-r\)之间的答案
如果\(l, r\)能够匹配
则有\(f_{l,r} = f_{l+1,r-1}+2\)
否则
\(f_{l,r} = max(f_{l+1,r},f_{l,r - 1})\)
这样就有40分了
\(k = 2\):
我们发现,其实每一对数就是一个区间
我们要寻找的是嵌套的最大的不相交的区间
左端点排序之后,实质上是求右端点的最长递减子序列
所以求一下右端点的LIS就可以了
之后我么推广到k<=4,发现将所有可能的区间进行上述操作即可,因为要求单调递减所以不可能存在同一个数被选择两次
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<vector>
using namespace std;
const int N = 5e5 + 3;
struct node{
int li,ri,v;
}q[N << 1];
vector <int> G[N];
int tot,maxx;
int a[N],f[N];
int sum[N];
inline int read(){
int v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
int n,m,k;
struct BIT{
int c[N];
inline void clear(){memset(c,0,sizeof(c));}
inline void updata(int x,int v){
for(;x <= n;x += x & -x) c[x] = max(c[x],v);
}
inline int query(int x){
int res = 0;
for(;x;x -= x & -x) res = max(res,c[x]);
return res;
}
}T;
inline bool cmp(node x,node y){
if(x.li != y.li) return x.li < y.li;
return x.ri < y.ri;
}
int main(){
int tt = read();
while(tt--){
memset(sum,0,sizeof(sum));
int ans = 0;
n = read(),k = read();tot = 0;
T.clear();memset(f,0,sizeof(f));
for(int i = 1;i <= 100000;++i) G[i].clear();
for(int i = 1;i <= n;++i) {
a[i] = read();
q[++tot] = (node){i,i,1};
for(int j = 0;j < (int)G[a[i]].size();++j)
q[++tot] = (node){G[a[i]][j],i,2};
G[a[i]].push_back(i);
}
sort(q + 1,q + tot + 1,cmp);
for(int i = 1;i <= tot;++i){
f[i] = max(f[i],T.query(n - q[i].ri + 1 - 1) + q[i].v);
T.updata(n - q[i].ri + 1,f[i]);
ans = max(ans,f[i]);
}
printf("%d\n",ans);
}
return 0;
}
E
此类题目一般要旋转坐标系!!!
首先,我们考虑一下\(n^2\)做法
我们旋转坐标系之后,求出每一条直线有矩形的交点,然后把交点进行旋转.
之后我们发现每一条线与矩形的交点旋转之后是可以求出的
这样的话,线段就变成了只有\(x,y,d\)三个参数的
如果是竖着的,就\(d\)行,从\(x\)到\(y\)
横着同理
之后我们发现
我们在枚举竖着的之后,可以将符合条件的加入BIT查询即可,由于查询的是横着的线段在这个区间内的数量
而任意两条线段,所以要\(ans + C^2_{x}\)
\(nlogn\)
我们发现,要求的其实就是\(\sum_{l + 1}^rC_x^2\)
所以考虑线段树扫描线,在加入横着线段的同时维护区间的\(\sum_{l + 1} ^rC_x^2\)的答案
而
\(C_{x + k}^2 = C_{x}^2+x*k+C^2_k\)
所以我们要维护区间\(x\)的和,区间长度,以及区间\(C_{x}^2\)的和
但是注意一点:
在下方标记的时候,要先更新区间\(C_x^2\)的值,因为它的值是受之前的\(\sum x\)影响的
同时此题离散化的是由,由于使用了upper_bound缩小的范围
所以只能先排序,然后边用便利离散化
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cctype>
#include<vector>
#include<algorithm>
#include<queue>
#define LL long long
#define mk make_pair
#define pii pair<LL,LL>
using namespace std;
const int N = 2e5 + 3;
const LL INF = 1e15;
const LL mod = 1e9 + 7;
vector <pii> G1;
LL A[N],B[N];
inline LL mo(LL x){
if(x >= mod) x -= mod;
if(x < 0) x += mod;
return x;
}
inline LL read(){
LL v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
inline LL get(LL x,LL k,LL len,LL s1){
return (k * (k - 1) / 2 * len % mod + x + s1 * k % mod) % mod;
}
struct tree{
int t;
struct node{
int lc,rc;
LL s1,s2;
LL tag;
}a[N << 1];
inline void pushup(int u){
a[u].s1 = (a[a[u].lc].s1 + a[a[u].rc].s1) % mod;
a[u].s2 = (a[a[u].lc].s2 + a[a[u].rc].s2) % mod;
}
inline void build(int u,int l,int r){
if(l == r) return ;
int mid = (l + r) >> 1;
a[u].lc = ++t;
build(a[u].lc,l,mid);
a[u].rc = ++t;
build(a[u].rc,mid + 1,r);
pushup(u);
}
inline void pushdown(int u,int l,int r){
if(!a[u].tag) return ;
int mid = (l + r) >> 1;
a[a[u].lc].s2 = get(a[a[u].lc].s2,a[u].tag,mid - l + 1,a[a[u].lc].s1);
a[a[u].rc].s2 = get(a[a[u].rc].s2,a[u].tag,r - mid,a[a[u].rc].s1);
a[a[u].lc].s1 = (a[a[u].lc].s1 + a[u].tag * (mid - l + 1)) % mod;
a[a[u].rc].s1 = (a[a[u].rc].s1 + a[u].tag * (r - mid)) % mod;
a[a[u].lc].tag = mo(a[a[u].lc].tag + a[u].tag);
a[a[u].rc].tag = mo(a[a[u].rc].tag + a[u].tag);
a[u].tag = 0;
}
inline void updata(int u,int l,int r,int ll,int rr,int w){
// printf("%d %d %d %lld %lld\n",u,l,r,a[u].s1,a[u].s2);
if(l == ll && r == rr){
a[u].s2 = get(a[u].s2,w,r - l + 1,a[u].s1);
a[u].s1 = (a[u].s1 + r - l + 1) % mod;
a[u].tag = mo(a[u].tag + w);
return ;
}
pushdown(u,l,r);
int mid = (l + r) >> 1;
if(rr <= mid) updata(a[u].lc,l,mid,ll,rr,w);
else if(ll > mid) updata(a[u].rc,mid + 1,r,ll,rr,w);
else {
updata(a[u].lc,l,mid,ll,mid,w);
updata(a[u].rc,mid + 1,r,mid + 1,rr,w);
}
pushup(u);
}
inline int query(int u,int l,int r,int ll,int rr){
if(ll > rr) return 0;
if(l == ll && r == rr) return a[u].s2;
pushdown(u,l,r);
int mid = (l + r) >> 1;
if(rr <= mid) return query(a[u].lc,l,mid,ll,rr);
else if(ll > mid) return query(a[u].rc,mid + 1,r,ll,rr);
else return (query(a[u].lc,l,mid,ll,mid) + query(a[u].rc,mid + 1,r,mid + 1,rr)) % mod;
}
}T;
LL w,h;
int n,m;
LL a[N],b[N];
struct line{
LL li,ri;
LL di;
};
line x[N],y[N];
int main(){
int tot = 0;
w = read(),h = read(),n = read(),m = read();
for(int i = 1;i <= n;++i) a[i] = read();
for(int i = 1;i <= m;++i) b[i] = read();
for(int i = 1;i <= n;++i){
x[i].di = a[i];
B[i] = a[i];
}
for(int i = 1;i <= m;++i){
LL p1=min(w+h,min(2*w-b[i],2*h+b[i]));
LL p2=max(0ll,max(-b[i],b[i]));
// .push_back(mp(p2,p1));
y[i].ri = p1;
y[i].li = p2;
}
// for(int i = 1;i <= n;++i) printf("%d ",x[i].di);puts("");
// for(int i = 1;i <= m;++i) printf("%d %d\n",y[i].li,y[i].ri);
sort(B + 1,B + n + 1);
B[0] = unique(B + 1,B + n + 1) - B - 1;
for(int i = 1;i <= n;++i) //x[i].di = lower_bound(B + 1,B + B[0] + 1,x[i].di) - B,
G1.push_back(mk(x[i].di,INF));
for(int i = 1;i <= m;++i){
// y[i].li = upper_bound(B + 1,B + B[0] + 1,y[i].li) - B - 1;
// y[i].ri = upper_bound(B + 1,B + B[0] + 1,y[i].ri) - B - 1;
G1.push_back(mk(y[i].li,y[i].ri));
// G1[y[i].li].push_back(y[i].ri);
// G2[y[i].ri].push_back(y[i].li);
}
sort(G1.begin(),G1.end());
// for(int i = 0;i < (int)G1.size();++i) printf("%lld %lld\n",G1[i].first,G1[i].second);
T.t = 1;
T.build(1,1,n);
LL ans = 0;
for(int i = 0;i < (int)G1.size();++i){
if(G1[i].first > G1[i].second) continue;
if(G1[i].second == INF){
G1[i].first = lower_bound(B + 1,B + B[0] + 1,G1[i].first) - B;
if(G1[i].first < n) ans = (ans + T.query(1,1,n,G1[i].first + 1,n)) % mod;
}
else{
G1[i].second = upper_bound(B + 1,B + B[0] + 1,G1[i].second) - B - 1;
if(G1[i].second >= 1) T.updata(1,1,n,1,G1[i].second,1);
}
// cout << ans << endl;
}
cout << ans << endl;
return 0;
}
ZR7.17的更多相关文章
- Golang, 以17个简短代码片段,切底弄懂 channel 基础
(原创出处为本博客:http://www.cnblogs.com/linguanh/) 前序: 因为打算自己搞个基于Golang的IM服务器,所以复习了下之前一直没怎么使用的协程.管道等高并发编程知识 ...
- .NET平台开源项目速览(17)FluentConsole让你的控制台酷起来
从该系列的第一篇文章 .NET平台开源项目速览(1)SharpConfig配置文件读写组件 开始,不知不觉已经到第17篇了.每一次我们都是介绍一个小巧甚至微不足道的.NET平台的开源软件,或者学习,或 ...
- Centos 6.6 下搭建php5.2.17+Zend Optimizer3.3.9+Jexus环境
(为何安装php5.2.17这个版本 因为phpweb这个程序用到了Zend Optimizer3.3.9 这个东东已经停止更新了 最高支持5.2版本的php 所以就有了一晚上填坑的自己和总结了这篇文 ...
- 企业IT管理员IE11升级指南【17】—— F12 开发者工具
企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...
- CSharpGL(17)重构CSharpGL
CSharpGL(17)重构CSharpGL CSharpGL用起来我自己都觉得繁琐了,这是到了重构的时候. 下载 CSharpGL已在GitHub开源,欢迎对OpenGL有兴趣的同学加入(https ...
- ABP(现代ASP.NET样板开发框架)系列之17、ABP应用层——参数有效性验证
点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之17.ABP应用层——参数有效性验证 ABP是“ASP.NET Boilerplate Project (ASP. ...
- 从零开始编写自己的C#框架(17)——Web层后端首页
后端首页是管理员登陆后进入的第一个页面,主要是显示当前登陆用户信息.在线人数.菜单树列表.相关功能按键和系统介绍.让管理员能更方便的找到息想要的内容. 根据不同系统的需要,首页会显示不同的内容,比如显 ...
- ERROR 1010 (HY000): Error dropping database (can't rmdir './test/', errno: 17)
在删除数据库的时候报标题所示错误 mysql> drop database test; ERROR (HY000): Error dropping database (can't rmdir ' ...
- Xamarin for Visual Studio V3.11.431 于 2015.4.3-2015.4.17 最新发布(Win & Mac)
Beta Release: April 3 edited April 17 in Visual Studio Released versions: Windows Xamarin.VisualStud ...
随机推荐
- metro扁平UI网页组件
在线演示 本地下载
- 连接池c3p0
连接池c3p0 C3P0:hibernate和spring使用,有自动回收空闲连接的功能. 使用步骤: 1.导入jar包(c3p0-0.9.1.2.jar) 2.使用api a.硬编码(不推荐) ne ...
- Oracle日期
oracle 日期格式 to_date("要转换的字符串","转换的格式") 两个参数的格式必须匹配,否则会报错. 即按照第二个参数的格式解释第一个参数. ...
- Excel中IP地址排序
思路 将IP地址按"."分隔,提取"."之间的每个数,然后根据提取出的列从左至右进行主要字段及次要字段排序 公式说明 返回一个字符串在另一个字符串中出现的起始位 ...
- Cmakelists.txt中配置glew
在cmakelists.txt中添加: add_library(glew_static STATIC IMPORTED) set_target_properties(glew_static PROPE ...
- 巨蟒python全栈开发-第11阶段 ansible3_3入门playbook剧本
1.playbook剧本 2.playbook传参 3.setup模块介绍 4.playbook的tags 5.playbook的handlers&&templates模块 6.条件和 ...
- CAD安装失败怎样卸载重新安装CAD,解决CAD安装失败的方法总结
技术帖:CAD没有按照正确方式卸载,导致CAD安装失败.楼主也查过网上关于如何解决CAD安装失败的一些文章,是说删除几个CAD文件和CAD软件注册表就可以解决CAD安装失败的问题,实际的情况并没有这么 ...
- 异常解决:non-compatible bean definition of same name and class【com.xxx.xxx.XXX】
昨天同事遇到这样一个问题,意思是spring找到 有相同的实现类名在不同的package目录下. 跟踪他的项目代码并未发现问题. 重新给他的maven项目进行maven install一下. 查看 ...
- @noi.ac - 506@ 强连通分量
目录 @description@ @solution@ @accepted code@ @details@ @description@ 有一天你学了一个叫能求出有向图中所有的强连通分量的算法,你决定将 ...
- hdu 1596 find the safest road (变形SP && dij+heap)
Problem - 1596 变形最短路问题,给出邻接矩阵,要求求出给定点对间安全率最大值. 这题可以用dijkstra+heap来做.对于每一个查询,做一次dij即可. 代码如下: #include ...