这题不知道为什么就是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校赛圣杯战争的更多相关文章

  1. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  2. SCNU省选校赛第二场B题题解

    今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...

  3. 2014上半年acm总结(1)(入门+校赛)

    大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干=  = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...

  4. 2017CUIT校赛-线上赛

    2017Pwnhub杯-CUIT校赛 这是CUIT第十三届校赛啦,也是我参加的第一次校赛. 在被虐到崩溃的过程中也学到了一些东西. 这次比赛是从5.27早上十点打到5.28晚上十点,共36小时,中间睡 ...

  5. HZNU第十二届校赛赛后补题

    愉快的校赛翻皮水! 题解 A 温暖的签到,注意用gets #include <map> #include <set> #include <ctime> #inclu ...

  6. 校赛F

    问题描述 例如对于数列[1 2 3 4 5 6],排序后变为[6 1 5 2 4 3].换句话说,对于一个有序递增的序列a1, a2, a3, ……, an,排序后为an, a1, an-1, a2, ...

  7. 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 ...

  8. 【魔改】hdu6325 多校赛3G xy排序凸包+llvector模板

    凸包算法前的预处理,可以极角排序,也可以按X,Y轴排序, 极角排序需要找到角落里的一个点,Xy轴排序要跑两遍凸包 而本题的要求只要一个上半凸包,并且有X轴从小到大以及字典序限制,完全符合xy排序,直接 ...

  9. 牛客网多校赛第9场 E-Music Game【概率期望】【逆元】

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

随机推荐

  1. 【 D3.js 入门系列 --- 4 】 如何使用scale(比例)

    在上一节中使用了一个很重要的概念 — scale (这个不知道翻译成什么,暂且叫它比例).本节将重点介绍它的相关使用方法. 在介绍 scale 之前,先介绍两个经常和 scale 一起出现的函数,在上 ...

  2. 【转】Android M(6.0) 权限爬坑之旅

    原文网址:https://yanlu.me/android-m6-0-permission-chasm/ 有一篇全面介绍Android M 运行时权限文章写的非常全面:Android M 新的运行时权 ...

  3. latch: cache buffers chains故障处理总结(转载)

    一大早就接到开发商的电话,说数据库的CPU使用率为100%,应用相应迟缓.急匆匆的赶到现场发现进行了基本的检查后发现是latch: cache buffers chains 作祟,处理过程还算顺利,当 ...

  4. Python decode与encode

      字符串在Python内部的表示是unicode编码(8-bit string),因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicod ...

  5. hessian不能注入dao的问题解决

    天天卡,写个程序很费劲,不是卡这儿就是卡那里,一天天的不出活,周六日费时间都在这上面了. 问题:hessian能调通,就是不能操作数据库,userDao不能注入,为null,期初以为是实体类赋值的问题 ...

  6. Java web项目引用java项目,类型找不到

    Java web项目引用java项目,类型找不到 错误信息: java.lang.ClassNotFoundException: org.codehaus.jackson.map.ObjectMapp ...

  7. 【SVN】自动备份SVN仓库

    仓库的位置为:C:\xxx\SVNRepo\ MyCommonUtils MyStudyProject SVN仓库备份.bat '参考连接:http://www.uml.org.cn/pzgl/201 ...

  8. 使用jquery的delay方式模拟sleep

    javascript中并没有原生sleep函数可供调用,一般来说为了实现sleep功能,大都是采用SetTimeout来模拟,以下片段采用jquery的delay方法来模拟,也算是提供了另外一个视角吧 ...

  9. JS Math对象中一些小技巧

    JS中快速获取数组中最大/最小值 var a=[1,2,3,5]; alert(Math.max.apply(Math, a));//最大值 alert(Math.min.apply(Math, a) ...

  10. java语言实现堆排序

    package secondChapter; import java.util.Random; public class HeapSort { private static int AHeapSize ...