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. PHP环境搭建-记录

    转于 http://jingyan.baidu.com/article/fcb5aff797ec41edaa4a71c4.html php5.5 做了大量的更新,在与apache搭配的时候如何选择也很 ...

  2. LeetCode:16. 3Sum Closest(Medium)

    1. 原题链接 https://leetcode.com/problems/3sum-closest/description/ 2. 题目要求 数组S = nums[n]包含n个整数,找出S中三个整数 ...

  3. 「日常训练」 Mike and Frog (CFR305D2C)

    题意与分析 (Codeforces 548C) 我开始以为是一条数学题,死活不知道怎么做,无奈看题解,才知这是一条暴力,思维江化了- - 题意大概是这样的: 两个东西的初始高度分别为h1,h2&quo ...

  4. 【个人训练】(UVa146)ID Codes

    题意与解析 这题其实特别简单,求给定排列的后继.使用stl(next_permutation)可以方便地解决这个问题.但是,想要自己动手解就是另外一回事了.我的解法是从后往前找到第一个$a_i$比$a ...

  5. CSS层叠样式表的解释

    css:    在标签上设置style属性css注释:     /*z注释内容*/css样式的编写位置:    1.在标签的的style属性里    2.在head里面,style标签中写样式     ...

  6. 剑指offer-斐波那契数列07

    题目描述 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0). n<=39 class Solution: def Fibonacci(self ...

  7. erc20代币合约

    看这篇文章需要对以太坊,智能合约,代币等概念有基本的了解. 什么是ERC20 可以把ERC20简单理解成以太坊上的一个代币协议,所有基于以太坊开发的代币合约都遵守这个协议.遵守这些协议的代币我们可以认 ...

  8. java设计模式之模版方法模式以及在java中作用

    模板方法模式是类的行为模式.准备一个抽象类,将部分逻辑以具体方法以及具体构造函数的形式实现,然后声明一些抽象方法来迫使子类实现剩余的逻辑.不同的子类可以以不同的方式实现这些抽象方法,从而对剩余的逻辑有 ...

  9. MyBatis实例教程--开发环境搭建

    MyBatis实例教程--开发环境搭建 准备工作: 1.mybatis 的开发环境搭建,选择: eclipse j2ee 版本,mysql 5.1 ,jdk 1.7,mybatis3.2.0.jar包 ...

  10. HDU 4433 locker(DP)(2012 Asia Tianjin Regional Contest)

    Problem Description A password locker with N digits, each digit can be rotated to 0-9 circularly.You ...