zstu2016校赛圣杯战争
这题不知道为什么就是T,简直有毒。
思想和巴比伦那题差不多。
话说,寻找一个区间内满足一个条件的最左(右)边的一个数,用线段树来写,应该是可以的,之前博客里大连网赛那题的线段树写法应该是有点小问题的。现在按照下面的套路来,虽然是T的= =。当然也可以用单调栈来实现。
代码如下(T的):
#include <stdio.h>
#include <algorithm>
#include <string.h>
#define ls (o<<1)
#define rs (o<<1|1)
#define t_mid (l+r>>1)
#define lson ls,l,t_mid
#define rson rs,t_mid+1,r
using namespace std;
typedef long long ll;
const int N = + ; int n,m,q;
ll atk[N];
int nxt[N],pos[N];
int c[N<<],d[N<<];
// 线段树维护(nxt[i] - i + 1)的最大值和(nxt[i])的最大值 void build(int o,int l,int r)
{
if(l == r) {c[o] = nxt[l]-l+; d[o] = nxt[l]; return;}
build(lson);
build(rson);
c[o] = max(c[ls],c[rs]); d[o] = max(d[ls],d[rs]);
} int Find(int o,int l,int r,int ql,int qr,int where)
{
//if(ql > qr) return -1;
if(l == r)
{
if(nxt[l] >= where) return l;
else return -;
}
int ans = -;
if(t_mid >= qr)
{
if(d[ls] >= where) ans = Find(lson,ql,qr,where);
}
else if(ql > t_mid)
{
if(d[rs] >= where) ans = Find(rson,ql,qr,where);
}
else
{
if(d[ls] >= where) ans = Find(lson,ql,t_mid,where);
if(ans == - && d[rs] >= where) ans = Find(rson,t_mid+,qr,where);
}
return ans;
} int Find2(int o,int l,int r,int ql,int qr)
{
if(ql == l && qr == r)
{
return d[o];
}
int ans = ;
if(t_mid >= qr) ans = Find2(lson,ql,qr);
else if(t_mid < ql) ans = Find2(rson,ql,qr);
else
{
ans = max(Find2(lson,ql,t_mid), Find2(rson,t_mid+,qr));
} return ans;
} int query(int o,int l,int r,int ql,int qr)
{
if(ql == l && qr == r)
{
return c[o];
}
if(qr <= t_mid) return query(lson,ql,qr);
else if(ql > t_mid) return query(rson,ql,qr);
else return max(query(lson,ql,t_mid), query(rson,t_mid+,qr));
} int solve(int ql,int qr)
{
int temp = -;
//int temp = Find(1,1,n,ql,qr,qr); int ans = , ans2 = , ans3 = ; if(temp == -) ans2 = query(,,n,ql,qr);
else
{
ans = qr - temp + ;
if(temp != ql) ans2 = query(,,n,ql,temp-);
}
if(ql > )
{
ans3 = Find2(,,n,,ql-);
if(ans3 > qr) ans3 = qr;
if(ans3 >= ql) ans3 = ans3 - ql + ;
} return max(max(max(ans,ans2),ans3),);
} int main()
{
int T;scanf("%d",&T);
while(T--)
{
memset(nxt,-,sizeof(nxt));
//memset(atk,0,sizeof(atk));
scanf("%d%d%d",&n,&m,&q);
//nxt[0] = n;
for(int i=;i<=n;i++) {scanf("%d",atk+i);atk[i]+=atk[i-];}
for(int i=;i<=m;i++) scanf("%d",pos+i);
for(int i=;i<=m;i++)
{
int hp;scanf("%d",&hp);
int now = pos[i] - ;
int l = pos[i], r = n, ans = -;
while(l <= r)
{
int mid = l + r >> ;
if(atk[mid] - atk[now] <= hp) {ans = mid; l = mid + ;}
else r = mid - ;
}
nxt[pos[i]] = max(ans,nxt[pos[i]]); ans = -;
l = , r = pos[i];
now = pos[i];
while(l <= r)
{
int mid = l + r >> ;
if(atk[now] - atk[mid-] <= hp) {ans = mid; r = mid - ;}
else l = mid + ;
}
nxt[ans] = max(pos[i],nxt[ans]);
//printf("%d %d ??\n",pos[i],ans);
} /*int now = -1;
for(int i=1;i<=n;i++)
{
if(nxt[i] != -1) now = max(now,nxt[i]);
else
{
nxt[i] = now;
if(now == i) now = -1;
}
}*/
//----------------------处理线段-------------------------
build(,,n);
//for(int i=1;i<=n;i++) printf("%d !!\n",nxt[i]);
int ans = ;
int ql, qr;
while(q--)
{
scanf("%d%d",&ql,&qr);
ql ^= ans;
qr ^= ans; //if(ql > qr) swap(ql, qr);
/*if(ql < 0) ql = -ql;
if(qr < 0) qr = -qr;
if(ql > qr) swap(ql, qr);
if(ql < 1||ql > n) ql = 1;
if(qr <1 ||qr > n) qr = n; */ //ql = 1,qr = n;
if(ql > qr) swap(ql, qr);
printf("%d\n",ans=solve(ql,qr));
}
}
return ;
}
zstu2016校赛圣杯战争的更多相关文章
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- SCNU省选校赛第二场B题题解
今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...
- 2014上半年acm总结(1)(入门+校赛)
大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干= = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...
- 2017CUIT校赛-线上赛
2017Pwnhub杯-CUIT校赛 这是CUIT第十三届校赛啦,也是我参加的第一次校赛. 在被虐到崩溃的过程中也学到了一些东西. 这次比赛是从5.27早上十点打到5.28晚上十点,共36小时,中间睡 ...
- HZNU第十二届校赛赛后补题
愉快的校赛翻皮水! 题解 A 温暖的签到,注意用gets #include <map> #include <set> #include <ctime> #inclu ...
- 校赛F
问题描述 例如对于数列[1 2 3 4 5 6],排序后变为[6 1 5 2 4 3].换句话说,对于一个有序递增的序列a1, a2, a3, ……, an,排序后为an, a1, an-1, a2, ...
- PKU2018校赛 H题 Safe Upper Bound
http://poj.openjudge.cn/practice/C18H 题目 算平均数用到公式\[\bar{x}=\frac{x_1+x_2+x_3+\cdots+x_n}{n}\] 但如果用in ...
- 【魔改】hdu6325 多校赛3G xy排序凸包+llvector模板
凸包算法前的预处理,可以极角排序,也可以按X,Y轴排序, 极角排序需要找到角落里的一个点,Xy轴排序要跑两遍凸包 而本题的要求只要一个上半凸包,并且有X轴从小到大以及字典序限制,完全符合xy排序,直接 ...
- 牛客网多校赛第9场 E-Music Game【概率期望】【逆元】
链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
随机推荐
- CF 628C --- Bear and String Distance --- 简单贪心
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...
- 使用Condition Variables 实现一个线程安全队列
使用Condition Variables实现一个线程安全队列 测试机: i7-4800MQ .7GHz, logical core, physical core, 8G memory, 256GB ...
- (转) 一张图解AlphaGo原理及弱点
一张图解AlphaGo原理及弱点 2016-03-23 郑宇,张钧波 CKDD 作者简介: 郑宇,博士, Editor-in-Chief of ACM Transactions on Intellig ...
- iTextSharp 使用详解(转)
PDF文件是目前比较流行的电子文档格式,在办公自动化(OA)等软件的开发中,经常要用到该格式,但介绍如何制作PDF格式文件的资料非常少,在网上搜来搜去,都转贴的是同一段“暴力”破解的方法,代码片断如下 ...
- [solr] - Facet
Solr facet使用于分类统计,是最好的工具.下面例子使用facet将可模拟查询搜索出租房信息. 1.在schema.xml中的内容如下: <?xml version="1.0&q ...
- Amazon Web Services
- Hello Dojo!(翻译)
http://dojotoolkit.org/documentation/tutorials/1.10/hello_dojo/index.html 欢迎学习DOJO!在本教程中,你将学些到如何加载DO ...
- linux查看磁盘io的几种方法
怎样才能快速的定位到并发高是由于磁盘io开销大呢?可以通过三种方式: 第一种:用 top 命令 中的cpu 信息观察 Top可以看到的cpu信息有: Tasks: 29 total, 1 runnin ...
- OpenExplorer打开文件夹
Eclipse中文件打开功能,可以到https://github.com/samsonw/OpenExplorer/downloads下载最新版本,将jar包放到eclipse的plugins目录中, ...
- Codeforces 723e [图论][欧拉回路]
/* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给你一个有n个点,m条边的无向图,给每条边规定一个方向,使得这个图变成有向图,并且使得尽可能多的点入度与出度相同. 输出有多少个这样的点并且输出 ...