hdu 4288 离线线段树+间隔求和

计算分子相似度(摩根分子指纹计算) import numpy as np import pandas as pd import seaborn as sns import matplotlib as plt from rdkit.Chem import Draw from rdkit.Chem import AllChem as Chem from rdkit.Chem import PandasTools from rdkit import DataStructs data = pd.read_csv(r'47_covidLead.csv' 阅读详情

Coder

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4838    Accepted Submission(s): 1853


Problem Description
  In mathematics and computer science, an algorithm describes a set of procedures or instructions that define a procedure. The term has become increasing popular since the advent of cheap and reliable computers. Many companies now employ a single coder to write an algorithm that will replace many other employees. An added benefit to the employer is that the coder will also become redundant once their work is done. 1
  You are now the signle coder, and have been assigned a new task writing code, since your boss would like to replace many other employees (and you when you become redundant once your task is complete).
Your code should be able to complete a task to replace these employees who do nothing all day but eating: make the digest sum.
  By saying “digest sum” we study some properties of data. For the sake of simplicity, our data is a set of integers. Your code should give response to following operations:
  1. add x – add the element x to the set;
  2. del x – remove the element x from the set;
  3. sum – find the digest sum of the set. The digest sum should be understood by

  where the set S is written as {a1, a2, ... , ak} satisfying a1 < a2 < a3 < ... < ak 
  Can you complete this task (and be then fired)?
------------------------------------------------------------------------------
1 See http://uncyclopedia.wikia.com/wiki/Algorithm
 

Input
  There’re several test cases.
  In each test case, the first line contains one integer N ( 1 <= N <= 105 ), the number of operations to process.
  Then following is n lines, each one containing one of three operations: “add x” or “del x” or “sum”.
  You may assume that 1 <= x <= 109.
  Please see the sample for detailed format.
  For any “add x” it is guaranteed that x is not currently in the set just before this operation.
  For any “del x” it is guaranteed that x must currently be in the set just before this operation.
  Please process until EOF (End Of File).
 

Output
  For each operation “sum” please print one line containing exactly one integer denoting the digest sum of the current set. Print 0 if the set is empty.
 

Sample Input
9 add 1 add 2 add 3 add 4 add 5 sum add 6 del 3 sum 6 add 1 add 3 add 5 add 7 add 9 sum
 

Sample Output
3 4 5


/*
hdu 4288 离线线段树+间隔求和
分别有添加,删除,求和
sum是求 i%5==3的所有数的和,而且数列满足a[0] < a[1] ......
开始以为只会在数列后面添加,然后WR
而且最开始觉得求和很麻烦,于是试了下暴力点的TLE

所以先对所有要用的数进行处理,然后每次找出它们应该在的位置,进行插入删除即可。
主要是没想到两边有规律能推出公式,sum[j]保存当前区间mod 5为j的和
tree[i].sum[j]=(ll)(tree[lson].sum[j]+tree[rson].sum[((j-tree[lson].cnt)%5+5)%5]);

hhh-2016-03-02 23:14:26
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <vector>
#define lson (i<<1)
#define rson (i<<1|1)
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 500000+10;
int x[maxn];
int tp[maxn],tot;
char opr[maxn][10];
struct node
{
    int l,r;
    ll sum[6];
    int cnt;
    int mid()
    {
        return (l+r)>>1;
    }
} tree[maxn<<2];
int flag;
void push_up(int i)
{
    for(int j = 0; j < 5; j++)
    {
        tree[i].sum[j] = (ll)(tree[lson].sum[j]+tree[rson].sum[((j-tree[lson].cnt)%5+5)%5]);
    }
}

void build(int i,int l,int r)
{
    tree[i].l=l,tree[i].r=r;
    tree[i].cnt = 0;
    memset(tree[i].sum,0,sizeof(tree[i].sum));
    int mid = tree[i].mid();
    if(l == r)
        return;
    build(lson,l,mid);
    build(rson,mid+1,r);
}

void update(int i,int k,int val)
{
    tree[i].cnt += 2*flag-1;
    if(tree[i].l == k && tree[i].r == k)
    {
        tree[i].sum[0] = flag*val;
        return ;
    }
    int mid = tree[i].mid();
    if(k <= mid)update(lson,k,val);
    else update(rson,k,val);
    push_up(i);
}

int Search(int k)
{
    int l = 0,r = tot-1;
    while(l<=r)
    {
        int mid = (l+r)>>1;
        if(tp[mid]<k)
            l = mid+1;
        else if(tp[mid]>k)
            r = mid-1;
        else
            return mid;
    }
}
int main()
{
    int n;
    while(scanf("%d",&n) != EOF)
    {
        tot = 0;
        for(int i = 0; i<n; i++)
        {
            scanf("%s",opr[i]);
            if(opr[i][0] != 's')
            {
                scanf("%d",&x[i]);
                tp[tot++] = x[i];
            }
        }
        sort(tp,tp+tot);
        tot = unique(tp,tp+tot)-tp;//去重
        if(!tot)
            memset(tree[1].sum,0,sizeof(tree[1].sum));
        else
            build(1,0,tot);
        for(int i =0; i < n; i++)
        {
            if(opr[i][0] == 's')
            {
                printf("%I64d\n",tree[1].sum[2]);
            }
            else if(opr[i][0] == 'a')
            {
                flag = 1;
                int pos = Search(x[i]);
                update(1,pos,x[i]);
            }
            else if(opr[i][0] == 'd')
            {
                flag =0 ;
                int pos = Search(x[i]);
                update(1,pos,x[i]);
            }
        }
    }
    return 0;
}




多agv系统调度的MATLAB仿真 从起点出发,到货物点领取货物最后到卸货点,以完成任务总时间最短为目标进行单目标优化,约束条件为,任务不冲突,路径不冲突,要能实现路径规避 ,4-6台agv一起工作。左右货架间隔可通过1个agv,上下货架间隔可通过两个agv,通道为双向行驶通道。一台agv只能带一个货物,优化目标为完成任务总的时间最短,agv的速度是匀速,转弯也不会减速,取货物时间为固定值。上面的图里面货物看为正方形跟agv一样的长度大小,agv试做是跟货物一样大小的正方形agv的速度是每秒1个车身。多台agv一起完成... 阅读详情

相关推荐

PET,CT图像融合笔记

PET-CT怎样进行图像融合?图像融合实现CT与PET图像的融合 OpenCV实现(附实验结果)

chenran187906的博客 8409

hdu3333(线段树离散化离线处理)

#include #include #include using namespace std; typedef long long ll; const int maxn = 30005; int n,m; ll num[maxn],tmp[maxn]; int vis[maxn],pre[maxn]; ll tree[maxn<<2]; struct node { int l,r,pos;

constbh的博客 451

工业视觉光源频闪控制的三种核心模式与选型实战

本文深入解析工业视觉系统中光源频闪控制的三种核心模式:光源主控、相机主控与硬同步。针对高速飞拍、缺陷检测等场景,详细对比了各模式的时序原理、硬件要求与适用场景,并提供了基于产线速度与检测需求的实战选型指南,帮助工程师有效消除运动模糊、提升成像质量与系统稳定性。

weixin_29299807的博客 435

线段树例题 henu Sanzo' 建议

题目链接 题目描述: 输入一个数 n ,接下来一行给定一个长度为 n 的序列,输入一个数 m ,接下来 m 次询问,每次询问输入两个数 l ,r,输出数列中 l ,r区间内的异或和。 异或有这么一些性质 a ^ b ^ a = b a ^ 0 = a 通过这些性质,我们可以知道,一个区间 l ,r 内的异或和等于 [l , r - 1] ^ a[ r ] 或者是 [ l , r + ...

correct 198

Hi3516CV610 YOLOv8模型转换与部署实战:从源码到板端推理全流程解析

本文详细解析了Hi3516CV610开发板上YOLOv8模型的转换与部署全流程,包括模型转换、量化、编译和部署等关键步骤。通过实战案例和避坑指南,帮助开发者高效实现从PyTorch模型到嵌入式设备的推理优化,适用于智能门禁、视频分析等实时场景。

weixin_30790841的博客 654

【数据攻略】字节面试真题(含答案)+100道面试题库

数据攻略

qq_40002713的博客 4102

【线段树 && 离线处理 && 维护区间规定下标的和】HDU - 4288 Coder

Problem Dscription 给你n个操作,操作分为三种,(1): add x,往集合里面添加元素x。(2): del x,从集合里面移除元素x。(3): sum 求下标mod 5 == 3的对应元素值的和。集合满足从小到大 思路: 离线处理:就是先输入完数据后在处理。线段树维护两个量,num代表该区间有几个数。sum[]代表该区间mod5==1的和,mod5==2的和,mod5==

ACMer 梁剑锋 的博客 294

深度理解嵌入(embedding)层

首先从one_hot开始: one_hot的优点:计算方便快捷、表达能力强。 one_hot的缺点:过于稀疏,过于占用资源,尤其是在数据量特别大时;数据之间完全独立。

weixin_44441131的博客 5658

HDU 4288 Coder 【线段树】

题目链接segment tree, single-point update题意维护一个集合,这个集合可进行以下操作: + 向其中添加一个数(保证之前没有这个数) + 向其中删除一个数(保证集合中有这个数) + 求所有下标%5==3的数的和(从小到大排列) 完成给定的操作,返回sum的值分析求区间和问题,尝试使用线段树。然而是求的有步长的和,怎么处理?首先,每个区间中记录下标模5相同的数的和(

Help me up!I can still AC! 492

MounRiver避坑实录:手把手迁移CH32V307 EVT工程到自定义目录

本文详细记录了将沁恒CH32V307的EVT工程迁移到自定义目录的完整流程与避坑指南。针对MounRiver Studio的虚拟链接机制,重点讲解了如何清理旧配置、重新设置头文件路径、链接脚本等关键步骤,帮助开发者创建独立、可维护的MCU项目工程。

uber9的博客 243

EXCEL VBA从入门到精通 第一章:VBA入门

在VBA中,需要使用关键字Dim来定义一个变量,后面跟上变量名和变量的数据类型。例如,下面的代码定义了一个整型变量x和一个字符串变量name在VBA中,使用关键字Const来定义常量,后面跟上常量名和常量的值。例如,下面的代码定义了一个整型常量MAX_NUM和一个字符串常量MESSAGE需要注意的是,常量一旦被定义,其值就不能被改变。

1万+

hdu 4288

这题按我的做法是超时的,虽然开始也知道这应该是个线段树,不过由于之前都是看还没独立写过,所以没去尝试,果然那后面自己的写法超时了,没办法还是得用线段树,可基本不太会怎么办····最后只好先看看别人的代码了,不过能看懂也说明之前线段树的学习是有成效的,好像这题不仅有线段树,还说有离散化什么的,我猜大概意思是把每个下标mod 5的和用线段树表示出来,由于他们是间隔散乱的,如何让他们整合用线段树来表达,

NiaNiaJR的专栏 952

Fiori Elements 从入门到精通开发教程的文章目录

Fiori Elements 开发技术相对 SAP 其他历史悠久,发展成熟的开发技术来说,是一个新事物。正因如此,迄今为止国内深入讲解 Fiori Elements 应用的中文材料几乎没有。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 4757

hdu 4630 查询[L,R]区间内任意两个数的最大公约数

No Pain No Game Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2000    Accepted Submission(s): 851 Problem Description Life is a g

阳光下的泡沫 2622

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

hdu5634 BestCoder Round #73 (div.1)

Rikka with Phi    Accepts: 5    Submissions: 66  Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description Rikka and Yuta are in

阳光下的泡沫 801

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

SPOJ DQUERY树状数组离线or主席树

D-query Time Limit: 227MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Submit Status Description English Vietnamese Given a sequence of n nu

阳光下的泡沫 771

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

2015 多校联赛 ——HDU5316(线段树)

Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an innate talent, gaining it through study and practice, or receiving it from another being, often a g

阳光下的泡沫 700

hdu 4638 树状数组 区间内连续区间的个数(尽可能长)

Group Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1959    Accepted Submission(s): 1006 Problem Description There are n men ,eve

阳光下的泡沫 674

zoj2112 树状数组+主席树 区间动第k大

Dynamic Rankings Time Limit: 10000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Submit Status Description The Company Dynamic Rankings has developed a new k

阳光下的泡沫 650

hdu 4578 线段树(标记处理)

Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) Total Submission(s): 4095    Accepted Submission(s): 1008 Problem Description Yuanfang i

阳光下的泡沫 636

hdu4605 树状数组+离散化+dfs

Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2189    Accepted Submission(s): 634 Problem Description When the m

阳光下的泡沫 610

hdu3340 线段树+多边形

Rain in ACStar Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 788    Accepted Submission(s): 218 Problem Description Maybe you hav

阳光下的泡沫 605

hdu 3436 线段树 一顿操作

Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3348    Accepted Submission(s): 904 Problem Description Ponyo and Gar

阳光下的泡沫 581

hdu 5493 (树状数组)

题意:在一个队列中,你知道一个人在他左边或者右边比他高的人的个数,求字典序最小的答案 思路:先将人按  矮-->高 排序,然后算出在每个人前面需要预留的位置。树状数组(也可以线段树)解决时,先二分查找合适的位置,如果合理则标记,每次查找时    枚举的人数 - 前面已占的人数 = 可预留位置 判断分别在它左边 或者 右边时可能的最小值进行比较。 预留的位置①:pnode[i].num(即比他

阳光下的泡沫 578

hdu 3397 线段树双标记

Sequence operation Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7502    Accepted Submission(s): 2233 Problem Description lxhgww

阳光下的泡沫 563

hdu 2871 线段树(各种操作)

Memory Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5913    Accepted Submission(s): 1380 Problem Description Memory unit

阳光下的泡沫 557
上一篇: hdu 3016 dp+线段树
下一篇: hdu1698 线段树区间更新
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值