Lucky Array Codeforces - 121E && Bear and Bad Powers of 42 Codeforces - 679E
http://codeforces.com/contest/121/problem/E
话说这题貌似暴力可A啊。。。
正解是想出来了,结果重构代码,调了不知道多久才A
错误记录:
1.线段树搞混num(节点编号)和l(区间端点)
2.之前的dfs没有分离,写的非常混乱,迫不得已重构代码
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define N 100000
int data[]={,,,,,,,,,,,,,,
,,,,,,,,,,,,
,,,};
bool ok[];
int sd=;
int n,m;
int d[N+];
vector<pii> qq;
//d[i]表示满足data[j]>(i位置的实际值)的最小j
//线段树中查询出的位置的值表示data[d[i]]-(i位置的实际值)
namespace S
{
#define mid (l+((r-l)>>1))
#define lc (num<<1)
#define rc (num<<1|1)
int minn[*N],sum[*N],delv[*N];
void pd(int num)
{
minn[lc]-=delv[num];minn[rc]-=delv[num];
delv[lc]+=delv[num];delv[rc]+=delv[num];
delv[num]=;
}
void delx(int L,int R,int x,int l,int r,int num)
{
if(L<=l&&r<=R)
{
minn[num]-=x;delv[num]+=x;
return;
}
pd(num);
if(L<=mid) delx(L,R,x,l,mid,lc);
if(mid<R) delx(L,R,x,mid+,r,rc);
minn[num]=min(minn[lc],minn[rc]);
}
void setx(int L,int x,int l,int r,int num)
{
if(l==r) {minn[num]=x;return;}
pd(num);
if(L<=mid) setx(L,x,l,mid,lc);
else setx(L,x,mid+,r,rc);
minn[num]=min(minn[lc],minn[rc]);
}
void setsum(int L,int x,int l,int r,int num)
{
if(l==r) {sum[num]=x;return;}
if(L<=mid) setsum(L,x,l,mid,lc);
else setsum(L,x,mid+,r,rc);
sum[num]=sum[lc]+sum[rc];
}
void update(int l,int r,int num)
{
if(minn[num]>) return;
if(l==r) {qq.pb(mp(l,data[d[l]]-minn[num]));return;}//minn[l]->minn[num]
pd(num);
update(l,mid,lc);update(mid+,r,rc);
minn[num]=min(minn[lc],minn[rc]);
}
int gsum(int L,int R,int l,int r,int num)
{
if(L<=l&&r<=R) return sum[num];
int ans=;
if(L<=mid) ans+=gsum(L,R,l,mid,lc);
if(mid<R) ans+=gsum(L,R,mid+,r,rc);
return ans;
}
void work()
{
for(auto pp:qq)
{
int &l=pp.fi,&d=pp.se;
int p=upper_bound(data,data+sd,d)-data;
setx(l,data[p]-d,,n,);
setsum(l,ok[d],,n,);
::d[l]=p;
}
qq.clear();
}
}
char tmp[];
int main()
{
int i,t,L,R,x;
for(i=;i<sd;i++) ok[data[i]]=;
for(i=;i<sd;i++) data[i+sd]=data[i]+;
sd*=;sort(data,data+sd);
data[sd++]=;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++) scanf("%d",&t),qq.pb(mp(i,t));
S::work();
while(m--)
{
scanf("%s",tmp);
if(tmp[]=='c')
{
scanf("%d%d",&L,&R);S::update(,n,);S::work();
printf("%d\n",S::gsum(L,R,,n,));
}
else
{
scanf("%d%d%d",&L,&R,&x);
S::delx(L,R,x,,n,);
}
}
return ;
}
https://codeforces.com/problemset/problem/679/E
跟上面那道类似,可以发现涉及到42的幂很少(显然出题人不是想让我们写高精)
因此开一棵线段树维护每个位置到下一个“关键点”(是否是42的幂的属性变化的点)的距离即可
对于区间修改,就用set维护一下相同的区间,一段相同的放在一起处理
大概是这样吧,可能还有一些细节。。
Lucky Array Codeforces - 121E && Bear and Bad Powers of 42 Codeforces - 679E的更多相关文章
- CF679E Bear and Bad Powers of 42
一段时间不写线段树标记,有些生疏了 codeforces 679e Bear and Bad Powers of 42 - CHADLZX - 博客园 关键点是:42的次幂,在long long范围内 ...
- codeforces 679e Bear and Bad Powers of 42
传送门:http://codeforces.com/contest/679/problem/E 题目意思很清晰,给你一个序列,要求你完成以下三个操作: 1.输出A[i] 2.将[a,b]区间的所有数字 ...
- Codeforces 679E - Bear and Bad Powers of 42(线段树+势能分析)
Codeforces 题目传送门 & 洛谷题目传送门 这个 \(42\) 的条件非常奇怪,不过注意到本题 \(a_i\) 范围的最大值为 \(10^{14}\),而在值域范围内 \(42\) ...
- Codeforces679E. Bear and Bad Powers of 42
传送门 今天子帧的一套模拟题的T3. 考试的时候其实已经想到了正解了,但是一些地方没有想清楚,就没敢写,只打了个暴力. 首先考虑用线段树维护区间信息. 先把每个值拆成两个信息,一是距离他最近的且大于他 ...
- Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array 分块
E. Lucky Array time limit per test 4 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array
E. Lucky Array Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers w ...
- Codeforces 385C Bear and Prime Numbers
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...
- Codeforces 385B Bear and Strings
题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...
- Codeforces 680D Bear and Tower of Cubes 贪心 DFS
链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...
随机推荐
- java之集合Collection 具体解释之4
package cn.itcast_04; public class Student { private String name; private int age; public Student() ...
- poj 1180 Batch Scheduling (斜率优化)
Batch Scheduling \(solution:\) 这应该是斜率优化中最经典的一道题目,虽然之前已经写过一道 \(catstransport\) 的题解了,但还是来回顾一下吧,这道题其实较那 ...
- (linux)SD卡初始化-mmc_sd_init_card函数(续)
转自:http://www.cnblogs.com/fengeryi/p/3472728.html mmc_sd_init_card剩下的关于UHS-I的分支结构. uhs-I的初始化流程图如 ...
- HUST1017 Exact cover —— Dancing Links 精确覆盖 模板题
题目链接:https://vjudge.net/problem/HUST-1017 1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 7673 次提交 3898 次 ...
- HDU2181 哈密顿绕行世界问题 —— DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181 哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) ...
- html5--6-8 CSS选择器5
html5--6-8 CSS选择器5 实例 <!DOCTYPE html> <html lang="zh-cn"> <head> <met ...
- 【Maven】pom.xml(1)
在pom.xml加入: <build> <finalName>oauth2</finalName> <resources> <resource&g ...
- hdu 4302 Holedox Eating(优先队列/线段树)
题意:一只蚂蚁位与原点,在x轴正半轴上会不时地出现一些蛋糕,蚂蚁每次想吃蛋糕时选取最近的去吃,如果前后距离相同,则吃眼前的那一块(即方向为蚂蚁的正前),求最后蚂蚁行进距离. 思路:优先队列q存储蚂蚁前 ...
- docker容器安装使用
window安装 1 下载 http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/ docker toolbox 是一个 ...
- Objective-C基础知识
内联函数 “内联函数”是一个很老的概念,在其他语言譬如C++语言中也出现了.所谓“内联函数”指的是“有函数的结构,但不具备函数的性质,类似于宏替换功能的代码块”. 在实际应用中,常常把规模较小.逻辑较 ...