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 ...
随机推荐
- python爬取豆瓣流浪地球影评,生成词云
代码很简单,一看就懂. (没有模拟点击,所以都是未展开的) 地址: https://movie.douban.com/subject/26266893/reviews?rating=&star ...
- 《史上最简单的MySQL教程》系列分享专栏
<史上最简单的MySQL教程>系列分享专栏 <史上最简单的MySQL教程>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/read ...
- Windows Store App下代码加载page resource和resw文件里的string
加载page resource 在page的code behind里: this.Resources["textBoxStyle"] 加载resw文件里的string: Resou ...
- 实现一个带有指纹加密功能的笔记本(Android)第一部分
自己经常会忘记一些密码什么的,想把这些密码保存下来,但是别人做的软件总有一点不安全的感觉,所以自己动手做了一个带有指纹加密的笔记本. 以下是本工程用到的一些第三方包 compile 'org.gree ...
- PHP.41-TP框架商城应用实例-后台16-商品属性2-AJAX添加、删除
添加商品属性 思路:根据[后台15]类型表{id,type_name}与属性表{id,attr_name,attr_type,attr_option_values,type_id} 1.建表商品属性 ...
- [bzoj5158][Tjoi2014]Alice and Bob
好羞愧啊最近一直在刷水... 题意:给定序列$c$的$a_i$,构造出一个序列$c$使得$\sum b_i$最大. 其中$a_i$表示以$c_i$结尾的最长上升子序列长度,$b_i$表示以$c_i$为 ...
- Microsoft Security Essentials 和 Windows Defender 离线升级包下载地址
自从微软提供了免费的杀毒软件之后我就卸载掉了其他的杀毒软件.但是最近遇到了个小问题,我这里有一批电脑不能联网,杀毒软件的升级成了问题.在网上搜索了一番,终于找到了官方的离线升级包下载地址.放在这里备用 ...
- Django笔记 —— 模型高级进阶
最近在学习Django,打算玩玩网页后台方面的东西,因为一直很好奇但却没怎么接触过.Django对我来说是一个全新的内容,思路想来也是全新的,或许并不能写得很明白,所以大家就凑合着看吧- 本篇笔记(其 ...
- 【性能调优】一次关于慢查询及FGC频繁的调优经历
以下来分享一个关于MySQL数据库慢查询和FGC频繁的性能案例. 一.系统架构 一个简单的dubbo服务,服务提供者提供接口,并且提供接口的实现,提供方注册服务到Zookeeper注册中心,然后消费者 ...
- MySQL☞between ... and ...
between 初值 and 终值:求出该列列值在初值和终值之间所有的数据 格式如下: select 列名/* from 表名 where 列名 between 初值 and 终值 如下图: