当前位置:网站首页>[acnoi2022] one step short
[acnoi2022] one step short
2022-07-28 02:56:00 【OneInDark】
I also thought about , Write something 《 gossip 》 Class , However, considering the negative energy it must carry , And anticipating the headmaster and roll master —— Maybe there are dogs —— Pungent sarcasm in the comment area , Give up after all .
After all, I didn't write 《 gossip 》 Qualifications . I got good grades , So what he does is reasonable . I'm not like that . I have no right . I'm nothing .
The bottom of my heart is only cold 、 Darkness and death . My life is only worth cursing, not chatting . I can only name it 《 Curse 》 And there is nothing else .
But since then, this idea has been deeply rooted in my heart . Like an extinct volcano , Even if it is “ die ” Of , Its interior is still hot magma . So I borrow a little space in front of my blog , Write something a little .
Many incredible things have happened recently , And one after another : First, the corneal plastic lens was accidentally lost , Then the braces were lost , Then the glasses leg of the frame glasses is broken , Now I'm at the bottom of the exam .
This seems to be some kind of omen . Something I don't want to admit , But there are already well-known omens .
but , Maybe , It's also a good thing . At least it makes my psychological burden less heavy .
I have turned a blind eye to my weakness . Don't be surprised at your incompetence . It's no surprise that I'm stupid .
subject
Background
because O U Y E \sf OUYE OUYE Excessive involution , Ordinary people like me have No, Existence Space 了 .
Title Description
consider 2 k 2^k 2k A segment tree with leaves , The value of each node is the larger value of the child nodes .
The leaf value is [ 1 , 2 k ] [1,2^k] [1,2k] Given the permutation . Now? q q q Time to ask x , y x,y x,y, ask x x x The maximum number of nodes on which the value can appear , If the exchange is at most y y y The value of the secondary leaf .
Forced Online , And the space is limited 16 M i B 16\rm MiB 16MiB .
Data range and tips
k ⩽ 19 k\leqslant 19 k⩽19 and q ⩽ 2 × 1 0 5 q\leqslant 2\times 10^5 q⩽2×105 .
Ideas
if y ≠ 0 y\ne 0 y=0, Then you only need to judge on a certain layer , Whether any node has at most y y y More than x x x Value .
y = 0 y=0 y=0 The line segment tree does not change , You can count the answers directly . Therefore, the following is omitted .
Scan line
See greater than x x x, Consider processing from large to small x x x .
Insert a new element one at a time , This will affect k k k One node in each layer . Then we need to maintain each layer min c n t \min cnt mincnt . Maintain with data structure , It seems to be O ( k 2 2 k ) \mathcal O(k^22^k) O(k22k) Complexity .
In fact, each layer of records min \min min Number of occurrences of , Find out min \min min After the change, the violence can be recalculated . Because there is L L L In the layer of nodes , min \min min Not more than 2 k L 2^k\over L L2k, And each increase requires O ( L ) \mathcal O(L) O(L) Recalculate , therefore k k k The total complexity of the layer O ( k 2 k ) \mathcal O(k2^k) O(k2k) .
So we get each x x x Want to be in t t t When it appears on nodes , y y y At least how much . If stored , You can deal with all inquiries online . Complexity O ( k 2 k + q log k ) \mathcal O(k2^k+q\log k) O(k2k+qlogk) . If online , Spatial complexity O ( k 2 k ) \mathcal O(k2^k) O(k2k), If offline , Spatial complexity O ( 2 k + q ) \mathcal O(2^k+q) O(2k+q) .
Two dimensional partial order
Scan line Is each x x x To query the available segment tree nodes .
Think in reverse : Each segment tree node can give x x x What to offer .
Obviously the first t t t Big value v v v Limits are given : if x ⩾ v x\geqslant v x⩾v, be y ⩾ t − 1 y\geqslant t{-}1 y⩾t−1 You can get the answer of this interval .
Notice that there are only O ( 2 k ) \mathcal O(2^k) O(2k) Such a contribution , Write down the answer directly with the array violence scan line .
The sum of this array and Scan line The results are the same .
Transforming dimensions
be aware Half plane in , The limits given y ⩾ t − 1 y\geqslant t{-}1 y⩾t−1 Only L L L Kind of , among L L L Is the length of a single node .
So we record f ( t ) f(t) f(t) by , stay y ⩾ t − 1 y\geqslant t{-}1 y⩾t−1 when , x ⩾ f ( t ) x\geqslant f(t) x⩾f(t) Can reach this layer .
Due to the f f f The length sum of is O ( 2 k ) \mathcal O(2^k) O(2k), Space complexity is just O ( 2 k ) \mathcal O(2^k) O(2k) Of .
Asking can still be divided , Time complexity O ( k 2 k + q log k ) \mathcal O(k2^k+q\log k) O(k2k+qlogk), Spatial complexity O ( 2 k ) \mathcal O(2^k) O(2k) .
To be unique
How to force online ? Use the previous answer .
However, the answer is only k k k Kind of , So this O ( q k ) \mathcal O(qk) O(qk) Ask offline , We also get acceptable practices .
Code
#include <cstdio>
#include <algorithm> // Almighty XJX yyds!!
#include <cstring> // oracle: ZXY yydBUS!!!
#include <cctype> // rainybunny root of the evil.
#include <functional>
using llong = long long;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
# define rep0(i,a,b) for(int i=(a); i!=(b); ++i)
inline int readint(){
int a = 0, c = getchar(), f = 1;
for(; !isdigit(c); c=getchar()) if(c == '-') f = -f;
for(; isdigit(c); c=getchar()) a = a*10+(c^48);
return a*f;
}
const int MAXK = 19;
int a[1<<MAXK]; int* tag[MAXK];
int ori[1<<MAXK]; /** for y = 0 */
const int INF = 0x3fffFFFF;
int tmp[1<<MAXK];
int main(){
int n = readint(), k = readint(), typ = readint();
rep0(i,0,n) a[i] = readint()-1;
rep0(j,0,k){
// merge for each layer
tag[j] = new int[2<<j];
std::fill_n(tag[j],2<<j,INF);
int* l = a; int* r = a+(2<<j);
for(; l!=a+n; r+=(2<<j)){
int* const mid = l+(1<<j);
ori[std::min(*l,*mid)] = j; // lose here
std::merge(l,mid,mid,r,tmp,std::greater<int>());
memcpy(l,tmp,(2<<j)<<2); // copy back
for(int* i=tag[j]; l!=r; ++l,++i)
*i = std::min(*i,*l); // corresponding
}
}
ori[n-1] = k; // the final winner
for(int q=readint(),x,y,ans=0; q; --q){
x = readint(), y = readint();
if(typ) x ^= ans, y ^= ans;
if(!y){
printf("%d\n",ans=ori[x-1]); continue; }
int l = 31-__builtin_clz(y); /** smaller than @a y */
int r = 31-__builtin_clz(x--); /** too big to replace */
if(l > r){
printf("%d\n",ans=r); continue; }
while(l != r){
const int mid = (l+r+1)>>1;
if(tag[mid-1][y] <= x) // acceptable
l = mid; else r = mid-1;
}
printf("%d\n",ans=r);
}
return 0;
}
边栏推荐
- Redis AOF log persistence
- Share an esp32 relay
- [wechat applet development (V)] the interface is intelligently configured according to the official version of the experience version of the development version
- [TA frost wolf \u may - hundred people plan] Figure 3.7 TP (d) r architecture of mobile terminal
- P6118 [JOI 2019 Final]珍しい都市 题解
- Actual case of ROS communication
- "29 years old, general function test, how do I get five offers in a week?"
- “29岁,普通功能测试,我是如何在一周内拿到5份Offer的?”
- Special network technology virtual host PHP version setting
- POC模拟攻击利器 —— Nuclei入门(一)
猜你喜欢

IO流:节点流和处理流详细归纳。

1313_ Pyserial installation and document generation

分布式事务——Senta(一)

为什么登录时,明明使用的是数据库里已经有的账号信息,但依旧显示“用户不存在”?

第二季度邮件安全报告:邮件攻击暴增4倍,利用知名品牌获取信任

MySQL is shown in the figure. The existing tables a and B need to be associated with a and B tables through projectcode to find idcardnum with different addresses.

分布式 session 的4个解决方案,你觉得哪个最好?

JS中的reduce()函数介绍

2022.7.8 supplement of empty Luna

TFX airflow experience
随机推荐
POC simulation attack weapon - Introduction to nucleus (I)
CNN循环训练的解释 | PyTorch系列(二十二)
Collision and rebound of objects in unity (learning)
Commissioning experience of ROS
First knowledge of C language -- structure, branch and loop statements
数据中台夯实数据基础
基于FPGA的64位8级流水线加法器
2022.7.8 eth price analysis
[TA frost wolf \u may - hundred people plan] Figure 3.7 TP (d) r architecture of mobile terminal
数字孪生农业丨智慧农业稻米加工厂从“看天吃饭”到“知天而作”
欢迎使用CSDN-markdown编辑器阿萨德
【ELM分类】基于核极限学习机和极限学习机实现UCI数据集分类附matlab代码
【微信小程序开发(六)】绘制音乐播放器环形进度条
Is it you who are not suitable for learning programming?
[leetcode] 13. linked list cycle · circular linked list
【OpenGL】GLES20.glClear
Chapter III queue
Welcome to CSDN markdown editor Assad
[elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code
ROS的调试经验