原题传送门

Luogu P4396 [AHOI2013]作业

询问多了10倍,但还能跑过(smog

#include <bits/stdc++.h>
#define N 100005
#define M 1000005
//#define getchar nc
using namespace std;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
register int x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return x*f;
}
inline void write(register int x)
{
if(!x)putchar('0');if(x<0)x=-x,putchar('-');
static int sta[20];register int tot=0;
while(x)sta[tot++]=x%10,x/=10;
while(tot)putchar(sta[--tot]+48);
}
int n,m,blocksize=0,ans[M],v[N],p[N];
struct BinaryIndexTree{
int tr[N];
inline void update(register int pos,register int x)
{
for(register int i=pos;i<=n;i+=i&(-i))
tr[i]+=x;
}
inline int query(register int pos)
{
int res=0;
for(register int i=pos;i;i-=i&(-i))
res+=tr[i];
return res;
}
}tr;
struct query{
int l,r,a,b,id,bl;
}q[M];
inline bool cmp(register query a,register query b)
{
return a.bl!=b.bl?a.l<b.l:((a.bl&1)?a.r<b.r:a.r>b.r);
}
inline void add(register int x)
{
if(++p[v[x]]==1)
tr.update(v[x],1);
}
inline void del(register int x)
{
if(--p[v[x]]==0)
tr.update(v[x],-1);
}
int main()
{
n=read(),m=read();
blocksize=sqrt(n);
for(register int i=1;i<=n;++i)
v[i]=read();
for(register int i=1;i<=m;++i)
q[i].l=read(),q[i].r=read(),q[i].a=read(),q[i].b=read(),q[i].id=i,q[i].bl=(q[i].l-1)/blocksize+1;
sort(q+1,q+1+m,cmp);
int l=1,r=0;
for(register int i=1;i<=m;++i)
{
int ll=q[i].l,rr=q[i].r;
while(l>ll)
add(--l);
while(l<ll)
del(l++);
while(r<rr)
add(++r);
while(r>rr)
del(r--);
ans[q[i].id]=tr.query(q[i].b)-tr.query(q[i].a-1);
}
for(register int i=1;i<=m;++i)
write(ans[i]),puts("");
return 0;
}

【题解】Luogu P4867 Gty的二逼妹子序列的更多相关文章

  1. P4867 Gty的二逼妹子序列

    题目描述 Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b]的妹子的美丽度的种类数. 为了方便,我们规定妹子们的美 ...

  2. 洛谷 P4867 Gty的二逼妹子序列

    链接: P4867 题意: 给出长度为 \(n(1\leq n\leq 10^5)\) 的序列 \(s\),保证\(1\leq s_i\leq n\).有 \(m(1\leq m\leq 10^6)\ ...

  3. Luogu 4867 Gty的二逼妹子序列

    BZOJ3809,是权限题. 我永远喜欢莫队. 先莫队一下移下左右指针,然后用一个数据结构维护一下区间$[a, b]$中的颜色的值,跟着指针移动一起修改修改,每一次$query$的时候就相当于查询一下 ...

  4. 洛谷P4867 Gty的二逼妹子序列(莫队+树状数组)

    传送门 本来打算用主席树 然后发现没办法维护颜色数 于是用了莫队加树状数组 然后竟然A了…… //minamoto #include<iostream> #include<cstdi ...

  5. [AHOI2013]作业 & Gty的二逼妹子序列 莫队

    ---题面--- 题解: 题目要求统计一个区间内数值在[a, b]内的数的个数和种数,而这个是可以用树状数组统计出来的,所以可以考虑莫队. 考虑区间[l, r]转移到[l, r + 1],那么对于维护 ...

  6. Bzoj 3809: Gty的二逼妹子序列 莫队,分块

    3809: Gty的二逼妹子序列 Time Limit: 35 Sec  Memory Limit: 28 MBSubmit: 868  Solved: 234[Submit][Status][Dis ...

  7. 【BZOJ3809/3236】Gty的二逼妹子序列 [Ahoi2013]作业 莫队算法+分块

    [BZOJ3809]Gty的二逼妹子序列 Description Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b ...

  8. BZOJ 3809: Gty的二逼妹子序列

    3809: Gty的二逼妹子序列 Time Limit: 80 Sec  Memory Limit: 28 MBSubmit: 1387  Solved: 400[Submit][Status][Di ...

  9. 【BZOJ-3809】Gty的二逼妹子序列 分块 + 莫队算法

    3809: Gty的二逼妹子序列 Time Limit: 80 Sec  Memory Limit: 28 MBSubmit: 1072  Solved: 292[Submit][Status][Di ...

随机推荐

  1. linux安装杀毒软件

    https://www.cnblogs.com/bingo1024/p/9018212.html

  2. 更为复杂C程序的运行时结构

    运行环境 win 10 企业版 1809 17763.194,MinGW V3.14 32位,Bundled V3.13.2,Bundled GDB V8.2. 在C语言中,栈的方向是从高地址向低地址 ...

  3. [dev] EPOLLOUT的应用场景

    问题 什么场景下,才需要epoll EPOLLOUT消息呢?也就是监听write 分析 找到一篇知乎,基本上读完就明白了 https://www.zhihu.com/question/22840801 ...

  4. LG1484 种树

    题意 \(N\)个数,至多选\(k\)个,相邻两数不能同时选,问最大价值. 思路 一种假的思路:直接扔进对里面,每次都选最大的可以选的,再把两边和自己标记为不能选,一直贪心下去.是不是很有道理? 假在 ...

  5. Centos修改时间为24小时制

    终端输入命令:tzselect 根据提示选择:5 --> 9-->1-->1-->okrm /etc/localtimeln -sf /usr/share/zoneinfo/A ...

  6. mybatis模糊查询

    今天遇到一个模糊查询的问题,需求是:根据传入的时间查询当天的所有数据,解决办法是使用$或者contact,具体sql模拟如下: select * from table_name where creat ...

  7. Linux(CentOs 7)系统重装笔记(二)---完全删除用户账号和root用户登录

    参考网址:https://jingyan.baidu.com/article/046a7b3ede1c38f9c27fa91b.html 一.完全删除用户 1.查看要删除的用户账号信息 find / ...

  8. C# .net 语言加密方案

    C# .net 语言加密方案 方案背景 当前C# .net语言的应用范围越来越广泛,IIS 的服务器架构后台代码.桌面应用程序的 winform .Unity3d 的逻辑脚本都在使用.C# .net ...

  9. [LeetCode] 132. Palindrome Partitioning II_ Hard tag: Dynamic Programming

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  10. Oracle SQL Loader

    C:/Documents and Settings/WWJD>sqlldr SQL :: Copyright (c) , , Oracle. All rights reserved. 用法: S ...