3236

思路:

  莫队+树状数组维护;

代码:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 100005 struct QueryType {
int l,r,a,b,id;
};
struct QueryType qu[maxn*]; int n,sum[maxn],sum_[maxn],ti[maxn],ans[maxn*][];
int ai[maxn],size,bel[maxn],m; inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} inline int lowbit(int x)
{
return x&(-x);
} inline void sadd(int x,int k)
{
while(x<=n) sum[x]+=k,x+=lowbit(x);
} inline int ssum(int p,int x)
{
int res=;p--;
while(x) res+=sum[x],x-=lowbit(x);
while(p) res-=sum[p],p-=lowbit(p);
return res;
} inline void tadd(int x,int k)
{
while(x<=n) sum_[x]+=k,x+=lowbit(x);
} inline int tsum(int p,int x)
{
int res=;p--;
while(x) res+=sum_[x],x-=lowbit(x);
while(p) res-=sum_[p],p-=lowbit(p);
return res;
} inline bool cmp(QueryType aaa,QueryType bbb)
{
if(bel[aaa.l]==bel[bbb.l])
{
if(bel[aaa.r]==bel[bbb.r])
{
if(aaa.l==bbb.l) return aaa.r<bbb.r;
else return aaa.l<bbb.l;
}
return bel[aaa.r]<bel[bbb.r];
}
else return bel[aaa.l]<bel[bbb.l];
} inline void updata(int now,int x)
{
int pre=ti[now];
ti[now]+=x,sadd(now,x);
if(pre==&&ti[now]==) tadd(now,);
if(pre==&&ti[now]==) tadd(now,-);
} int main()
{
in(n),in(m),size=sqrt(n);for(int i=;i<=n;i++) in(ai[i]),bel[i]=(i-)/size;
for(int i=;i<=m;i++) in(qu[i].l),in(qu[i].r),in(qu[i].a),in(qu[i].b),qu[i].id=i;
sort(qu+,qu+m+,cmp);int l=,r=,pos;
for(int no=;no<=m;no++)
{
if(l<qu[no].l) for(int i=l;i<qu[no].l;i++) updata(ai[i],-);
else for(int i=l-;i>=qu[no].l;i--) updata(ai[i],);
if(r>qu[no].r) for(int i=r;i>qu[no].r;i--) updata(ai[i],-);
else for(int i=r+;i<=qu[no].r;i++) updata(ai[i],);
l=qu[no].l,r=qu[no].r,ans[qu[no].id][]=ssum(qu[no].a,qu[no].b),ans[qu[no].id][]=tsum(qu[no].a,qu[no].b);
}
for(int i=;i<=m;i++) printf("%d %d\n",ans[i][],ans[i][]);
return ;
}

AC日记——[Ahoi2013]作业 bzoj 3236的更多相关文章

  1. [BZOJ 3236] [Ahoi2013] 作业 && [BZOJ 3809] 【莫队(+分块)】

    题目链接: BZOJ - 3236   BZOJ - 3809 算法一:莫队 首先,单纯的莫队算法是很好想的,就是用普通的第一关键字为 l 所在块,第二关键字为 r 的莫队. 这样每次端点移动添加或删 ...

  2. AC日记——[Hnoi2017]影魔 bzoj 4826

    4826 思路: 主席树矩阵加减+单调栈预处理: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 ...

  3. AC日记——[LNOI2014]LCA bzoj 3626

    3626 思路: 离线操作+树剖: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #defin ...

  4. AC日记——[ZJOI2012]网络 bzoj 2816

    2816 思路: 多个LCT: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 10005 #define l ...

  5. AC日记——[SCOI2009]游戏 bzoj 1025

    [SCOI2009]游戏 思路: 和为n的几个数最小公倍数有多少种. dp即可: 代码: #include <bits/stdc++.h> using namespace std; #de ...

  6. AC日记——[HNOI2014]世界树 bzoj 3572

    3572 思路: 虚树+乱搞: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 300005 #define ...

  7. AC日记——NOI2016区间 bzoj 4653

    4653 思路: 线段树,指针滑动: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1000005 #def ...

  8. AC日记——Rmq Problem bzoj 3339

    3339 思路: 恶心: 代码: #include <cstdio> #include <cstring> #include <iostream> #include ...

  9. AC日记——[HNOI2008]越狱 bzoj 1008

    1008 思路: 越狱情况=总情况-不越狱情况: 代码: #include <cstdio> #include <cstring> #include <iostream& ...

随机推荐

  1. 【题解】HNOI2016树

    大概最近写的这些题目都是仿生的代码……在这里先说明一下.可能比起做题记录来说更加像是学习笔记吧.之所以这样做主要还是因为感受到最近做的很多题目自己会做的都比较简单,不会做的又不敢触及,虽然也有所进步. ...

  2. CCmdUI

    原文链接地址:http://blog.csdn.net/luicha/article/details/6771185 CCmdUI是一个只被使用于ON_UPDATECOMMAND_UI消息的响应函数中 ...

  3. [Usaco2005 Dec]Cleaning Shifts 清理牛棚 (DP优化/线段树)

    [Usaco2005 Dec] Cleaning Shifts 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new ...

  4. Codeforces Round #531 (Div. 3) F. Elongated Matrix(状压DP)

    F. Elongated Matrix 题目链接:https://codeforces.com/contest/1102/problem/F 题意: 给出一个n*m的矩阵,现在可以随意交换任意的两行, ...

  5. php 上传csv文件

    php fgetcsv()函数 定义和用法 fgetcsv() 函数从文件指针中读入一行并解析 CSV 字段. 与 fgets() 类似,不同的是 fgetcsv() 解析读入的行并找出 CSV 格式 ...

  6. javascript中的递增递减操作符

    javascript中递增递减属于一元操作符,所谓一元操作符,即只能操作一个值的操作符. 递增和递减操作符各有两个版本:前置型和后置型.顾名思义,前置型应该位于要操作的变量之前,而后置型应该位于要操作 ...

  7. iOS 单元测试(Unit Test 和 UI Test)

    之前一直搞过~~最近试了一下下,完美~~ 附上一篇文章,不同的伙伴可以看看: http://www.jianshu.com/p/009844a0b9edUnitTest(简单的单元测试使用) http ...

  8. 【数据结构】bzoj3747Kinoman

    Description 共有m部电影,编号为1~m,第i部电影的好看值为w[i]. 在n天之中(从1~n编号)每天会放映一部电影,第i天放映的是第f[i]部. 你可以选择l,r(1<=l< ...

  9. Topcoder SRM 607 div1题解

    好久没来写了,继续继续... Easy(250pts): //前方请注意,样例中带有zyz,高能预警... 题目大意:给你一个字符串,中间有一些是未知字符,请你求出这个字符串的回文子串个数的期望值.数 ...

  10. #error#学习方法,如何避免初始化错误

    #error#学习方法,如何避免初始化错误.错误来自:本博客的另一篇文章Demo示例程序源代码: ,01-导航实例-QQ空间.xcodeproj - CYLLoginViewController.mD ...