【POJ3580】【splay版】SuperMemo

Description

Your friend, Jackson is invited to a TV show called SuperMemo in which the participant is told to play a memorizing game. At first, the host tells the participant a sequence of numbers, {A1, A2, ... An}. Then the host performs a series of operations and queries on the sequence which consists:

  1. ADD x y D: Add D to each number in sub-sequence {Ax ... Ay}. For example, performing "ADD 2 4 1" on {1, 2, 3, 4, 5} results in {1, 3, 4, 5, 5}
  2. REVERSE x y: reverse the sub-sequence {Ax ... Ay}. For example, performing "REVERSE 2 4" on {1, 2, 3, 4, 5} results in {1, 4, 3, 2, 5}
  3. REVOLVE x y T: rotate sub-sequence {Ax ... Ay} T times. For example, performing "REVOLVE 2 4 2" on {1, 2, 3, 4, 5} results in {1, 3, 4, 2, 5}
  4. INSERT x P: insert P after Ax. For example, performing "INSERT 2 4" on {1, 2, 3, 4, 5} results in {1, 2, 4, 3, 4, 5}
  5. DELETE x: delete Ax. For example, performing "DELETE 2" on {1, 2, 3, 4, 5} results in {1, 3, 4, 5}
  6. MIN x y: query the participant what is the minimum number in sub-sequence {Ax ... Ay}. For example, the correct answer to "MIN 2 4" on {1, 2, 3, 4, 5} is 2

To make the show more interesting, the participant is granted a chance to turn to someone else that means when Jackson feels difficult in answering a query he may call you for help. You task is to watch the TV show and write a program giving the correct answer to each query in order to assist Jackson whenever he calls.

Input

The first line contains n (n ≤ 100000).

The following n lines describe the sequence.

Then follows M (M ≤ 100000), the numbers of operations and queries.

The following M lines describe the operations and queries.

Output

For each "MIN" query, output the correct answer.

Sample Input

5
1 
2 
3 
4 
5
2
ADD 2 4 1
MIN 4 5

Sample Output

5

Source

【分析】
真实蛋疼了。。
第一次写的时候居然犯了一个傻逼到极点的错误。。。。
翻转部分不会,是看别人的。不过感觉应该还有不同的写法。
代码写得比较丑,主要是尝试了引用。
  1 #include <iostream>
  2 #include <cstdio>
  3 #include <algorithm>
  4 #include <cstring>
  5 #include <vector>
  6 #include <utility>
  7 #include <iomanip>
  8 #include <string>
  9 #include <cmath>
 10 #include <queue>
 11 #include <assert.h>
 12 #include <map>
 13 #include <ctime>
 14 #include <cstdlib>
 15 #define LOCAL
 16 const int MAXN = 200000 + 10;
 17 const int INF = 100000000;
 18 const int SIZE = 450;
 19 const int maxnode =  0x7fffffff + 10;
 20 using namespace std;
 21 struct SPLAY{
 22        struct Node{
 23               int val, Min;//分别为值,最小值,大小和lazy下标 
 24               int size, lazy;
 25               bool turn;
 26               Node *parent, *ch[2];
 27               
 28               //初始化 
 29               void NEW(int x){
 30                    Min = val = x;
 31                    size = 1;
 32                    lazy = turn = 0;
 33                    parent = ch[0] = ch[1] = NULL;
 34               }
 35               int cmp(){
 36                   if (parent->ch[0] == this) return 0;
 37                   if (parent->ch[1] == this) return 1;
 38               }
 39               //还是不要写在里面了..
 40               /*void pushdown(){
 41                    
 42               } 
 43               void update(){
 44                    size = 1;
 45                    if (x->ch[0] != NULL) size += x->ch[0]->size;
 46                    if (x->ch[1] != NULL) size += x->ch[0]->size;
 47               }     
 48               */    
 49        }mem[MAXN], *root;//mem为静态数组 
 50        int tot;
 51        
 52        int get(Node *&x){return (x == NULL ? 0 : x->size);}
 53        //————————————————————这一部分不能卸载里面 
 54        //更新 
 55        void update(Node *&x){
 56             if (x == NULL) return;
 57             x->size = 1;
 58             x->Min = x->val;
 59             if (x->ch[0] != NULL) {x->Min = min(x->Min, x->ch[0]->Min);x->size += x->ch[0]->size;}
 60             if (x->ch[1] != NULL) {x->Min = min(x->Min, x->ch[1]->Min);x->size += x->ch[1]->size;}
 61        }
 62        void pushdown(Node *&x){//标记下传 
 63             if (x == NULL) return;
 64             if (x->lazy){
 65                int tmp = x->lazy;
 66                x->val += tmp;
 67                if (x->ch[0] != NULL) {x->ch[0]->lazy += tmp;x->ch[0]->Min += tmp;}
 68                if (x->ch[1] != NULL) {x->ch[1]->lazy += tmp;x->ch[1]->Min += tmp;}
 69                x->lazy = 0;
 70             } 
 71             if (x->turn){//翻转
 72                swap(x->ch[0], x->ch[1]);//swap内部用什么实现的呢? 
 73                
 74                if (x->ch[0] != NULL) x->ch[0]->turn ^= 1;
 75                if (x->ch[1] != NULL) x->ch[1]->turn ^= 1; 
 76                x->turn = 0;
 77             }
 78        }
 79        
 80        //———————————————————————————— 
 81        //旋转,1为右旋, 0为左旋
 82        void Rotate(Node *&x, int d){//不用引用也可以 
 83             Node *y = x->parent;
 84             pushdown(y);//注意顺序 
 85             pushdown(x);
 86             pushdown(x->ch[d]);//这个不要忘了
 87             
 88             y->ch[d ^ 1] = x->ch[d];
 89             if (x->ch[d] != NULL) x->ch[d]->parent = y;
 90             x->parent = y->parent;
 91             if (y->parent != NULL){
 92                if (y->parent->ch[0] == y) y->parent->ch[0] = x;
 93                else y->parent->ch[1] = x;
 94             } 
 95             x->ch[d] = y;
 96             y->parent = x;
 97             update(y);
 98             if (y == root) root = x;//如果是引用要小心root被传下去 
 99        } 
100        void debug(){
101             Node *p = new Node;
102             root = new Node;
103             root->ch[1] = p;
104             p->parent = root;
105             printf("%d", p->cmp());
106        }
107        //注意我写的这个跟下午那个不一样,下午那个好麻烦 
108        void splay(Node *&x, Node *&y){
109             pushdown(x);
110             while (x != y){
111                   if(x->parent == y){
112                             if (y->ch[0] == x) Rotate(x, 1);
113                             else Rotate(x,0);
114                             break;
115                   }else{
116                             Node *y = x->parent, *z = y->parent;//注意一定要这样弄一下 
117                             if (z->ch[0] == y)
118                             if (y->ch[0] == x) Rotate(y,1),Rotate(x, 1);
119                             else Rotate(x, 0), Rotate(x, 1); 
120                             else if (y->ch[1] == x) Rotate(y, 0), Rotate(x, 0); 
121                             else Rotate(x, 1), Rotate(x, 0); 
122                             if (z == y) break;
123                   }
124                   update(x);
125             }
126             update(x);
127        }
128        //寻找第k大 
129        void find(Node *&t, int k){
130             int tmp;
131             Node *p = root;
132             while (1){
133                   pushdown(p);
134                   tmp = get(p->ch[0]);
135                   if (k == (tmp + 1)) break;
136                   if (k <= tmp) p = p->ch[0];
137                   else {k -= tmp + 1, p = p->ch[1];}
138             }
139             pushdown(p);
140             splay(p, t);
141        }
142        //插入操作 
143        void Insert(int pos, int val){
144             //还是卡出来 
145             find(root, pos + 1);
146             find(root->ch[1], pos + 2);
147             Node *t = &mem[tot++], *x = root->ch[1];
148             pushdown(root);
149             pushdown(x);
150             t->NEW(val);
151             //直接拆开放中间,放在root->ch[1]->ch[0]应该也可以 
152             t->ch[1] = x;
153             x->parent = t;
154             root->ch[1] = t;
155             t->parent = root;
156             splay(x, root);
157        }
158        //区间加 
159        void Add(int l, int r, int x){
160             find(root, l);
161             find(root->ch[1] , r + 2);
162             Node *t = root->ch[1]->ch[0];
163             pushdown(t);
164             update(t);
165             t->Min += x;
166             t->lazy += x;
167             splay(t, root);
168        }
169        //翻转操作 
170        void Reverse(int l, int r){
171             find(root, l);
172             find(root->ch[1], r + 2);
173             root->ch[1]->ch[0]->turn ^= 1;
174             Node *x = root->ch[1]->ch[0];
175             splay(x, root);
176        }
177        //交换操作,这一段我是看别人的.... 
178        void Revolve(int l, int r, int t){
179             Node *p1, *p2;
180             
181             find(root, l);
182             find(root->ch[1], r + 2);
183             find(root->ch[1]->ch[0], r + 1 - t);
184             
185             p1 = root->ch[1]->ch[0];
186             pushdown(p1);
187             p2 = p1->ch[1];
188             p1->ch[1] = NULL;
189             find(root->ch[1]->ch[0], l + 1);
190             p1 = root->ch[1]->ch[0];
191             pushdown(p1);
192             p1->ch[0] = p2;
193             p2->parent = p1;
194             splay(p2, root);
195        }
196        int getMin(int l, int r){
197             find(root, l);
198             find(root->ch[1], r + 2);
199             Node *x = root->ch[1];
200             pushdown(x);
201             x = x->ch[0];
202             pushdown(x);
203             update(x);
204             return x->Min; 
205        }
206        void Erase(int pos){//删除 
207             find(root, pos);
208             find(root->ch[1], pos + 2);
209             pushdown(root->ch[1]);
210             root->ch[1]->ch[0] = NULL;
211             Node *x = root->ch[1];
212             splay(x, root);
213        }
214        void init(){
215             //注意还要加一个正无穷 
216             tot = 0;
217             root = &mem[tot++];
218             root->NEW(INF);
219             root->ch[1] = &mem[tot++];
220             root->ch[1]->NEW(INF);
221        }
222        void print(Node *t){
223             if (t == NULL) return;
224             print(t->ch[0]);
225             printf("%d ", t->val);
226             if (t->parent != NULL) printf("%d\n", t->parent->val);
227             print(t->ch[1]);
228        }
229 }A;
230 
231 int n, m;
232 //注意在这里为了防止掉到0,所以每个位置都要+1 
233 void init(){//初始化 
234     A.init();
235     scanf("%d", &n);
236     for (int i = 0 ; i < n; i++){
237         int x;
238         scanf("%d", &x);
239         A.Insert(i, x);
240         //printf("%d\n", A.root->val);
241     }
242     //A.print(A.root);
243 }
244 void work(){
245      scanf("%d", &m);
246      for (int i = 1; i <= m; i++){//询问,按顺序来。。 
247            char str[20];
248            scanf("%s", str);
249            if (str[0] == 'A'){
250               int l, r, x;
251               scanf("%d%d%d", &l, &r, &x);
252               A.Add(l, r, x);
253            }else if (str[0] == 'R'){
254               int l, r;
255               scanf("%d%d", &l, &r);
256               if (str[3] == 'E') A.Reverse(l, r);
257               else{
258                    int x, len;
259                    scanf("%d", &x);
260                    len = r - l + 1;
261                    x = (x % len + len) % len;
262                    if (x == 0 || l == r) continue;//我开始居然傻逼的写在前面.... 
263                    A.Revolve(l, r, x);
264               } 
265            }else if (str[0] == 'I'){
266                  int l, x; 
267                  scanf("%d%d", &l, &x);
268                  A.Insert(l, x);
269            }else if (str[0] == 'D'){
270                  int l;
271                  scanf("%d", &l);
272                  A.Erase(l);
273            }else if (str[0] == 'M'){
274                  int l, r;
275                  scanf("%d%d", &l, &r);
276                  printf("%d\n", A.getMin(l, r));
277            }
278      }
279 }
280 void debug(){
281      
282 }
283 
284 int main(){
285     
286     init();
287     work();
288     //debug();
289     //A.debug();
290     return 0;
291 }
View Code

 

转载于:https://www.cnblogs.com/hoskey/p/4331221.html

基于STM32设计的猪舍养殖的监控系统_325 本课题基于STM32单片机,设计一款能够实时监测猪舍环境的智能监控系统。该系统能够通过温湿度、空气质量、光照强度等传感器实时监测猪舍的环境,并能够通过自动化控制设备(如风扇、照明灯、消毒喷雾等)调节环境参数,确保养殖环境的适宜性。同时,系统还支持通过ESP8266模块实现数据上传与远程控制,使养殖管理者能够通过手机APP或计算机远程监控和控制猪舍环境。 阅读详情

相关推荐

利用HTML+CSS设计PPT:html-to-pptx实现自动化转换与可编辑输出

在办公自动化和前端开发领域,将网页技术应用于文档生成是一个重要的技术方向。其核心原理在于通过解析HTML/CSS的结构与样式,将其映射为目标文档的原生对象模型。这项技术的价值在于,它能够将Web技术栈强大的布局与样式能力(如Flexbox、CSS Grid)与办公软件(如Microsoft PowerPoint)的广泛兼容性和可编辑性相结合。在实际应用场景中,这种技术特别适合需要快速生成兼具设计感与实用性的演示文稿,例如数据报告、产品发布和营销材料。本文探讨的html-to-pptx项目正是这一思路的工程实

weixin_30652491的博客 487

POJ 3580 splay模板题

POJ3580 splay

~~Free planet 跳动的行星 697

ElasticSearch集群搭建

docker安装es集群

weixin_46562226的博客 2026

POJ3580 splay

题意:对于一个序列有若干的操作

江上白衣凌云 464

Xilinx UltraScale+ FPGA实战:手把手教你实现USB3.0设备开发(附原理图+代码)

本文详细介绍了如何使用Xilinx UltraScale+ FPGA开发USB3.0设备,涵盖硬件设计、Vivado工程配置、Petalinux系统定制及功能测试全流程。通过实战案例和优化技巧,帮助开发者快速掌握高速数据传输实现方法,提升嵌入式系统开发效率。

weixin_29159995的博客 209

算法 A 求稳健平均值和稳健标准差

文章目录算法原理代码 算法原理 算法 A 来自 GB/T 6379.5。应用此算法计算得到数据平均值和标准差的稳健值。稳健性是估计算法的特点,而不是其产生的估计值的特点,因此严格来说,称由此算法计算的平均值和标准差是稳健的是不确切的。然而,为避免使用繁琐的术语,“稳健均值”和“稳健标准差”应理解为利用稳健算法计算的总体均值和总体标准差的均值估计。 设数据为 xi,i∈(1,2,⋯ ,n)x_i, i\in(1,2,\cdots,n)xi​,i∈(1,2,⋯,n),记稳健平均值为 x∗,s∗x^*, s^*x

zhuo木鸟的博客 9258

poj3580(splay 毒瘤题)

3: Lydsy1895 SuperMemo Time Limit: 10 SecMemory Limit: 64 MBSubmit: 15Solved: 11[Submit][Status][Web Board] Description 给出一个初始序列fA1;A2;:::Ang,要求你编写程序支持如下操作: 1. ADDxyD:给子序列fAx:::Ayg的每个元素都...

allia990718的博客 414

红薯游客小眼睛接口分析与Python脚本实现

小眼睛接口与请求流程分析,使用Python实现小眼睛+1

吴秋霖的博客 2615

BZOJ 1895 & POJ 3580 supermemo (splay)

SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 16524   Accepted: 5214 Case Time Limit: 2000MS Description Your friend, Jackson is invited t

K键盘里的青春K 1590

详解RT-DETR网络结构/数据集获取/环境搭建/训练/推理/验证/导出/部署

本文给大家带来是利用RT-DETR模训练自己的数据集,RT-DETR是一种新提出的目标检测模型,它利用的自注意力机制来处理图像数据。不同于YOLO通过连续的卷积层直接对图像区域进行分析,RT-DETR采用Transformer架构中的自注意力机制,这允许模型更有效地理解图像中不同部分之间的关系。这种方法使得RT-DETR在处理图像中的复杂场景和多对象环境时,能够展现出更高的准确性和效率。此外,RT-DETR在保持高精度的同时,也针对实时处理进行了优化,使其适合需要快速响应的应用场景。

Snu77的博客 6万+

【模型实战】MiMo-VL-7B讲解与实战

维度成绩MMMU70.6(图像理解最难测试之一)VideoMME70.8(视频理解标杆)59.4(超越78B参数模型)56.1(超过专用GUI模型)Elo评分开源VLM排名第一(7B~72B)社区热度过去一个月下载超1,600次(RL+SFT)📌一句话概括MiMo-VL 是目前性能最强、推理最稳、体验最佳、生态最全的7B级开源视觉语言模型。

m0_47867638的博客 1199

splay POJ 3580SuperMemo

从搞acm以来,一直负责队内的图论,搜索,树形DP。今年的regional结束了,想学学数据结构了 splay用的是孟神的模板,发现splay就是一个splay操作,没什么困难的,果断搞起 #include #include #include #include using namespace std; #define mid (L+R>>1) const int M = (

hrbeu_sssccode 968

如何通过 GitHub Actions 使用 SSH 自动化部署到阿里云 ECS 实例

通过 GitHub Actions 和 SSH 自动化部署,可以显著提高你的开发效率和部署的可靠性。本文介绍了如何生成 SSH 密钥、将公钥添加到阿里云 ECS 实例、将私钥添加到 GitHub Secrets,以及编写 GitHub Actions 工作流来实现自动化部署。希望这篇文章对你有所帮助!

吃面不喝汤的博客 1511

POJ3580 SuperMemo (Splay Tree的各种操作)

这题基本上就是SplaySplay TreeTree维护区间的终极题了。 AC后就能领悟到SplaySplay TreeTree的真谛(O_O) Splay Tree模板戳这里 题目大意: 对于一个数列{A1,A2,...,An}\{A_1,A_2,...,A_n\},写一个程序能够实现以下操作: ADD x y D:给数列{Ax,...,Ay}\{A_x,...,A_y\}中的每一个数都增

Sunshine_cfbsl 718

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

BZOJ 1895 & POJ 3580 supermemo [SPLAY]【数据结构】

SPLAY 入门级别题目 区间加,翻转,剪切,询问最值。点插入,删除。

Tabris的博客 939

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

「POJ3580」SuperMemo【splay】

SuperMemo Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 19781 Accepted: 6220 Case Time Limit: 2000MS Description Your friend, Jackson is invited to a TVTVTV show called SuperMemo in whi...

wzw 303

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

POJ3580 SuperMemo

splay模板

Monster__Yi的博客 1115

POJ-3580 SuperMemo(Splay树)

SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 16260   Accepted: 5111 Case Time Limit: 2000MS Description Your friend, Jackson is invited to

十分残念的博客 433

蓝书(算法竞赛进阶指南)刷题记录——POJ3580 SuperMemo (Splay)

题目:POJ3580. 题目大意:给定一个长度为nnn的序列,现在有mmm次操作支持: 1.格式ADD&ThinSpace;x&ThinSpace;y&ThinSpace;vADD\,x\,y\, vADDxyv,表示给区间[x,y][x,y][x,y]加上vvv. 2.格式REVERSE&ThinSpace;x&ThinSpace;yREVERSE\,x\...

hzk_cpp的博客 295

poj-3580 SuperMemo[splay tree]

学了splay 后 撸的第一道题。 是看了大神的教学,引用了大神的核心代码才会的:模板出处 刚开始没注意:使用一个节点你需要把他的标记先下压。提供了好多次wa。 /*题意:给一个数组,有6种操作: (1)add x y d : [x,y]中所有数加d ----x-1 ---------y+1 ---[x,y] 给y-1的左子树加上+d 标记 (2)reverse x y: [x,y

a915800048的专栏 475

POJ 3580 SuperMemo Splay树各种区间操作

SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 11106   Accepted: 3494 Case Time Limit: 2000MS Description Your friend, Jackson is invited t

suyuxuan94的专栏 535

SuperMemo 【POJ - 3580】【Splay】

题目链接 一份完整的解题代码 这是第二次来做这道题,关于Splay与其他数据结构又更好的联系起来了,更加的注意那些在细节上的处理,在pushdown()与pushup()上的处理尤其重要。 这次写的更加清晰了。 #include &lt;iostream&gt; #include &lt;cstdio&gt; #include &lt;cmath&gt; #include &lt...

既然弱小,就只顾变强就是了 234

poj3580 SuperMemo splay --- 从入门到入土

(太可怕了,我只是一个刚学懂splay的蒟蒻) poj地址:http://poj.org/problem?id=3580 AcWing地址:https://www.acwing.com/problem/content/268/ 题意: 给你一个数列 A1~An 有几个操作: 输入格式 第一行包含一个整数 n。 接下来 n 行给出了序列中的数。 接下来一行包含一个整数 ...

forOnward的博客 471

【Splay 超全模板!!】POJ - 3580 SuperMemo

 POJ - 3580  SuperMemo   Your friend, Jackson is invited to a TV show called SuperMemo in which the participant is told to play a memorizing game. At first, the host tells the participant a sequence...

qq_41037114的博客 255

poj3580 SuperMemo

一看就知道是splay。。其实是专门为了练splay而写的。。还是比较好写的,起码不要维护N个信息。。代码也不是很长,只有166行。维护的信息少了,collect 过程自然就舒服了。 Submit1:果断WA。。Submit2:AC。因为拿了hty的程序拿来对拍。。对拍果然是个很强大的东东。犯了N个低级错误,原因是对于arrange过程的乱用。splay主过程很漂亮,基本就是模板了,好

roosephu的专栏 770

POJ 3580 SuperMemo Splay 区间维护

题目大意:维护一种数据结构,它支持以下功能: 1.从

(╯°口°)╯(┴—┴ 1079
上一篇: 【POJ3481】【splay】Double Queue
下一篇: 【HDU3487】【splay分裂合并】Play with Chain
Gregory99174
博客等级 码龄10年 2粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值