首页 > 其他分享 >[Ynoi2016] 掉进兔子洞

[Ynoi2016] 掉进兔子洞

时间:2022-10-28 11:22:11浏览次数:52  
标签:cnt ch cur int text 兔子 Ynoi2016 include

\(\text{Solution}\)

莫队配合 \(\text{bitset}\)

发现答案困难的部分在于同一个数在三个区间出现次数的最小值
考虑强行拆开看,用莫队处理出每个区间每个数的出现次数,这个可以用 \(\text{bitset}\)
然后取 \(\min\) 相当于每个询问涉及的三个区间的 \(\text{bitset}\) 并起来

\(\text{Code}\)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <bitset>
#define IN inline
using namespace std;

template <typename T>
IN void read(T &x) {
	x = 0; char ch = getchar(); int f = 0;
	for(; !isdigit(ch); f = (ch == '-' ? 1 : f), ch = getchar());
	for(; isdigit(ch); x = (x<<3)+(x<<1)+(ch^48), ch = getchar());
	if (f) x = ~x + 1;
}

typedef long long LL;
const int N = 1e5 + 3;
int a[N], n, m, B, cnt[N], ans[N], num, now, b[N];
struct Que{int l, r, id;}Q[N];
IN bool cmp(Que a, Que b){return (a.l / B ^ b.l / B) ? (a.l < b.l) : ((a.l / B & 1) ? a.r < b.r : a.r > b.r);}
bitset<N> S[N / 3 + 2], cur;

IN void add(int x){cur.set(a[x] + cnt[a[x]]), ++cnt[a[x]];}
IN void del(int x){--cnt[a[x]], cur.reset(a[x] + cnt[a[x]]);}
IN void solve() {
	B = n / sqrt(2.0 * num / 3) + 1, cur.reset();
	for(int i = 1; i <= n; i++) cnt[i] = 0;
	for(int i = 1; i <= now; i++) S[i].set();
	sort(Q + 1, Q + num + 1, cmp);
	for(int i = 1, l = 1, r = 0; i <= num; i++) {
		while (l > Q[i].l) add(--l);
		while (r < Q[i].r) add(++r);
		while (l < Q[i].l) del(l++);
		while (r > Q[i].r) del(r--);
		S[Q[i].id] &= cur;
	}
	for(int i = 1; i <= now; i++) printf("%d\n", ans[i] - (int)S[i].count() * 3);
}

int main() {
	read(n), read(m);
	for(int i = 1; i <= n; i++) read(a[i]), b[i] = a[i];
	sort(b + 1, b + n + 1);
	for(int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
	num = now = 0;
	for(int i = 1; i <= m; i++) {
		ans[++now] = 0;
		for(int j = 0; j < 3; j++)
			++num, read(Q[num].l), read(Q[num].r), ans[Q[num].id = now] += Q[num].r - Q[num].l + 1;
		if (now == m / 3 || i == m) solve(), num = now = 0;
	}
}

标签:cnt,ch,cur,int,text,兔子,Ynoi2016,include
From: https://www.cnblogs.com/leiyuanze/p/16835191.html

相关文章

  • 1025模拟赛(兔子场)
    1025模拟赛(兔子场)感谢兔子女王&兔子公主不杀之恩。A「AGC008C」TetrominoTiling题意\(~~~~\)七种俄罗斯方块,已知每种的数量,(按照形状记为\(\text{I,O,T,L,J,S,Z......
  • BZOJ 1001([BeiJing2006]狼抓兔子-最大流转对偶图最短路)
    1001:[BeiJing2006]狼抓兔子TimeLimit: 15Sec  MemoryLimit: 162MBSubmit: 5779  Solved: 1297​​Submit​​][​​Status​​][​​Discuss​​]D......
  • 兔子生崽
    #include<stdio.h>intmain(){ inta=1; intb=1; inti; /*1.//变量可以无限接收值(小技巧 a=a+b; b=a+b; */ /*2.将输出值按规律分行(小......
  • 简笔画~兔子
    •介绍简笔画,兔子。•步骤[captionid="attachment_3435"align="aligncenter"width="268"]​​​​简笔画~兔子1[/caption][captionid="attachment_3436"align="ali......
  • 看到就是赚到!当 LinkedList 不是列表时,速度快的兔子都追不上!
    作者:小姐姐味道ArrayList和LinkedList有什么区别?这种侮辱人的问题,默认就把这两者限定在了同一个场景之中,它甚至连八股文都算不上。一旦你被问到这种问题,也证明面试基本上泡......
  • 统计每个月兔子的总数---牛客网
    统计每个月兔子的总数_牛客题霸_牛客网(nowcoder.com) #include<iostream>usingnamespacestd;intmain(){//112358//这道题本质就是斐波那契......
  • [Ynoi2016] 炸脖龙 I
    题目传送门已经能过hack,原因:做快速幂的时候需要微判一下边界。很好奇lxl为什么不卡显然区间加可用线段树做。然后操作二用扩展欧拉定理,每个\(p\)最多递归\(\log\)......
  • hash の 题(内含兔子与兔子,Hash 键值 (hash))
     Hash键值(hash)【思路】按照正常模拟,很容易写出代码,如图: for(inti=1;i<=q;i++){ intopt; scanf("%d",&opt); if(opt==1){ intx,y,ans=0; scanf("%d%d"......