Naive Operations

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Others)
Total Submission(s): 2691    Accepted Submission(s): 1183

Problem Description
In a galaxy far, far away, there are two integer sequence a and b of length n.
b is a static permutation of 1 to n. Initially a is filled with zeroes.
There are two kind of operations:
1. add l r: add one for al,al+1...ar
2. query l r: query ∑ri=l⌊ai/bi⌋
 
Input
There are multiple test cases, please read till the end of input file.
For each test case, in the first line, two integers n,q, representing the length of a,b and the number of queries.
In the second line, n integers separated by spaces, representing permutation b.
In the following q lines, each line is either in the form 'add l r' or 'query l r', representing an operation.
1≤n,q≤100000, 1≤l≤r≤n, there're no more than 5 test cases.
 
Output
Output the answer for each 'query', each one line.
 
Sample Input
5 12
1 5 2 4 3
add 1 4
query 1 4
add 2 5
query 2 5
add 3 5
query 1 5
add 2 4
query 1 4
add 2 5
query 2 5
add 2 2
query 1 5
 
Sample Output
1
1
2
4
4
6
 

题意:初始时有一段长度为n的数组a为0,长度为n的数组b,给你数组b

  有操作add,把区间[l,r]内每一个ai+1,query,查询操作。 区间 a[i]/b[i]向下取整的和。

题解:

我们每次区间加一,变成把每个值减一,每次减到0的时候ai/bi的值就会+1,用cnt记录,再把值重新更新为bi,查询的时候查询+1 的总和。

用线段树保留最小值,当出现最小值为0的时候把cnt++,值更新为b[r],因为每次只会加+1所以总数不会太大

zzq的做法

考虑维护 的这样的最小的 ,每次 加一的时候 就减
一,一旦 变成 了那么就需要把 加一,这样两个线段树维护一下就行了。
注意到 由于 是排列是 的,那么复杂度就是 。

代码如下:

#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = 1e5+;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9+;
const double eps = 1e-;
int b[*maxn];
int n,q;
int dat[*maxn];
int lazy[*maxn];
int res;
int cnt[maxn*];
void init(int l,int r,int k){
int chl=k<<|,chr=(k+)<<,mid=(l+r)/;
if(r-l==){
lazy[k]=cnt[k]=;
dat[k]=b[r];
return ;
}else{
lazy[k]=cnt[k]=;
init(l,mid,chl);
init(mid,r,chr);
dat[k]=min(dat[chl],dat[chr]);
}
}
int sum(int a,int c,int l,int r,int k){
int chl=k<<|,chr=(k+)<<,mid=(l+r)/;
if(c<=l||a>=r){
return ;
}else if(a<=l&&r<=c){
return cnt[k];
}else {
lazy[chl]+=lazy[k];
lazy[chr]+=lazy[k];
lazy[k]=;
dat[k]=min(dat[chl]+lazy[chl],dat[chr]+lazy[chr]);
return sum(a,c,l,mid,chl)+sum(a,c,mid,r,chr);
}
}
void updata(int a,int c,int l ,int r , int k){
int chl=k<<|,chr=(k+)<<,mid=(l+r)/;
if(c<=l||a>=r){
return;
}else if(a<=l&&r<=c){
if(lazy[k]+dat[k]-<=){
if(r-l==){
cnt[k]++;
dat[k]=b[r];
lazy[k]=;
return;
}
lazy[chl]+=lazy[k];
lazy[chr]+=lazy[k];
lazy[k]=;
updata(a,c,l,mid,chl);
updata(a,c,mid,r,chr);
if(r-l!=){
cnt[k]=cnt[chl]+cnt[chr];
dat[k]=min(dat[chl]+lazy[chl],dat[chr]+lazy[chr]);
}
return;
}
lazy[k]--;
}else{
lazy[chl]+=lazy[k];
lazy[chr]+=lazy[k];
updata(a,c,l,mid,chl);
updata(a,c,mid,r,chr);
lazy[k]=;
dat[k]=min(dat[chl]+lazy[chl],dat[chr]+lazy[chr]);
if(r-l!=) cnt[k]=cnt[chl]+cnt[chr];
}
}
char ch[];
int l,r;
int main(){
#ifndef ONLINE_JUDGE
FIN
#endif
while(scanf("%d%d",&n,&q) !=EOF){
for(int i=;i<=n;i++){
scanf("%d",&b[i]);
}
init(,n,);
while(q--){
scanf("%s %d %d",ch,&l,&r);
if(ch[]=='a'){
updata(l-,r,,n,);
}else{
printf("%d\n",sum(l-,r,,n,));
}
}
}
return ;
}
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#define L long long
using namespace std;
const int q=;
int n,m,t,c[][],f[][],x[],a[],b[],p;
int main()
{
int i,j,k,l;
for(i=;i<=;i++)
{
c[i][]=;
for(j=;j<=i;j++)
c[i][j]=(c[i-][j]+c[i-][j-])%q;
}
x[]=;
for(i=;i<=;i++)
x[i]=(x[i-]<<)%q;
while(scanf("%d%d",&n,&m)!=EOF)
{
scanf("%d%d",&i,&j);
a[i]=;
for(k=i+;k<=n;k++)
{
a[k]=;
for(l=i;l<k;l++)
a[k]=(a[k]-(L)a[l]*c[k][l])%q;
}
b[j]=;
for(k=j+;k<=m;k++)
{
b[k]=;
for(l=j;l<k;l++)
b[k]=(b[k]-(L)b[l]*c[k][l])%q;
}
for(k=i;k<=n;k++)
for(l=j;l<=m;l++)
f[k][l]=(L)c[n][k]*c[m][l]%q*x[(n-k)*(m-l)]%q;
p=;
for(k=i;k<=n;k++)
for(l=j;l<=m;l++)
p=(p+(L)f[k][l]*a[k]%q*b[l])%q;
p=(p+q)%q;
printf("%d\n",p);
}
return ;
}

HDU 多校对抗 F Naive Operations的更多相关文章

  1. HDU 多校对抗第三场 L Visual Cube

    Problem L. Visual Cube Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java ...

  2. 杭电多校第二场 hdu 6315 Naive Operations 线段树变形

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  3. HDU 6351 Naive Operations(线段树)

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=6315 Naive Operations Time Limit: 6000/3000 MS (Java/O ...

  4. hdu Naive Operations 线段树

    题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 ...

  5. hdu 6315 Naive Operations (2018 Multi-University Training Contest 2 1007)

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  6. HDU 6315: Naive Operations

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  7. HDU6315 Naive Operations(多校第二场1007)(线段树)

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  8. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  9. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

随机推荐

  1. C语言实例解析精粹学习笔记——36(模拟社会关系)

    实例: 设计一个模拟社会关系的数据结构,每个人的信息用结构表示,包含名字.性别和指向父亲.母亲.配偶.子女的指针(只限两个子女).要求编写以下函数: (1)增加一个新人的函数 (2)建立人与人之间关系 ...

  2. Python自动化运维——文件内容差异对比

    Infi-chu: http://www.cnblogs.com/Infi-chu/ 模块:difflib 安装:Python版本大于等于2.3系统自带 功能:对比文本之间的差异,而且支持输出可读性比 ...

  3. (数据科学学习手札23)决策树分类原理详解&Python与R实现

    作为机器学习中可解释性非常好的一种算法,决策树(Decision Tree)是在已知各种情况发生概率的基础上,通过构成决策树来求取净现值的期望值大于等于零的概率,评价项目风险,判断其可行性的决策分析方 ...

  4. Spring事务:一种编程式事务,三种声明式事务

    事务隔离级别 隔离级别是指若干个并发的事务之间的隔离程度.TransactionDefinition 接口中定义了五个表示隔离级别的常量: TransactionDefinition.ISOLATIO ...

  5. python操作nosql数据库之memcache

    一.memcache的安装 1.memcache简介 Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象减少读取数据库的次数,从而 ...

  6. 根据生产场景对Linux系统进行分区

    转自:http://oldboy.blog.51cto.com/2561410/629558 老鸟谈生产场景如何对linux系统进行分区? █  前言:    我们买房子时,会考虑1室1厅,2室1厅, ...

  7. .NET基础知识之八——深拷贝,浅拷贝

    目录 1.概念 2.使用赋值符号"=" 3.浅复制 4.深复制 5.问题一:如果类里面嵌套有多个类,然后嵌套类里面又嵌套类,那么像上面实现深拷贝的方法还能用吗? 6.问题二:实现深 ...

  8. Linux初步——常用简单命令

    散乱的记录,目前是边学边用,以后有机会再整理 curl命令 发起一个HTTP请求,如:curl "http://www.baidu.com" 加上-I选项查看HTTP协议头的信息, ...

  9. Python 3基础教程32-正则

    本文介绍Python的正则,通过本文介绍和一个练习,对正则有一个基本了解就可以. # 正则表达式 ''' 正则表达式是有一些特殊字符组成,能够帮你找到一些符合一定规则的字符串 先来了解几个符号所代表的 ...

  10. jquery UI 跟随学习笔记——拖拽(Draggable)

    引言 这周暂时没有任务下达,所以老大给我的任务就是熟悉jquery相关插件,我就先选择了jquery UI插件,以及jquery库学习. 我用了两天的时候熟悉Interactions模块中的Dragg ...