AC日记——Rmq Problem bzoj 3339】的更多相关文章

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…
3339: Rmq Problem Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 833  Solved: 397[Submit][Status][Discuss] Description Input Output Sample Input 7 5 0 2 1 0 1 3 2 1 3 2 3 1 4 3 6 2 7 Sample Output 3 0 3 2 4 HINT Source By Xhr [Submit][Status][Discus…
Dynamic Problem Scoring 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 130 ],ac[],cnt,all,last1,last2; ][]; inline void in(int &now) { ;now=; char Cge…
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…
UVA - 10779 思路: 最大流: s向所有的贴纸的种类连边,流量为Bob拥有的数量: 然后,Bob的朋友如果没有这种贴纸,则这种贴纸向bob的朋友连边,容量1: 如果bob的朋友的贴纸很多大于1,向该贴纸的种类连边,容量数量-1: 所有贴纸的种类向t连边,容量1: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namesp…
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…
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…
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个城市.每个省必须有一个省会,这个省会可以位于省内,也可以在该省外.但是该省的任意一个城市到达省会所经过的道路上的城市(除了最后一个城市,即该省省会)都必须属于该省.一个城市可…
离线+线段树 Orz Hzwer,引用题解: 这一题在线似乎比较麻烦 至于离线.. 首先按照左端点将询问排序 然后一般可以这样考虑 首先如何得到1-i的sg值呢 这个可以一开始扫一遍完成 接着考虑l-r和l+1-r的答案有何不同 显然是l-next[l]-1这一段所有sg值大于a[l]的变为a[l] 这一步如果暴力修改的话只有30分 但是修改区间我们可以想到线段树,这样就能a了 晚上写题有点晕……忘了把当前时刻now置为q[i].l了,这种傻逼错误居然也犯…… /****************…
3339: Rmq Problem Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1075  Solved: 549[Submit][Status][Discuss] Description Input Output Sample Input 7 5 0 2 1 0 1 3 2 1 3 2 3 1 4 3 6 2 7 Sample Output 3 0 3 2 4 HINT Source By Xhr [Submit][Status][Discu…
3339: Rmq Problem 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3339 Description n个数,m次询问l,r.查询区间mex是什么. Input Output Sample Input 7 5 0 2 1 0 1 3 2 1 3 2 3 1 4 3 6 2 7 Sample Output 3 0 3 2 4 Hint 题意 题解: 莫队算法水题 直接暴力搞就行了 代码 #include<bits/stdc…
P4137 Rmq Problem / mex 题目描述 有一个长度为n的数组{a1,a2,-,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. 输入输出格式 输入格式: 第一行n,m. 第二行为n个数. 从第三行开始,每行一个询问l,r. 输出格式: 一行一个数,表示每个询问的答案. 输入输出样例 输入样例#1: 5 5 2 1 0 2 1 3 3 2 3 2 4 1 2 3 5 输出样例#1: 1 2 3 0 3 说明 对于30%的数据:1<=n,m<=1000 对于100%的…
G - Periodic RMQ Problem 思路: 题目给一段序列,然后序列复制很多次: 维护序列很多次后的性质: 线段树动态开点: 来,上代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005 struct TreeNodeType { int l, r, mid…
3489: A simple rmq problem Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 551  Solved: 170[Submit][Status][Discuss] Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过一次的数,并且要求找的这个数尽可能大.如果找不到这样的数,则直接输出0.我会采取一些措施强制在线. Input 第一行为两个整数…
题面:Rmq Problem / mex 题解: 先离散化,然后插一堆空白,大体就是如果(对于以a.data<b.data排序后的A)A[i-1].data+1!=A[i].data,则插一个空白叫做A[i-1].data+1, 开头和最尾也要这么插,意义是如果取不了A[i-1]了,最早能取的是啥数.要把这些空白也离散化然后扔主席树里啊. 主席树维护每个数A[i]出现的最晚位置(tree[i].data),查询时查询root[R]的树中最早的data<L的节点(这意味着该节点的下标离散化前代…
KD-Tree(乱搞) Orz zyf教给蒟蒻做法 蒟蒻并不会这题正解……(可持久化树套树?...Orz 对于每个点,我们可以求出pre[i],nex[i],那么询问的答案就是:求max (a[i]),其中 i 满足$ ( pre[i]<ql \ and \ nex[i]>qr\ and\ i \in [ql,qr] ) $ 然后我们以(i,pre[i],nex[i])为坐标……将所有点抽象到三维空间中,每次查询就相当于是一次区域求最值! 这题我的感受: 因为前面做了两道区域求和的……然后思路…
3489: A simple rmq problem Time Limit: 40 Sec  Memory Limit: 600 MBSubmit: 1594  Solved: 520[Submit][Status][Discuss] Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过一次的数,并且要求找的这个数尽可能大.如果找不到这样的数,则直接输出0.我会采取一些措施强制在线. Input 第一行为两个整…
[Luogu4137]Rmq Problem/mex (莫队) 题面 洛谷 题解 裸的莫队 暴力跳\(ans\)就能\(AC\) 考虑复杂度有保证的做法 每次计算的时候把数字按照大小也分块 每次就枚举答案在哪一块里面就好 #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm>…
[BZOJ3489]A simple rmq problem(KD-Tree) 题面 BZOJ 题解 直接做肯定不好做,首先我们知道我们是一个二维平面数点,但是限制区间只能出现一次很不好办,那么我们给每个数记录一下和它相等的上一个位置和下一个位置,那么这两个位置的限定范围就在区间以外,于是变成了一个\(4\)维数点问题,直接\(KD-Tree\)了. #include<iostream> #include<cstdio> #include<algorithm> usin…
[BZOJ3489]A simple rmq problem 题面 bzoj 题解 这个题不强制在线的话随便做啊... 考虑强制在线时怎么搞 预处理出一个位置上一个出现的相同数的位置\(pre\)与下一个位置\(nxt\) 则对于一个询问\([l,r]\) 一个位置\(i\)当且仅当\(pre_i<l\)且\(nxt_i>r\) 我们可以将一个位置看作一个点坐标为\((pre_i,nxt_i)\) 要求横坐标\(<l\)且纵坐标\(>r\) 这个可以用简单\(kdTree\) 也可…