HDU 多校对抗 F Naive Operations
Naive Operations
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Others)
Total Submission(s): 2691 Accepted Submission(s): 1183
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⌋
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.
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
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的更多相关文章
- HDU 多校对抗第三场 L Visual Cube
Problem L. Visual Cube Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java ...
- 杭电多校第二场 hdu 6315 Naive Operations 线段树变形
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- HDU 6351 Naive Operations(线段树)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=6315 Naive Operations Time Limit: 6000/3000 MS (Java/O ...
- hdu Naive Operations 线段树
题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 ...
- 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 ...
- HDU 6315: Naive Operations
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- HDU6315 Naive Operations(多校第二场1007)(线段树)
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
- 2018 HDU多校第三场赛后补题
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
随机推荐
- IO复用——select系统调用
1.select函数 此函数用于在一段时间内,监听用户感兴趣的文件描述符上的可读.可写和异常等事件. #include<sys/select.h> int select(int nfds, ...
- go学习笔记-流程控制(if/else,for/range)
流程控制(if/else,for/range) if if条件判断语句的语法概括起来就是:如果满足条件就做某事,否则做另一件事. func testIf() { num := 10 if num &l ...
- AOP原理??
面向切面编程,在我们的应用中,经常需要做一些事情,但是这些事情与核心业务无关,比如,事务.日志.权限拦截.统一异常处理等等.Spring AOP使用了代理模式. Spring AOP底层利用两种代理模 ...
- .Net 面试题 汇总(一)
1.@page指令只能在_aspx___文件(填写扩展名)中使用,而@Control指令只能用在_ascx___文件(填写扩展名)中使用. 2.说明控件DataGrid,DataTable,DataV ...
- js分类多选全选
效果如图: HTML代码: <div class="form-group quanxian-wrap"> <label>项目</label> & ...
- poorpool 的 考场 NOI Linux 配置
把~/.bashrc里的force_color_prompt=yes前面那个#去掉,终端就有高亮啦qwq!(然后source一下 然后vim ~/.vimrc然后加入 (为什么不改/etc/vim/v ...
- mongodb 安装使用遇到的问题记录
mongodb 常用命令: https://www.mongodb.org/downloads 官网64位下载链接 https://fastdl.mongodb.org/linux/mongodb-l ...
- Spring研磨分析、Quartz任务调度、Hibernate深入浅出系列文章笔记汇总
Spring研磨分析.Quartz任务调度.Hibernate深入浅出系列文章笔记汇总 置顶2017年04月27日 10:46:45 阅读数:1213 这系列文章主要是对Spring.Quartz.H ...
- Qt Charts_Audio实践
这里完全是照搬帮助文档中的代码生成的程序 上预览图 工程文件代码 #------------------------------------------------- # # Project crea ...
- SVN脱离锁定的几种方法
SVN经常出现被锁定而无法提交的问题,选择解锁又提示没有文件被锁定,很是头疼.这里整理了一下SVN 被锁定的几种解决方法: 1.出现这个问题后使用“清理”即"Clean up"功能 ...