SHARE
TWEET

Untitled

DASBD72 May 19th, 2019 (edited) 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <cstring>
  7. using namespace std;
  8. struct Line{
  9.     int index;
  10.     Line *l,*r;
  11. }*ptr[350][2];//head&tail
  12.  
  13. int cd(int nu,int de){//ceiling devide
  14.     int frac = (nu%de==0) ? nu/de : nu/de+1;
  15.     return frac;
  16. }
  17. int main() {
  18.     int N, M, BK, BL, amount;
  19.     cin >> N >> M;
  20.     BL = 316, amount = N;
  21.     //ªì©l¤Æ
  22.     for(int i = 1;i <= cd(N+M, BL);i++){
  23.         ptr[i][0] = new Line(); ptr[i][0]->index = -1;
  24.         ptr[i][1] = new Line(); ptr[i][1]->index = -2;
  25.         ptr[i][0]->r = ptr[i][1]; ptr[i][0]->l = ptr[i-1][1];
  26.         ptr[i][1]->l = ptr[i][0];
  27.         if(ptr[i-1][1]!=NULL) ptr[i-1][1]->r = ptr[i][0];
  28.        
  29.     }
  30.     //¿é¤J
  31.     for(int i = 1, x;i <= N;i++){
  32.         cin >> x;
  33.         Line *node = new Line();
  34.         node->index = x;
  35.         node->r = ptr[cd(i,BL)][1];
  36.         node->l = ptr[cd(i,BL)][1]->l;
  37.         ptr[cd(i,BL)][1]->l = node;
  38.         node->l->r = node;
  39.     }
  40.     //«ü¥O
  41.     while(M--){
  42.         char command[6];int coor, x;
  43.         cin >> command >> coor;
  44.         Line *node = ptr[cd(coor,BL)][0];
  45.         int tmp = coor - (cd(coor,BL) - 1) * BL;
  46.         while(tmp--&&node!=NULL)node = node->r;
  47.         if(command[0]=='A'){
  48.             amount++;
  49.             cin >> x;
  50.             Line *insert = new Line();
  51.             insert->index = x;
  52.             insert->l = node->l; insert->r = node;
  53.             insert->l->r = insert;
  54.             node->l = insert;
  55.             for(int i = cd(coor,BL);i < cd(amount,BL);i++){
  56.                 Line *pull = ptr[i][1]->l;
  57.                 pull->r->l = pull->l; pull->l->r = pull->r;
  58.                 pull->r = ptr[i+1][0]->r; pull->r->l = pull;
  59.                 pull->l = ptr[i+1][0]; ptr[i+1][0]->r = pull;
  60.             }
  61.         }
  62.         else if(command[0]=='L'){
  63.             node->l->r = node->r; node->r->l = node->l;
  64.             for(int i = cd(coor,BL);i < cd(amount,BL);i++){
  65.                 Line *pull = ptr[i+1][0]->r;
  66.                 pull->l->r = pull->r; pull->r->l = pull->l;
  67.                 pull->l = ptr[i][1]->l; pull->l->r = pull;
  68.                 pull->r = ptr[i][1]; ptr[i][1]->l = pull;
  69.             }
  70.             amount--;
  71.         }
  72.         else printf("%d\n",node->index);
  73.     }
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top