世风日下的哗啦啦族I

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://acdream.info/problem?pid=1738

Description

"世风日下啊,女生不穿裙子的太少了"
"这不是社会的进步吗(逃"
"哎,是否可以建立一种结构统计一下各学院各专业各班级女生穿裙子的数量以及裙子的长度"
"然后查询区间裙子最短值?"
"并输出这个区间 穿这个裙子长度的妹子 有多少个?"
"然后判断下在有风的情况下,多少妹子是安全的."

"maya 哗啦啦族真是太可怕啦!"

Input

第一行 n,m表示n个妹子,m个操作
第二行 a1 a2 a3 …… an,n个整数,表示妹子一开始的裙子长度,如果穿的是裤子,ai=-1
下面m行:
总共3种操作
1 a b
修改a妹子的裙子,变成b长度
2 l r
查询[l,r]区间的妹子最短的裙子长度,并输出有多少个妹子穿这个长度裙子的
3 l r t
输出[l,r]区间的妹子身穿裙子长度小于等于t的个数
1<=n,m<=50000
1<=a<=n
1<=b<=50000
1<=ai<=50000
1<=l<=r<=n
0<=t<=50000

Output

根据询问,输出答案

具体看样例

Sample Input

3 3
1 2 3
1 1 4
2 1 3
3 1 3 2

Sample Output

2 1
1

HINT

题意

题解:

分块分块,暴力暴力!

暴力治天下!

(我迷之的二分分块会T……

http://pan.baidu.com/s/1hqu4qBa

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** ll n,q,m,block;
ll a[],b[],pos[],add[];
int minn[];
int num[]; ll find(ll x,ll v)
{
if(minn[x]>v)
return ;
ll l=(x-)*block+,r=min(x*block,n);
int num=;
for(int i=l;i<=r;i++)
if(b[i]<=v)
num++;
else
break;
return num;
/* while(l<r)
{
ll mid=(l+r)>>1;
if(b[mid]<v)
l=mid+1;
else if(b[mid]>v)
r=mid-1;
}
return r-last+1;
*/
} void reset(ll x)
{
ll l=(x-)*block+,r=min(x*block,n);
for(ll i=l;i<=r;i++)
b[i]=a[i];
sort(b+l,b+r+);
minn[x]=b[l];
num[x]=;
for(int i=l;i<=r;i++)
if(b[i]==minn[x])
num[x]++;
else
break;
} void update(ll x,ll v)
{
a[x]=v;
reset(pos[x]);
} ll query(ll x,ll y)
{
ll ans=inf;
if(pos[x]==pos[y])
{
for(int i=x;i<=y;i++)
ans=min(a[i],ans);
}
else
{
for(int i=x;i<=pos[x]*block;i++)
ans=min(ans,a[i]);
for(int i=(pos[y]-)*block+;i<=y;i++)
ans=min(ans,a[i]);
}
for(int i=pos[x]+;i<pos[y];i++)
ans=min(ans,(ll)minn[i]);
return ans;
} int query1(int x,int y,int z)
{
int ans=;
if(pos[x]==pos[y])
{
for(int i=x;i<=y;i++)
{
if(a[i]==z)
ans++;
}
}
else
{
for(int i=x;i<=pos[x]*block;i++)
{
if(a[i]==z)
ans++;
}
for(int i=(pos[y]-)*block+;i<=y;i++)
{
if(a[i]==z)
ans++;
}
}
for(int i=pos[x]+;i<pos[y];i++)
{
if(minn[i]==z)
ans+=num[i];
}
return ans;
} int deal(int x,int y,int z)
{
int ans=;
if(pos[x]==pos[y])
{
for(int i=x;i<=y;i++)
if(a[i]<=z)
ans++;
}
else
{
for(int i=x;i<=pos[x]*block;i++)
if(a[i]<=z)
ans++;
for(int i=(pos[y]-)*block+;i<=y;i++)
if(a[i]<=z)
ans++;
}
for(int i=pos[x]+;i<pos[y];i++)
ans+=find(i,z);
return ans;
} int main()
{
//test;
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout); n=read(),q=read();
block=int(sqrt(n));
for(int i=;i<=n;i++)
{
a[i]=read();
pos[i]=(i-)/block+;
b[i]=a[i];
}
int x,y,v,ch;
if(n%block)m=n/block+;
else m=n/block;
for(int i=;i<=m;i++)reset(i);
for(int i=;i<=q;i++)
{
ch=read();
if(ch==)
{
x=read(),v=read();
update(x,v);
}
else if(ch==)
{
int x=read(),y=read();
int tmp=query(x,y),tmp2=query1(x,y,tmp);
printf("%d %d\n",tmp,tmp2);
}
else
{
int x=read(),y=read(),z=read();
printf("%d\n",deal(x,y,z));
}
}
return ;
}

acdream 1738 世风日下的哗啦啦族I 分块的更多相关文章

  1. ACdream 1738 世风日下的哗啦啦族I(分块大法+二分)

    世风日下的哗啦啦族I Time Limit: 4000/2000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit S ...

  2. Acdream 1738 世风日下的哗啦啦族I 树套树

    世风日下的哗啦啦族I Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acdream.info/problem?pid=1738 Descri ...

  3. acdream 1738 世风日下的哗啦啦族I

    原题链接:http://acdream.info/problem?pid=1738 树套树裸题,如下: #include<algorithm> #include<iostream&g ...

  4. 世风日下的哗啦啦族I (简单分块模板)

    题目链接 #include <bits/stdc++.h> using namespace std; typedef long long ll; #define inf 0x7ffffff ...

  5. 2017"百度之星"程序设计大赛 - 资格赛【1001 Floyd求最小环 1002 歪解(并查集),1003 完全背包 1004 01背包 1005 打表找规律+卡特兰数】

    度度熊保护村庄 Accepts: 13 Submissions: 488 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3276 ...

  6. [SinGuLaRiTy] 2017 百度之星程序设计大赛-资格赛

    [SinGuLaRiTy-1034] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 度度熊保护村庄  Time Limit: 2000/10 ...

  7. HDU 6081 度度熊的王国战略(全局最小割堆优化)

    Problem Description度度熊国王率领着喵哈哈族的勇士,准备进攻哗啦啦族.哗啦啦族是一个强悍的民族,里面有充满智慧的谋士,拥有无穷力量的战士.所以这一场战争,将会十分艰难.为了更好的进攻 ...

  8. HDU 6081 度度熊的王国战略(全局最小割Stoer-Wagner算法)

    Problem Description 度度熊国王率领着喵哈哈族的勇士,准备进攻哗啦啦族. 哗啦啦族是一个强悍的民族,里面有充满智慧的谋士,拥有无穷力量的战士. 所以这一场战争,将会十分艰难. 为了更 ...

  9. HDU 6081 度度熊的王国战略【并查集/数据弱水题/正解最小割算法】

    链接6081 度度熊的王国战略 Time Limit: 40000/20000 MS (Java/Others) Memory Limit: 32768/132768 K (Java/Others) ...

随机推荐

  1. cocos2d-x 全面总结--字体描边和制作阴影

    关于字体描边的实现,不考虑效果和效率的话,是有三种方式: ① 利用CCLabelTTF制作文字描边和阴影效果 ② 利用CCRenderTexture渲染文理的方式生成带有描边效果的文字 ③ 利用sha ...

  2. 华丽的bootstrap3碰到土鳖IE6

    之前由于看好很容易上手的bootstrap,然后用这个框架写了个网站,对于不会美工和细致设计的攻城师来说,bootstrap是个界面设计的瑞士军刀,三下五除二就能搞定个不算太丑的页面. 吭哧吭哧工作了 ...

  3. 高薪诚聘.NET MVC开发工程师

    你想有大好的发展前途吗?你想拥有高的月薪吗? 赶快来吧! 1.企业网站.电子商务开发: 2.进行详细设计.代码开发,配合测试,高质量完成项目: 3.参与技术难题攻关.组织技术积累等工作. 任职资格: ...

  4. 分布式数据库hbase详解

    新霸哥注意到了在人类随着计算机技术的发展,数据的存储量发生了很大的变化,可以用海量来形容,同时,存储的数据类型也是有多种多样的,网页,图片,视频,音频,电子邮件等等,所以在这中情况下以谷歌旗下的Big ...

  5. LeetCode Database: Rank Scores

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...

  6. excel导入数据到sqlserver

    1.读取excel数据到dataset public static System.Data.DataSet ExcelSqlConnection(string filepath, string tab ...

  7. 【24点游戏】cocos2dx 源码

    1.  4个数字 24点判断 double Calc(double a, double b, string oper) { double result = 0; const char *p = ope ...

  8. 有趣的库:pipe(类似linux | 管道)库

    pipe并不是Python内置的库,如果你安装了easy_install,直接可以安装它,否则你需要自己下载它:http://pypi.python.org/pypi/pipe 之所以要介绍这个库,是 ...

  9. oracle 体系结构解析

    三.oracle 体系结构 1.oracle内存由SGA+PGA所构成 2.oracle数据库体系结构数据库的体系结构是指数据库的组成.工作过程与原理,以及数据在数据库中的组织与管理机制. oracl ...

  10. ubuntu下apt-get update出现hash校验和错误

    可能原因 校园网进行网络缓存导致内容滞后. 解决办法 先清除旧的apt-get更新列表 sudo rm -rf /var/lib/apt/lists/* 使用代理服务器或者VPN 重新更新 sudo ...