当前位置:网站首页>Krypton binary
Krypton binary
2022-04-23 06:46:00 【Round moon】
Binary system
Title Description
You are an algorithm enthusiast , I'm trying to learn computer knowledge . You know, , The most beautiful thing about computers is binary , You are pressing on this point o I have deep experience in it , Of course, binary is used in co and o It's also very clever , Not to mention T say nini Games can follow xor It's a matter of fact , And today you have another binary problem , For you who love to think , I decided to cut off this binary problem all the time .
You come across a lot of decimal numbers , For these numbers , They all manage their corresponding layers , Such as digital 8, Its binary is 1, Then it manages 4(10),2(10), Two segments , When the numbers break in 2,4 When the interval increases , Foam stands for binary (10) and (10) Two floors in [2,4] The interval increases 3.
This question has two operations , Read into one opt
opt by 1 when : Read in a number qi, An interval li, ri And an increased value ki, Indicates that each interval in the hierarchy managed by this number increases ki value .
opt by 2 when : Read in a number ai, An interval li,ri, Represents the sum of the values of each interval in the hierarchy managed by this number .
Input
The first line has two integers n,q, Express n Indicates the interval length (1≤li ≤ri ≤n≤100000),q Express q(1≤q≤100000) operations . Data assurance (1≤ai≤1024),ki stay int Within the scope of
Back q That's ok , Each line starts with a number opt Indicates the operation performed
opt= 1 When followed by an integer ai Indicates management hierarchy ,li,ri Indicates the interval ,ki Indicates the increased value opt= 2 When followed by an integer ai Indicates management hierarchy ,li,ri Indicates the interval
Output
For each second operation , Output a line indicating the answer to the query .
Sample Input
5 3
1 3 1 5 2
2 1 1 2
2 3 1 2
Sample Output
4
8
Thinking analysis
open 12 A line tree , Don't ask why 12 One question is that I don't want to get stuck .
Then detect that the binary bit of the number is 1 The serial number of , Push ( queue ), Then maintain the segment tree of the serial number in turn .
At the last reading , It is also to query the line segment tree of all serial numbers , Just ask for a peace OK 了 .
Accepted Code
//#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<string.h>
#include <iomanip>
#include<stdio.h>
#include<vector>
#include<string>
#include<math.h>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll ll_inf = 9223372036854775807;
const int int_inf = 2147483647;
const short short_inf = 32767;
const ll less_inf = 0x3f3f3f3f;
const char char_inf = 127;
#pragma GCC optimize(2)
#define accelerate cin.tie(NULL);cout.tie(NULL);ios::sync_with_stdio(false);
#define PI 3.141592653589793
#define EPS 1.0e-8
ll gcd(ll a, ll b) {
return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
inline ll read() {
ll c = getchar(), Nig = 1, x = 0;
while (!isdigit(c) && c != '-')c = getchar();
if (c == '-')Nig = -1, c = getchar();
while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
return Nig * x;
}
inline void out(ll a) {
if (a < 0)putchar('-'), a = -a;
if (a > 9)out(a / 10);
putchar(a % 10 + '0');
}
ll qpow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
#define read read()
const int N = 100007;
struct node
{
ll sum, num;
bool lazy;
}tree[12][N << 2];
void pushup(int k, int rt)
{
tree[k][rt].sum = tree[k][rt << 1].sum + tree[k][rt << 1|1].sum;
}
void pushdown(int k, int len, int rt)
{
if (tree[k][rt].lazy)
{
tree[k][rt << 1].lazy = tree[k][rt << 1 | 1].lazy = true;
tree[k][rt].lazy = false;
tree[k][rt << 1].num += tree[k][rt].num;
tree[k][rt << 1 | 1].num += tree[k][rt].num;
tree[k][rt << 1].sum += tree[k][rt].num * (len - (len >> 1));
tree[k][rt << 1 | 1].sum += tree[k][rt].num * (len >> 1);
tree[k][rt].num = 0;
}
}
void update(int L, int R, ll val, int k, int l, int r, int rt)
{
if (L <= l && r <= R)
{
tree[k][rt].lazy = true;
tree[k][rt].num += val;
tree[k][rt].sum += (r - l + 1) * val;
return;
}
pushdown(k, r - l + 1, rt);
int mid = l + r >> 1;
if (L <= mid)update(L, R, val, k, l, mid, rt << 1);
if (R >= mid + 1)update(L, R, val, k, mid + 1, r, rt << 1 | 1);
pushup(k, rt);
}
ll query(int L, int R, int k, int l, int r, int rt)
{
if (L <= l && r <= R)return tree[k][rt].sum;
pushdown(k, r - l + 1, rt);
int mid = l + r >> 1;
ll res = 0;
if (L <= mid)res += query(L, R, k, l, mid, rt << 1);
if (R > mid)res += query(L, R, k, mid + 1, r, rt << 1 | 1);
return res;
}
stack<ll>s;
int main()
{
accelerate;
int n, m;
cin >> n >> m;
while (m--)
{
ll mark, id;
cin >> mark >> id;
if (mark == 1)
{
for (ll i = 1, cnt = 0; i <= 1024; i <<= 1, cnt++)
if (i & id)s.push(cnt);
ll l, r, val;
cin >> l >> r >> val;
while (!s.empty())
{
ll now = s.top();
s.pop();
update(l, r, val, now, 1, n, 1);
}
}
else
{
for (ll i = 1, cnt = 0; i <= 1024; i <<= 1, cnt++)
if (i & id)s.push(cnt);
ll ans = 0;
ll l, r;
cin >> l >> r;
while (!s.empty())
{
ll now = s.top();
s.pop();
ans += query(l, r, now, 1, n, 1);
}
cout << ans << endl;
}
}
}
By-Round Moon
版权声明
本文为[Round moon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230549499537.html
边栏推荐
- realsense 选型大对比D455 D435i D415 T265 3D硬件对比
- Initialization of classes and objects (constructors and destructors)
- TensorFlow张量介绍
- Interprocess communication - mutex
- C language advanced notes 3
- C语言进阶要点笔记2
- 相机标定:关键点法 vs 直接法
- C语言实现memcpy、memset、strcpy、strncpy、strcmp、strncmp、strlen
- [UDS unified diagnostic service] II. Network layer protocol (2) - data transmission rules (single frame and multi frame)
- FOC SVPWM函数PWMC_SetPhaseVoltage解析
猜你喜欢
![[UDS unified diagnosis service] IV. typical diagnosis service (1) - diagnosis and communication management function unit](/img/4f/7ca6505b545fb825b0dba36f474da7.png)
[UDS unified diagnosis service] IV. typical diagnosis service (1) - diagnosis and communication management function unit

记第一次使用阿里字体图标库

CUDA project encountered a series of compilation problems after changing the environment (computer)

copy constructor

【UDS统一诊断服务】二、网络层协议(1)— 网络层概述与功能

Shell脚本 &&和||的使用
![[UDS unified diagnostic service] IV. typical diagnostic service (2) - data transmission function unit](/img/22/c501c79176a93345dc72ff150c53c3.png)
[UDS unified diagnostic service] IV. typical diagnostic service (2) - data transmission function unit
![C [document operation] PDF files and pictures are converted to each other](/img/6b/0742aa3eb45fbca091d6d20bc55326.png)
C [document operation] PDF files and pictures are converted to each other
[ThreadX] h743 + ThreadX + Filex migration record

浮点数双精度,单精度以及半精度知识总结
随机推荐
[UDS unified diagnostic service] II. Network layer protocol (2) - data transmission rules (single frame and multi frame)
约瑟夫序列 线段树 O(nlogn)
OpenCV使用 GenericIndex 进行 KNN 搜索
QT icon application
C51/C52 特殊功能寄存器表
SDOI2009-HH的项链
四元数乘法
【UDS统一诊断服务】四、诊断典型服务(1)— 诊断和通信管理功能单元
Running QT program in visual Stdio
Palindromic Primes
金额输入框,用于充值提现
Notes on advanced points of C language 5
ARM常用汇编指令
Eigen 库常用基本用法 备忘
CUDA project encountered a series of compilation problems after changing the environment (computer)
ES6面试题(参考文档)
卷积神经网络实现CIFAR100数据集分类
C语言数组处理批量数据
基于VGG对五种类别图片的迁移学习
Cross domain issues - allow origin header contains multiple values but only one is allowed