传送门

今天子帧的一套模拟题的T3。

考试的时候其实已经想到了正解了,但是一些地方没有想清楚,就没敢写,只打了个暴力。

首先考虑用线段树维护区间信息。

先把每个值拆成两个信息,一是距离他最近的且大于他的$42$的整次幂,而是到距离他最近的且大于他的$42$的整次幂的距离。

操作1和操作2不需要细说。

对于操作3,每次加入一个数后check整棵线段树的Min,如果出现负数就逐个升级。如果出现了0就再次增加,直到不出现0为止。

因为每个数最多升级$logN$次,所以时间上是没有问题的。

另一个小细节(被卡了很长时间),在每次下传操作2的lazytag之前要先将下一个的操作3的lazytag清空。

//Codeforces 679E
//by Cydiater
//2017.1.20
#include <iostream>
#include <queue>
#include <map>
#include <ctime>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <set>
#include <vector>
using namespace std;
#define ll long long
#define up(i,j,n)	for(int i=j;i<=n;i++)
#define down(i,j,n)	for(int i=j;i>=n;i--)
#define cmax(a,b)	a=max(a,b)
#define cmin(a,b)	a=min(a,b)
#define FILE		"bad42"
const int MAXN=2e5+5;
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll pw[MAXN],N,M,arr[MAXN];
//little tool
ll Level(ll num){up(i,0,11)if(pw[i]>=num)return i;}
ll Dist(ll num){up(i,0,11)if(pw[i]>=num)return pw[i]-num;}
struct tree{
	ll Min,tag1,tag2,level;
	//tag1 -> opt2
	//tag2 -> opt3
}t[MAXN<<2];
namespace SegmentTree{
	inline void reload(int root){t[root].Min=min(t[root<<1].Min,t[root<<1|1].Min);}
	inline void Uplevel(int root){
		ll num=pw[t[root].level]-t[root].Min;
		t[root].level=Level(num);
		t[root].Min=Dist(num);
	}
	inline void Pushdown(int leftt,int rightt,int root){
		if(t[root].tag1>0){
			if(leftt!=rightt){
				t[root<<1].level=Level(t[root].tag1);
				t[root<<1].Min=Dist(t[root].tag1);
				t[root<<1].tag1=t[root].tag1;
				t[root<<1].tag2=0;

				t[root<<1|1].level=Level(t[root].tag1);
				t[root<<1|1].Min=Dist(t[root].tag1);
				t[root<<1|1].tag1=t[root].tag1;
				t[root<<1|1].tag2=0;
			}
			t[root].tag1=0;
		}
		if(t[root].tag2>0){
			if(leftt!=rightt){
				t[root<<1].Min-=t[root].tag2;
				t[root<<1].tag2+=t[root].tag2;

				t[root<<1|1].Min-=t[root].tag2;
				t[root<<1|1].tag2+=t[root].tag2;
			}
			t[root].tag2=0;
		}
	}
	void Build(int leftt,int rightt,int root){
		if(leftt==rightt){
			t[root].Min=Dist(arr[leftt]);t[root].level=Level(arr[leftt]);
			t[root].tag1=-1;t[root].tag2=0;
			return;
		}
		int mid=(leftt+rightt)>>1;
		t[root].tag1=-1;t[root].tag2=0;
		Build(leftt,mid,root<<1);
		Build(mid+1,rightt,root<<1|1);
		reload(root);
	}
	ll Realnum(int leftt,int rightt,int root,int pos){
		Pushdown(leftt,rightt,root);
		if(leftt==rightt||t[root].tag1==0)	return pw[t[root].level]-t[root].Min;
		int mid=(leftt+rightt)>>1;
		if(mid>=pos)				return Realnum(leftt,mid,root<<1,pos);
		else if(mid+1<=pos)			return Realnum(mid+1,rightt,root<<1|1,pos);
	}
	void Modify(int leftt,int rightt,int root,int L,int R,int val,int tag){
		Pushdown(leftt,rightt,root);
		int mid=(leftt+rightt)>>1;
		if(leftt>=L&&rightt<=R){
			if(tag==1){
				t[root].tag1=val;
				t[root].level=Level(val);
				t[root].Min=Dist(val);
			}
			else{
				t[root].tag2=val;
				t[root].Min-=val;
			}
			return;
		}
		t[root].tag1=-1;
		if(L>=mid+1)	Modify(mid+1,rightt,root<<1|1,L,R,val,tag);
		else if(R<=mid)	Modify(leftt,mid,root<<1,L,R,val,tag);
		else{
			Modify(leftt,mid,root<<1,L,R,val,tag);
			Modify(mid+1,rightt,root<<1|1,L,R,val,tag);
		}
		reload(root);
	}
	void fix(int leftt,int rightt,int root){
		Pushdown(leftt,rightt,root);
		if(leftt==rightt||t[root].tag1==0){
			Uplevel(root);
			return;
		}
		int mid=(leftt+rightt)>>1;
		if(t[root<<1].Min<0)	fix(leftt,mid,root<<1);
		if(t[root<<1|1].Min<0)	fix(mid+1,rightt,root<<1|1);
		reload(root);
	}
}using namespace SegmentTree;
namespace solution{
	void Prepare(){
		pw[0]=1;
		up(i,1,11)pw[i]=pw[i-1]*42LL;
		N=read();M=read();
		up(i,1,N)arr[i]=read();
		Build(1,N,1);
	}
	void Solve(){
		while(M--){
			int opt=read();
			if(opt==1){
				int pos=read();
				printf("%I64d\n",Realnum(1,N,1,pos));
			}
			if(opt==2){
				int L=read(),R=read(),val=read();
				Modify(1,N,1,L,R,val,1);
			}
			if(opt==3){
				int L=read(),R=read(),val=read();
				do{
					Modify(1,N,1,L,R,val,2);
					//printf("%d\n",Realnum(1,N,1,1));
					if(t[1].Min<0)fix(1,N,1);
				}while(t[1].Min==0);
			}
			//up(i,1,N)printf("%d ",Realnum(1,N,1,i));puts("");
		}
	}
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("out1.out","w",stdout);
	//freopen(FILE".in","r",stdin);
	//freopen(FILE".out","w",stdout);
	using namespace solution;
	Prepare();
	Solve();
	return 0;
}

Codeforces679E. Bear and Bad Powers of 42的更多相关文章

  1. CF679E Bear and Bad Powers of 42

    一段时间不写线段树标记,有些生疏了 codeforces 679e Bear and Bad Powers of 42 - CHADLZX - 博客园 关键点是:42的次幂,在long long范围内 ...

  2. codeforces 679e Bear and Bad Powers of 42

    传送门:http://codeforces.com/contest/679/problem/E 题目意思很清晰,给你一个序列,要求你完成以下三个操作: 1.输出A[i] 2.将[a,b]区间的所有数字 ...

  3. Lucky Array Codeforces - 121E && Bear and Bad Powers of 42 Codeforces - 679E

    http://codeforces.com/contest/121/problem/E 话说这题貌似暴力可A啊... 正解是想出来了,结果重构代码,调了不知道多久才A 错误记录: 1.线段树搞混num ...

  4. Codeforces 679E - Bear and Bad Powers of 42(线段树+势能分析)

    Codeforces 题目传送门 & 洛谷题目传送门 这个 \(42\) 的条件非常奇怪,不过注意到本题 \(a_i\) 范围的最大值为 \(10^{14}\),而在值域范围内 \(42\) ...

  5. (Problem 29)Distinct powers

    Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...

  6. Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes dfs

    D. Bear and Tower of Cubes 题目连接: http://www.codeforces.com/contest/680/problem/D Description Limak i ...

  7. codeforces 680D D. Bear and Tower of Cubes(dfs+贪心)

    题目链接: D. Bear and Tower of Cubes time limit per test 2 seconds memory limit per test 256 megabytes i ...

  8. 【19.05%】【codeforces 680D】Bear and Tower of Cubes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 1142 - Summing up Powers (II)

    1142 - Summing up Powers (II)    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit ...

随机推荐

  1. SPS读书笔记1——均值比较(T检验,方差检验,非参数检验汇总)

    均值比较.单样本T检验(One-sample Test))目的:检验单个变量的均值与给定的某个常数是否一致.)判断标准:p<0.05;t>1.98即认为是有显著差异的..独立样本T检验(I ...

  2. git--简单操作

    Git简介 一.      安装 下载地址: https://git-scm.com/downloads: https://pan.baidu.com/s/1kU5OCOB#list/path=%2F ...

  3. jQuery UI dialog 参数说明

    前段时间碰到个问题 jquery UI dialog弹出层 弹出多个层是 比如弹出两个层A和B  B层如果显示的数据表格太大,伸到了A层的外面,那伸到A层之外的部分就看不到了,因为B层是在A层上弹出的 ...

  4. 第九课——redis集群

    第九课时作业 静哥 by 2016.4.18~2016.4.25 1.节点 (1)节点概念:一个节点就是redis集群里的一台redis服务器.一个redis集群是由多个节点(node)组成,最初每个 ...

  5. wf-删除所选

    w框架-结合用户的不同点击路径,提交正确的id集合. <table class="table"> <tr> <td></td> &l ...

  6. d3.js 之增加感染力:使用转场效果

    转场/transition 图形比数据有感染力,动起来的图形比静态的图形更有感染力. 转场是一种过渡,提供两个稳定状态间的一种动态渐进的变化.转场的概念来源于电影. 电影中存在不同场景之间的切换,比如 ...

  7. 如何在 windows 配置 libtorch c++ 前端库?

    如何在 windows 配置 libtorch c++ 前端库? 下载 pytorch 已经编译好的库: 此库不带 gpu,主要方便演示.支持 win7 win10 系统. 下载地址:https:// ...

  8. Python程序员鲜为人知但你应该知道的16个问题(转)

    add by zhj: 没找到原文出处,只能找到转载的,文中说有17个坑,其实是16个 全文如下 这篇文章主要介绍了Python程序员代码编写时应该避免的16个“坑”,也可以说成Python程序员代码 ...

  9. Ubuntu 常见错误--Could not get lock

    问题产生的原因:另外一个程序正在运行,导致资源被锁不可用.而导致资源被锁的原因可能是上次运行安装或更新时没有正常完成,进而出现此状况 解决问题的办法:sudo rm /var/cache/apt/ar ...

  10. 【Spring Task】定时任务详解实例-@Scheduled

    Spring的任务调度,采用注解的形式 spring的配置文件如下,先扫描到任务的类,打开spirng任务的标签 <beans xmlns="http://www.springfram ...