首页 > 其他分享 >P8969 幻梦 | Dream with Dynamic

P8969 幻梦 | Dream with Dynamic

时间:2024-10-18 20:00:31浏览次数:1  
标签:P8969 return int LL Dynamic popcount 幻梦 include define

Sol

好题!

注意到 popcount 操作会使数以 \(\log\) 的速度变小,所以没有加操作的话我们就可以直接暴力维护。

但是注意到有加操作,考虑懒标记,先 popcount 后加。

当一个区间 popcount 之后,值域范围极小,所以考虑暴力对每一种数预处理 popcount。

这里其实可以用线段树但是我懒了,用了分块。

Code

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cassert>
#include <chrono>
#include <random>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define desktop "C:\\Users\\MPC\\Desktop\\"
#define IOS ios :: sync_with_stdio (false),cin.tie (0),cout.tie (0)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> PII;
const int dx[] = {1,0,-1,0},dy[] = {0,-1,0,1};
template <typename T1,typename T2> bool tomax (T1 &x,T2 y) {
    if (y > x) return x = y,true;
    return false;
}
template <typename T1,typename T2> bool tomin (T1 &x,T2 y) {
    if (y < x) return x = y,true;
    return false;
}
LL power (LL a,LL b,LL p) {
    LL ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return ans;
}
#define popcount(x) __builtin_popcountll (x)
int fastio = (IOS,0);
#define endl '\n'
#define puts(s) cout << s << endl
const int N = 300010,B = 1010;
int n,q;
LL a[N];
bool vis[51];
int pos[N];
struct block {
	int l,r;
	bool flag;
	int to[51];
	LL add;
	void push_down () {
		if (!flag) for (int i = l;i <= r;i++) a[i] += add;
		else for (int i = l;i <= r;i++) a[i] = to[a[i]] + add;
		flag = add = 0;
	}
	void opt_add (LL k) {
		add += k;
	}
	void opt_popcount () {
		if (!flag) {
			memset (vis,0,sizeof (vis));
			for (int i = l;i <= r;i++) {
				a[i] = popcount (a[i] + add);
				vis[a[i]] = true;
			}
			for (int i = 1;i <= 50;i++) {
				if (vis[i]) to[i] = i;
			}
		}
		else {
			for (int i = 1;i <= 50;i++) to[i] = popcount (to[i] + add);
		}
		add = 0,flag = true;
	}
}b[N];
void modify_add (int l,int r,int k) {
	int p = pos[l],q = pos[r];
	if (p == q) {
		b[p].push_down ();
		for (int i = l;i <= r;i++) a[i] += k;
	}
	else {
		for (int i = p + 1;i <= q - 1;i++) b[i].opt_add (k);
		b[p].push_down (),b[q].push_down ();
		for (int i = l;i <= b[p].r;i++) a[i] += k;
		for (int i = b[q].l;i <= r;i++) a[i] += k;
	}
}
void modify_popcount (int l,int r) {
	int p = pos[l],q = pos[r];
	if (p == q) {
		b[p].push_down ();
		for (int i = l;i <= r;i++) a[i] = popcount (a[i]);
	}
	else {
		for (int i = p + 1;i <= q - 1;i++) b[i].opt_popcount ();
		b[p].push_down (),b[q].push_down ();
		for (int i = l;i <= b[p].r;i++) a[i] = popcount (a[i]);
		for (int i = b[q].l;i <= r;i++) a[i] = popcount (a[i]);
	}
}
LL query (int x) {
	int p = pos[x];
	if (!b[p].flag) return a[x] + b[p].add;
	return b[p].to[a[x]] + b[p].add;
}
int main () {
	cin >> n >> q;
	for (int i = 1;i <= n;i++) cin >> a[i];
	for (int i = 1;i <= n;i++) pos[i] = (i - 1) / B + 1;
	for (int i = 1;(i - 1) * B + 1 <= n;i++) b[i].l = (i - 1) * B + 1,b[i].r = min (i * B,n);
	while (q--) {
		char op;
		cin >> op;
		if (op == 'A') {
			int l,r,k;
			cin >> l >> r >> k;
			modify_add (l,r,k);
		}
		else if (op == 'P') {
			int l,r;
			cin >> l >> r;
			modify_popcount (l,r);
		}
		else {
			int x;
			cin >> x;
			cout << query (x) << endl;
		}
	}
	return 0;
}

标签:P8969,return,int,LL,Dynamic,popcount,幻梦,include,define
From: https://www.cnblogs.com/incra/p/18474948

相关文章

  • DBPM: 增强时间序列对比学习:一种动态坏对挖掘方法《Towards Enhancing Time Series Co
    今天是2024年10月12日,思路枯竭,还是论文看的太少了,继续看论文.论文:TowardsEnhancingTimeSeriesContrastiveLearning:ADynamicBadPairMiningApproach或者是:TowardsEnhancingTimeSeriesContrastiveLearning:ADynamicBadPairMiningApproachGitHub:https://git......
  • ME 588, Dynamics and Vibration
    ME588,DynamicsandVibrationHomework1Distributed:9/25/2024,Due:10/11/20241.Consideraspring-masssystemmountedonaspinningdiskasshowninFig.1.Thediskspinsatconstantangularvelocityω.Moreover,thediskhasadiametricalslot,alo......
  • 65_索引管理_定制化自己的dynamic mapping策略
    课程大纲1、定制dynamic策略true:遇到陌生字段,就进行dynamicmappingfalse:遇到陌生字段,就忽略strict:遇到陌生字段,就报错PUT/my_index{"mappings":{"my_type":{"dynamic":"strict","properties":{"title":{"type":&......
  • 【笔记】Dynamic Taint Analysis 动态污点分析
    DynamicTaintAnalysis动态污点分析什么是动态污点分析?为什么要搞动态污点分析?“污点”指的是什么?DTA中的“污点”指代的是不可信的输入,比如用户输入、网络请求、文件数据等。比方说,如果把程序看作一个城市,外部输入的数据就像来自外界的货物。有些货物可能携带危险物质(恶意输......
  • ADAU1701的Dynamics Processors算法补充例程合集(10个例程)
    作者的话做ADAU1701,心血来潮,再过了一遍SigmaDSP的算法合辑,发现有不少遗留的,比较有特点的算法,就在这个系列文章里一一呈现吧。ADAU1701我写了超过100个例程,但是都很早期,2018年开始弄的,我感觉并不是很全,那这一次就彻底把他补全一下,这个系列文章,将把我能够找到的,ADI原厂提供......
  • WPF dynamically generate grid with calculated rows and columns, put the custom c
    privatevoidFillGridRandomly(){rowsColsSet=newHashSet<XY>();if(gd!=null){gd.Children.Clear();}for(inti=0;i<50;i++){while(true){XYxy=newXY();......
  • YOLOv8改进 | 检测头篇 | 利用DynamicHead增加辅助检测头针对性检测(四头版本)
    鱼弦:公众号【红尘灯塔】,CSDN博客专家、内容合伙人、新星导师、全栈领域优质创作者、51CTO(Top红人+专家博主)、github开源爱好者(go-zero源码二次开发、游戏后端架构https://github.com/Peakchen)YOLOv8改进|检测头篇|利用DynamicHead增加辅助检测头针对性检测(四头版......
  • Dynamic Locomotion in the MIT Cheetah 3 Through Convex Model-Predictive Control
    1.SwingLegControl\(J_i\inR^{3*3}\)是足端雅可比;\(\tau_{i,ff}\)是前馈力矩\(\Lambda\inR^{3*3}\)是操作空间惯性矩阵;\(a_{i,ref}\inR^{3*3}\)是机体坐标系下的参考加速度q是关节角度;\(C_i\dot{q}_i+G_i\)是科里奥利力和重力2.GroundForceControl\(\tau......
  • AnomalyLLM: Few-shot Anomaly Edge Detection for Dynamic Graphs using Large Langu
    本文是LLM系列文章,针对《AnomalyLLM:Few-shotAnomalyEdgeDetectionforDynamicGraphsusingLargeLanguageModels》的翻译。AnomalyLLM:使用大型语言模型对动态图进行少量异常边缘检测摘要1引言2相关工作3前言4方法5实验6结论摘要检测动态图的......
  • C# 新技能 DynamicExpresso 动态表达式解析器
    目录前言项目介绍项目特点项目应用项目示例1、参数2、返回值3、生成动态委托4、Lambda表达式5、特殊标识符项目地址最后前言项目开发中有时候我们需要快速地执行一些小脚本,不想每次都去生成编译整个项目。这时如果有一个好用的动态表达式解析器那就就特别方......