SGU 187.Twist and whirl - want to cheat( splay )

維護一個支持翻轉次數M的長度N的序列..最后輸出序列.1<=N<=130000, 1<=M<=2000

splay裸題...

-------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 130009;
struct Node {
Node *p, *ch[2];
int s, v;
bool rev;
inline void setc(Node* t, int c) {
ch[c] = t;
t->p = this;
}
inline int d() {
return p->ch[1] == this;
}
inline void Rev() {
rev ^= 1;
}
inline void pushDown() {
if(rev) {
ch[0]->Rev();
ch[1]->Rev();
swap(ch[0], ch[1]);
rev = false;
}
}
inline void upd() {
s = ch[0]->s + ch[1]->s + 1;
}
} mempool[maxn], *pt, *Root, *Null;
void InitSplay() {
pt = mempool;
Root = Null = pt++;
Null->s = 0;
Null->setc(Null, 0);
Null->setc(Null, 1);
}
Node* newNode(int v) {
pt->v = v;
pt->rev = false;
pt->s = 1;
pt->p = pt->ch[0] = pt->ch[1] = Null;
return pt++;
}
void Rot(Node* t) {
Node* p = t->p;
p->pushDown();
t->pushDown();
int d = t->d();
p->p->setc(t, p->d());
p->setc(t->ch[d ^ 1], d);
t->setc(p, d ^ 1);
p->upd();
if(p == Root) Root = t;
}
void Splay(Node* t, Node* f = Null) {
for(Node* p = t->p; p != f; p = t->p) {
if(p->p != f)
p->d() != t->d() ? Rot(t) : Rot(p);
Rot(t);
}
t->upd();
}
Node* Build(int l, int r) {
if(l >= r) return Null;
int m = (l + r) >> 1;
Node* t = newNode(m);
t->setc(Build(l, m), 0);
t->setc(Build(m + 1, r), 1);
t->upd();
return t;
}
Node* Select(int k) {
for(Node* t = Root; ; ) {
t->pushDown();
int s = t->ch[0]->s;
if(k == s) return t;
if(k < s)
t = t->ch[0];
else
k -= s + 1, t = t->ch[1];
}
}
Node* Range(int l, int r) {
Splay(Select(--l));
Splay(Select(++r), Root);
return Root->ch[1]->ch[0];
}
void DFS(Node* t) {
if(t == Null) return;
t->pushDown();
DFS(t->ch[0]);
printf("%d ", t->v);
DFS(t->ch[1]);
}
int N, M;
int main() {
InitSplay();
scanf("%d%d", &N, &M);
Root = Build(0, N + 2);
while(M--) {
int l, r;
scanf("%d%d", &l, &r);
Node* t = Range(l, r);
t->Rev();
Splay(t);
}
DFS(Range(1, N));
return 0;
}

-------------------------------------------------------------

187. Twist and whirl - want to cheat

time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard input
output: standard output



A well-known sharper I*** invented a new way to swindle people. There are N thimbles on the table, and there is a small ball with the number under each of them. The balls are numbered with numbers from 1 to N from left to right. At one operation I*** changes the order of some subsequence of successive thimbles to the opposite. Your task is to find the order of numbers (from left to right) in sequence after all of his manipulations. The total number of manipulations is M.

Input
The first line contains two integer numbers N and M (1<=N<=130000, 1<=M<=2000) separated by a space. Each of the following M lines contains two integer numbers Pi, Qi (1<=Pi<=Qi<=N) - positions of the leftmost and rightmost thimbles in rotated sequence.

Output
Output the sequence of N numbers - the numbers of balls in the thimbles from left to right.

Sample test(s)

Input
Test #1?
5 2?
1 3?
4 5?

Test #2?
5 2?
1 4?
2 5?

Output
Test #1?
3 2 1 5 4?

Test #2?
4 5 1 2 3
[submit]
[forum]

Author:Michael R. Mirzayanov
Resource:ACM International Collegiate Programming Contest 2003-2004?
North-Eastern European Region, Southern Subregion
Date:2003 October, 9




?

轉載于:https://www.cnblogs.com/JSZX11556/p/5049649.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/373955.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/373955.shtml
英文地址,請注明出處:http://en.pswp.cn/news/373955.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

練習一萬小時成天才

隨著暢銷書《異類》的流行&#xff0c;“練習一萬小時成天才”這個口號現在是盡人皆知。也許仍然有不少人相信那些不世出的天才必有天生的神秘能力&#xff0c;但科學家通過大量的調查研究已經達成共識&#xff0c;那就是所有頂級高手都是練出來的。不但如此&#xff0c;最近幾…

(轉)數據流圖

轉自:http://jingyan.baidu.com/article/4f34706eefdb04e387b56deb.html 數據流圖4種圖元 數據流圖的實例 轉載于:https://www.cnblogs.com/wrencai/p/5852389.html

從CLI監視OpenJDK

目前&#xff0c;我大部分時間在Java虛擬機 &#xff08;JVM&#xff09;內或周圍進行大量工作&#xff0c;大部分時間是在Linux上。 當事情變得不對勁并且我試圖確定原因時&#xff0c;我接觸了Java性能分析工具。 這些工具有兩種形式&#xff0c;一種是精美的GUI&#xff08;…

python數據庫優化_python | Mysql性能優化一

對mysql優化是一個綜合性的技術&#xff0c;主要包括表的設計合理化(符合3NF)添加適當索引(index) [四種: 普通索引、主鍵索引、唯一索引unique、全文索引]分表技術(水平分割、垂直分割)讀寫[寫: update/delete/add]分離存儲過程 [模塊化編程&#xff0c;可以提高速度]對mysql配…

MySQL中文亂碼問題

項目中用到MySQL數據庫時中文出現亂碼問題&#xff08;中文字符都變成了&#xff1f;&#xff09;解決&#xff1a; 1、統一項目與數據庫的編碼&#xff0c;項目中用的是UTF-8因此我的把數據庫的編碼統一成UTF-8 修改方式&#xff1a;修改 MySQL根目錄中的 my.ini 文件替換d…

json與字符串互轉

1 字符串轉JSON var objeval((str"))var objJSON.parse(str)var objstr.parseJSON()2 JSON轉字符串 var strobj.toJSONString()var strJSON.stringify(obj)轉載于:https://www.cnblogs.com/liu-xia/p/5050878.html

使用RequestFactory API進行Spring GWT集成

從GWT 2.4開始&#xff0c;將RequestFactory API與后端的Spring服務集成很容易&#xff0c;您需要做的就是在服務器上創建一個自定義ServiceLocator&#xff0c;GWT將使用它來正確定位被調用的服務&#xff1a; public class SpringServiceLocator implements ServiceLocator {…

C++實例講解Binder通信

binder是android里面的通信機制&#xff0c;這就不說它如何如何好了&#xff0c;Goog已經說過了&#xff0c;這里不多說。binder是一個面向對象的編程方法&#xff0c;大量使用虛函數類。最近研究binder看到一網友寫的&#xff0c;就借鑒一下。這個例子很好的解釋里binder通信關…

2014編程之美初賽第一場

題目1 : 焦距 時間限制:2000ms單點時限:1000ms內存限制:256MB描述 一般來說&#xff0c;我們采用針孔相機模型&#xff0c;也就是認為它用到的是小孔成像原理。 在相機坐標系下&#xff0c;一般來說&#xff0c;我們用到的單位長度&#xff0c;不是“米”這樣的國際單位&#x…

高中python公開課怎么上好_如何上好高中英語公開課

談如何上好高中英語公開課對青年教師來說&#xff0c;開一節公開課&#xff0c;如同完成一次蛻變&#xff0c;累掉一層皮&#xff0c;有著刻骨銘心的陣痛&#xff0c;但換來的是突飛猛進的專業成長。可以說&#xff0c;公開課是青年教師培訓的有效途徑&#xff0c;是名師培養的…

Codeforces Round #261 (Div. 2) - E (459E)

題目連接&#xff1a;http://codeforces.com/contest/459/problem/E 題目大意&#xff1a;給定一張有向圖&#xff0c;無自環無重邊&#xff0c;每條邊有一個邊權&#xff0c;求最長嚴格上升路徑長度。(1≤n&#xff0c;m≤3 *10^5) 初見此題覺得以邊為點&#xff0c;以點為邊&…

回收對象以提高性能

總覽 在上一篇文章中&#xff0c;我說過對象反序列化更快的原因是由于使用了回收對象。 由于兩個原因&#xff0c;這可能令人驚訝&#xff1a;1&#xff09;相信如今創建對象是如此之快&#xff0c;無關緊要或與回收自己一樣快&#xff0c;2&#xff09;默認情況下&#xff0c;…

jquery GET POST

<!DOCTYPE html> <html> <head> <meta charset"UTF-8"> <head> <!--引入百度庫--> <script src"http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <title></title> <scrip…

C++高精度運算類bign (重載操作符)

大數據操作&#xff0c;有如下問題&#xff1a; 計算&#xff1a;45678913561232654213212314875231656511323132 456789135612326542132123*14875231656511323132 比較&#xff1a;7531479535511335666686565>753147953551451213356666865 ? long long類型存儲不了&…

oj系統格式錯誤_論文查重會不會檢查格式?【paperpp吧】

高等學校一般都會要求大學生在畢業時需要寫作畢業論文&#xff0c;并且會提前發出關于畢業論文的通知&#xff0c;在通知上一般會說明論文寫作的相關要求&#xff0c;其中就會規定論文的相關格式。當然&#xff0c;學校也會在通知中說明論文查重的相關事宜&#xff0c;那么論文…

JavaScript Cookies

相關&#xff1a;jquery-cookie cookie 是存儲于訪問者的計算機中的變量&#xff0c;常用來存儲用戶名字&#xff0c;密碼&#xff0c;日期&#xff0e; 示例&#xff1a; 1 document.cookie"usernameJohn Doe"; 2 document.cookie"usernameJohn Doe; expiresTh…

大數據 -- Hadoop集群搭建

Hadoop集群搭建 1.修改/etc/hosts文件 在每臺linux機器上&#xff0c;sudo vim /etc/hosts 編寫hosts文件。將主機名和ip地址的映射填寫進去。編輯完后&#xff0c;結果如下&#xff1a; 2.配置ssh&#xff0c;實現無密碼登錄 四臺虛擬機上&#xff0c;使用&#xff1a; ssh-ke…

通過示例休眠–第2部分(DetachedCriteria)

所以上次我們幫助正義聯盟有效地管理了他們的超級英雄。 今天&#xff0c;我們集中討論“復仇者聯盟”將如何使用冬眠的“分離標準”找出每個超級英雄的敵人&#xff0c;以保護他們的超級英雄。 您可以從此處下載工作示例。 在此示例中&#xff0c;我們僅考慮兩個實體。 復仇者…

2014編程之美初賽第二場

題目1 : 神奇的數列 時間限制:2000ms單點時限:1000ms內存限制:256MB描述 大神同學是一個熱愛數字的孩子&#xff0c;她無時無刻不在思考生活與數學的聯系。有一天&#xff0c;她發現其實公歷的設計是有講究的。 每4年就會多閏一天&#xff0c;每一百年又會有一年不是閏年&#…

usb大容量存儲設備驅動_usb無法識別怎么辦 如何解決usb識別故障【詳細步驟】...

usb無法識別怎么辦? 隨著計算機硬件飛速發展&#xff0c;外圍設備日益增多&#xff0c;鍵盤、鼠標等早已為人所共知&#xff0c;數碼相機、MP3隨身聽接踵而至&#xff0c;這么多的設備&#xff0c;如何接入個人計算機?USB就是基于這個目的產生的。USB是一個使計算機周邊設備連…