BZOJ1269 文本编辑器Editor

BZOJ 1269 文本编辑器Editor


解析:BZOJ1507加强版,首先是数据加强,然后是多了一个reverse,似乎没什么,但是这意味着你需要加上一系列的pushdown······千万不要把pushdown位置搞错,千万不要多打,千万不要少打,不要作死。


Source:

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         #include 
        
          #include 
         
           using namespace std; inline void R(int &v) { char c = 0; bool p = true; v = 0; while(!isdigit(c)) { if(c == '-') p = false; c = getchar(); } while(isdigit(c)) { v = (v << 3) + (v << 1) + (c ^ '0'); c = getchar(); } if(!p) v = -v; } template 
          
            struct memorypool { T buf[size], *tail, *end, *st[size]; int top; memorypool() : top(0), tail(buf), end(buf + size) {} inline T *alloc() { if (top) return st[--top]; if (tail != end) return tail++; return new T; } inline void recycle(T *p) { if (top > size) delete p; else st[top++] = p; } }; const int MAXN = 1024 * 1024 * 4 ; const int MAX = 1024 * 1024 * 4 ; template 
           
             struct Splay { enum Relation { L = 0, R = 1 }; struct node { node *child[2], *parent, **root; int size; T value; bool reverse, bound; inline void init(node *parent, node **root, const T &value, bool bound = false) { this->parent = parent, this->root = root, this->value = value, this->bound = bound; this->reverse = false, this->size = 1, child[L] = child[R] = NULL; } inline void recycle(memorypool 
            
              &pool) { if(child[L]) pool.recycle(child[L]); if(child[R]) pool.recycle(child[R]); } inline void pushdown() { if(reverse) { if(child[L]) child[L]->reverse ^= 1; if(child[R]) child[R]->reverse ^= 1; swap(child[L], child[R]), reverse = false; } } inline Relation relation() { return this == parent->child[L] ? L : R; } inline void maintain() { pushdown(), size = (child[L] ? child[L]->size : 0) + (child[R] ? child[R]->size : 0) + 1; } inline void rotate() { if(parent->parent) parent->parent->pushdown(); parent->pushdown(), pushdown(); Relation x = relation(); node *oldparent = parent; if(oldparent->parent) oldparent->parent->child[oldparent->relation()] = this; parent = oldparent->parent, oldparent->child[x] = child[x ^ 1]; if(child[x ^ 1]) child[x ^ 1]->parent = oldparent; child[x ^ 1] = oldparent, oldparent->parent = this, oldparent->maintain(), maintain(); if(!parent) *root = this; } inline void splay(node *targetparent = NULL) { while(parent != targetparent) { if(parent->parent == targetparent) rotate(); else { parent->parent->pushdown(), parent->pushdown(); if(parent->relation() == relation()) parent->rotate(), rotate(); else rotate(), rotate(); } } } inline int rank() { return child[L] ? child[L]->size : 0; } inline int pos() { return splay(), child[L] ? child[L]->size : 0; } } *root; memorypool 
             
               pool; Splay() : root(NULL) { buildbound(L), buildbound(R); } inline node *buildrange(const T *a, int l, int r, node *parent) { if(l > r) return NULL; register int mid = l + r >> 1; node *v = pool.alloc(); v->init(parent, &root, a[mid - 1]); if(l != r) v->child[L] = buildrange(a, l, mid - 1, v), v->child[R] = buildrange(a, mid+1, r, v); return v->maintain(), v; } inline void buildbound(Relation x) { node **v = &root, *parent = NULL; while(*v) parent = (*v), parent->size++, v = &parent->child[x]; (*v) = pool.alloc(), (*v)->init(parent, &root, 0, true), (*v)->maintain(); } inline node *select(int k) { k++; node *v = root; while(v->pushdown(), v->rank() + 1 != k) v = (v->rank() >= k ? v->child[L] : (k -= v->rank() + 1, v->child[R])); return v->splay(), v; } inline node *&select(int l, int r) { node *vl = select(l - 1), *vr = select(r + 1); return vl->splay(), vr->splay(vl), vr->child[L]; } inline void erase(int l, int r) { node *&range = select(l, r); range->recycle(pool), pool.recycle(range), range = NULL; root->child[R]->maintain(), root->maintain(); } inline void insert(int pos, const T *a, int n) { node *&range = select(pos + 1, pos); range = buildrange(a, 1, n, root->child[R]); root->child[R]->maintain(), root->maintain(); } inline void reverse(int l, int r) { node *range = select(l ,r); range->reverse ^= 1; } inline int size() { return root->size - 2; } }; Splay 
              
                splay; int main() { static char type[10], a[MAX], c; static int x, pos, n; R(n); while(n--) { scanf("%s", type); if(type[0] == 'I') { R(x); int cnt = 0; while(true) { c = getchar(); if(c >= 32 && c <= 126) a[cnt++] = c; if(cnt == x) break; } splay.insert(pos, a, x); } else if(type[0] == 'M') R(x), pos = x; else if(type[0] == 'D') R(x), splay.erase(pos + 1, pos + x); else if(type[0] == 'R') R(x), splay.reverse(pos + 1, pos + x); else if(type[0] == 'G') cout << splay.select(pos + 1)->value << '\n'; else if(type[0] == 'P') pos--; else if(type[0] == 'N') pos++; } return 0; } 
               
              
             
            
           
          
         
       
      
      
     
     
    
    
   
   

BZOJ 2908 题目是一个数据下载任务。这个任务要求下载指定的数据文件,并统计文件中小于等于给定整数的数字个数。 为了完成这个任务,首先需要选择一个合适的网址来下载文件。我们可以使用一个网络爬虫库,如Python中的Requests库,来帮助我们完成文件下载的操作。 首先,我们需要使用Requests库中的get()方法来访问目标网址,并将目标文件下载到我们的本地计算机中。可以使用以下代码实现文件下载: ```python import requests url = '目标文件的网址' response = requests.get(url) with open('本地保存文件的路径', 'wb') as file: file.write(response.content) ``` 下载完成后,我们可以使用Python内置的open()函数打开已下载的文件,并按行读取文件内容。可以使用以下代码实现文件内容读取: ```python count = 0 with open('本地保存文件的路径', 'r') as file: for line in file: # 在这里实现对每一行数据的判断 # 如果小于等于给定整数,count 加 1 # 否则,不进行任何操作 ``` 在每一行的处理过程中,我们可以使用split()方法将一行数据分割成多个字符串,并使用int()函数将其转换为整数。然后,我们可以将该整数与给定整数进行比较,以判断是否小于等于给定整数。 最后,我们可以将统计结果打印出来,以满足题目的要求。 综上所述,以上是关于解决 BZOJ 2908 数据下载任务的简要步骤和代码实现。 希望对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值