标签:产生 BMI 编号 翻转 getchar can char 输出 rev
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 998 Accepted Submission(s): 328
1 #include <bits/stdc++.h> 2 #define N 150010 3 using namespace std; 4 int n,m; 5 // deque<int> q[N]; 6 int main(){ 7 while(~scanf("%d%d",&n,&m)){ 8 deque<int> q[n+1]; 9 // init(); 10 for(int i=0;i<m;i++){ 11 int k,u,v,val,w; 12 scanf("%d",&k); 13 if(k==2){ 14 scanf("%d%d",&u,&w); 15 if(q[u].empty()){ 16 printf("-1\n"); 17 }else{ 18 if(w==0){ 19 printf("%d\n",q[u].front()); 20 q[u].pop_front(); 21 }else{ 22 printf("%d\n",q[u].back()); 23 q[u].pop_back(); 24 } 25 } 26 }else{ 27 if(k==1){ 28 scanf("%d%d%d",&u,&w,&val); 29 if(w==0){ 30 q[u].push_front(val); 31 }else{ 32 q[u].push_back(val); 33 } 34 }else{ 35 scanf("%d%d%d",&u,&v,&w); 36 if(w==0){ 37 while(!q[v].empty()){ 38 int x = q[v].front(); 39 q[u].push_back(x); 40 q[v].pop_front(); 41 } 42 }else{ 43 while(!q[v].empty()){ 44 int x = q[v].back(); 45 q[u].push_back(x); 46 q[v].pop_back(); 47 } 48 } 49 } 50 } 51 } 52 } 53 return 0; 54 }
标签:产生 BMI 编号 翻转 getchar can char 输出 rev
原文地址:https://www.cnblogs.com/zllwxm123/p/9461324.html