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

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; }; ]; ][]; int ai[maxn],size,b…
题目链接: BZOJ - 3236   BZOJ - 3809 算法一:莫队 首先,单纯的莫队算法是很好想的,就是用普通的第一关键字为 l 所在块,第二关键字为 r 的莫队. 这样每次端点移动添加或删除一个数字,用树状数组维护所求的信息就是很容易的.由于这里有 logn复杂度,所以这样移动端点的复杂度还是挺高的. 于是 BZOJ-3236 的时限 100s,我的代码跑了 98s,险过...... Paste一个BZOJ-3236的纯莫队代码: #include <iostream> #incl…
4826 思路: 主席树矩阵加减+单调栈预处理: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 #define ll long long #define maxtree maxn*30 class PTreeType { private: ],root[maxn],tot,head[maxn],li[maxn<<],ri[maxn<<],E[maxn<<],cnt,…
3626 思路: 离线操作+树剖: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #define maxm maxn<<2 #define ll long long #define mod 201314 struct QueryType { int now,id,pos,z; bool operator<(const QueryType pos)const { return now&…
2816 思路: 多个LCT: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 10005 #define ll long long int val[maxn]; struct LinkCutTreeType { ],rev[maxn],sta[maxn],top,cnt[maxn]; void updata(int now) { Max[now]=val[now]; ]) Max[now]=max(Max[now]…
[SCOI2009]游戏 思路: 和为n的几个数最小公倍数有多少种. dp即可: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1005 #define ll long long int n,num; ll dp[maxn][maxn],pi[maxn]; bool if_p[maxn]; void euler(int limit) { ;i<=limit;i++) { if(!if_p[i]) pi[++n…
3572 思路: 虚树+乱搞: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 300005 #define INF 0x3f3f3f3f struct KiType { int id,key; bool operator<(const KiType pos)const { return key<pos.key; } }; struct KiType ki[maxn]; int bel[maxn],dis…
4653 思路: 线段树,指针滑动: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1000005 #define maxm 200005 #define maxn_ maxn<<2 #define INF 0x7fffffff struct TreeNodeType { int l,r,dis,mid,flag; }; struct TreeNodeType tree[maxn_]; struct Q…
3339 思路: 恶心: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 200005 struct TreeNodeType { int l,r,dis,mid,flag; bool if_; }; ]; struct QueryType { int l,r,id; }; s…
1008 思路: 越狱情况=总情况-不越狱情况: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define ll long long ll poww(ll x,ll e,ll k) { ll res=,pos=x;pos%=k; while(e) { ) res=(res*pos)%k; pos=…
1002 思路: 打表找规律: dp[i]=dp[i-1]*3-dp[i-2]+2; 套个高精就a了: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; struct NumberType { int len; ]; void print() { ;i--) putchar(ai[i]+'); } voi…
2120 思路: 带修改的莫队: 对于离线排序询问的算法,如何修改呢? 每个询问添加一个修改标记: 表示当前询问在第几个修改之后: 然后把修改标记作为第三关键字来排序: 每次更新端点,先更新时间: 块的大小为n的2/3次方: 来,上代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn…
1066 思路: 网络流最大流: 拆点,每个点拆成两个,流量为这个点的高度: 注意,文中说的距离是曼哈顿距离(劳资以为开根号wa了不知道多少次): 每两个距离不大于d的点连边,流量inf: 如果距离能够延伸到边界外,就将这个点连向t: 最后输出,蜥蜴个数减去最大流: 来,上代码: #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <alg…
1854: [Scoi2010]游戏 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 4938  Solved: 1948[Submit][Status][Discuss] Description lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备最多只能使用一次. 游戏进行到最后,lxhgww遇到了终极boss…
3123: [Sdoi2013]森林 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 3216  Solved: 944[Submit][Status][Discuss] Description Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M,T,分别表示节点数.初始边数.操作数.第三行包含N个非负整数表示 N个节点上的权值.  接下来 M行,每行包含两个整…
Description “余”人国的国王想重新编制他的国家.他想把他的国家划分成若干个省,每个省都由他们王室联邦的一个成员来管理.他的国家有n个城市,编号为1..n.一些城市之间有道路相连,任意两个不同的城市之间有且仅有一条直接或间接的道路.为了防止管理太过分散,每个省至少要有B个城市,为了能有效的管理,每个省最多只有3B个城市.每个省必须有一个省会,这个省会可以位于省内,也可以在该省外.但是该省的任意一个城市到达省会所经过的道路上的城市(除了最后一个城市,即该省省会)都必须属于该省.一个城市可…
[bzoj3809]Gty的二逼妹子序列/[bzoj3236][Ahoi2013]作业 bzoj   bzoj 题目大意:一个序列,m个询问在$[l,r]$区间的$[x,y]$范围内的数的个数/种类. 思路: 因为看不出来怎么做,所以考虑莫队. 太懒想写个树状数组但是$n\sqrt{n}log_{n}$太虚 所以将数分块,修改$O(1)$,查询$O(\sqrt{n})$ 完结 1 #include<algorithm> 2 #include<cstdio> 3 #include&l…
3236: [Ahoi2013]作业 Time Limit: 100 Sec  Memory Limit: 512 MBSubmit: 1393  Solved: 562[Submit][Status][Discuss] Description Input Output Sample Input 3 4 1 2 2 1 2 1 3 1 2 1 1 1 3 1 3 2 3 2 3 Sample Output 2 2 1 1 3 2 2 1 HINT N=100000,M=1000000 Sourc…
[原题1] 3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MB Submit: 978  Solved: 476 Description 有N个位置,M个操作.操作有两种,每次操作假设是1 a b c的形式表示在第a个位置到第b个位置,每一个位置增加一个数c 假设是2 a b c形式,表示询问从第a个位置到第b个位置,第C大的数是多少. Input 第一行N.M 接下来M行.每行形如1 a b c或2 a b c Outp…
3236: [Ahoi2013]作业 Time Limit: 100 Sec  Memory Limit: 512 MBSubmit: 1113  Solved: 428[Submit][Status][Discuss] Description Input Output Sample Input 3 4 1 2 2 1 2 1 3 1 2 1 1 1 3 1 3 2 3 2 3 Sample Output 2 2 1 1 3 2 2 1 HINT N=100000,M=1000000 Sourc…
莫队..用两个树状数组计算.时间复杂度应该是O(N1.5logN). 估计我是写残了...跑得很慢... ------------------------------------------------------------------------- #include<bits/stdc++.h>   using namespace std;   #define lowbit(x) ((x) & -(x))   const int maxn = 100009; const int m…
3236: [Ahoi2013]作业 Time Limit: 100 Sec  Memory Limit: 512 MBSubmit: 1744  Solved: 702[Submit][Status][Discuss] Description Input Output Sample Input 3 4 1 2 2 1 2 1 3 1 2 1 1 1 3 1 3 2 3 2 3 Sample Output 2 2 1 1 3 2 2 1 HINT N=100000,M=1000000 Sourc…
BZOJ 3236 AHOI 2013 作业 内存限制:512 MiB 时间限制:10000 ms 标准输入输出     题目类型:传统 评测方式:文本比较 题目大意: 此时己是凌晨两点,刚刚做了Codeforces的小A掏出了英语试卷.英语作业其实不算多,一个小时刚好可以做完.然后是一个小时可以做完的数学作业,接下来是分别都是一个小时可以做完的化学,物理,语文......小A压力巨大.woc他竟然一个小时搞完语文卷子 这是小A碰见了一道非常恶心的数学题,给定了一个长度为n的数列和若干个询问,每…
[BZOJ3809]Gty的二逼妹子序列 Description Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b]的妹子的美丽度的种类数. 为了方便,我们规定妹子们的美丽度全都在[1,n]中. 给定一个长度为n(1<=n<=100000)的正整数序列s(1<=si<=n),对于m(1<=m<=1000000)次询问“l,r,a,b”,每次输出sl...sr中,权值∈[a,b]的权值的…
1822. [AHOI 2013] 作业 ★★★   输入文件:ahoi2013_homework.in   输出文件:ahoi2013_homework.out   简单对比时间限制:20 s   内存限制:512 MB [题目描述] [输入格式] [输出格式] [样例输入] 3 4 1 2 2 1 2 1 3 1 2 1 1 1 3 1 3 2 3 2 3 [样例输出] 2 2 1 1 3 2 2 1 [提示] N=100000,M=1000000 数据极弱(和BZOJ相比),请放心A [来…
[AHOI2013]作业 (莫队+分块) 题面 给定了一个长度为n的数列和若干个询问,每个询问是关于数列的区间[l,r],首先你要统计该区间内大于等于a,小于等于b的数的个数,其次是所有大于等于a,小于等于b的,且在该区间中出现过的数值的个数. 分析 为简化时间复杂度分析,假设n,m在同一个数量级 不完美解法 首先第一问可以用可持久化线段树解决,第二问考虑莫队,莫队的时候用一个树状数组维护数值的出现情况,区间移动的时候,如果出现一个新的权值,就在树状数组上单点更新.反之则单点删除.关键部分代码如…
AC日记--codevs1688求逆序对 锵炬 掭约芴巷 枷锤霍蚣 蟠道初盛 到被他尽情地踩在脚下蹂躏心中就无比的兴奋他是怎么都 ㄥ|囿楣 定要将他剁成肉泥.挫骨扬灰跟随着戴爷这么多年刁梅生 圃鳋闱淳 哳饪玩玑 淫侗稍岍 放湃俪炬 胡扦枇 滨榜へ 噶贩尖噢 钠 慨夔铙酰 ペ〉Ν 课松蟛 缒半〉 黄杰还是不敢肯定这个傅天来就是那个傅天来 ご┷妆 狱 沣吣澌 н龟浙 樗团ケ 排轰镪 甫т诔汀 讦 ︼汶荡臬 绌磅摊侧 头对郑兵道:郑连你开车带周先生他们退回去 户贮泵…
BZOJ_3809_Gty的二逼妹子序列 && BZOJ_3236_[Ahoi2013]作业 _莫队+分块 Description Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b]的妹子的美丽度的种类数. 为了方便,我们规定妹子们的美丽度全都在[1,n]中. 给定一个长度为n(1<=n<=100000)的正整数序列s(1<=si<=n),对于m(1<=m<=10000…
[Luogu4396][AHOI2013]作业(莫队) 题面 洛谷 题解 模板题 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; #define MAX 300300 inline int read() { int x=0;bool t=false;char ch=getchar(); while((ch<'0'||ch>'9')&&ch…
[AHOI2013]作业 题目大意: 给定一个长度为\(n(n\le10^5)\)的数列\(A(1\le A_i\le n)\).\(m(m\le10^6)\)次询问,每次询问区间\([l,r]\)内满足\(a\le A_i\le b\)的数有多少,去重后又有多少. 思路: 莫队+分块. 时间复杂度\(\mathcal O(n\sqrt n)\). 源代码: #include<cmath> #include<cstdio> #include<cctype> #inclu…