HDU 4638 (莫队)】的更多相关文章

题目链接:Problem - 4638 做了两天莫队和分块,留个模板吧. 当插入r的时候,设arr[r]代表r的位置的数字,判断vis[arr[r-1]]和vis[arr[r+1]]是否访问过,如果两个都访问过,那么块的个数-1,如果有一个访问过,块的个数不变,如果都为0,块的个数+1. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include…
Group Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2483    Accepted Submission(s): 1272 Problem Description There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and i-…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5213 Lucky Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 763    Accepted Submission(s): 249 Problem Description WLD is always very lucky.His secret…
题意大致是有n个苹果,问你最多拿走m个苹果有多少种拿法.题目非常简单,就是求C(n,0)+...+C(n,m)的组合数的和,但是询问足足有1e5个,然后n,m都是1e5的范围,直接暴力的话肯定时间炸到奶奶都不认识了.当时想了好多好多,各种骚操作都想了一遍就是没想到居然是莫队....我用S(n,m)来记录C(n,0)+...+C(n,m)的和作为一个询问的答案 由组合数公式C(n,m) = C(n-1,m-1)+C(n-1,m)可以推的下面的式子 S(n,m) = S(n,m-1) + C(n,m…
Boring counting Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others)Total Submission(s): 2808    Accepted Submission(s): 826 Problem Description In this problem we consider a rooted tree with N vertices. The vertices ar…
NPY and girls Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 790    Accepted Submission(s): 280 Problem Description NPY's girlfriend blew him out!His honey doesn't love him any more!However, he…
Problem B. Harvest of Apples Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2397    Accepted Submission(s): 934 Problem Description There are n apples on a tree, numbered from 1 to n.Count th…
题意及思路:https://blog.csdn.net/tianyizhicheng/article/details/90369491 代码: #include <bits/stdc++.h> #define lowbit(x) (x & (-x)) using namespace std; const int maxn = 30010; int c[maxn * 3], num[maxn], b[maxn * 3], lb[maxn], rb[maxn], a[maxn]; int…
题目地址:HDU 5145 莫队真的好奇妙.. 这种复杂度竟然仅仅有n*sqrt(n)... 裸的莫队分块,先离线.然后按左端点分块,按块数作为第一关键字排序.然后按r值作为第二关键字进行排序. 都是从小到大,能够证明这种复杂度仅仅有n*sqrt(n). 然后进行块之间的转移. 代码例如以下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include…
题目链接 很裸的莫队, 就不多说了... #include<bits/stdc++.h> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeof(a)) #define rson m+1, r, rt<<1…