标签:nts nbsp scribe positive tor algorithm struct contains ast
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1204 Accepted Submission(s): 314
1 //2017-09-19 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 7 using namespace std; 8 9 const int N = 110000; 10 11 int a[N], n; 12 int _next[N], _pre[N]; 13 int head, tail, que[N<<1]; 14 15 int main() 16 { 17 int T; 18 scanf("%d", &T); 19 while(T--){ 20 scanf("%d", &n); 21 tail = 0; 22 for(int i = 1; i <= n; i++){ 23 scanf("%d", &a[i]); 24 _next[i] = i+1; 25 _pre[i] = i-1; 26 que[tail++] = i; 27 } 28 a[0] = 0; 29 a[n+1] = N; 30 _pre[0] = 0; 31 _next[0] = 1; 32 _pre[n+1] = N; 33 _next[n+1] = n+1; 34 int ans = n, fg = 1, ptr; 35 while(fg){ 36 fg = 0; 37 head = 0; 38 ptr = 0; 39 while(head < tail){ 40 int cnt = 0, i = que[head]; 41 for(; i <= n; i = _next[i]){ 42 if(a[i] > a[_next[i]]){ 43 cnt++; 44 fg = 1; 45 }else break; 46 } 47 if(cnt){ 48 ans -= cnt+1; 49 _next[_pre[que[head]]] = _next[i]; 50 _pre[_next[i]] = _pre[que[head]]; 51 que[ptr++] = _pre[que[head]]; 52 }; 53 while(que[head] <= i && head < tail)head++; 54 } 55 tail = ptr; 56 } 57 if(ans < 0)ans = 0; 58 printf("%d\n", ans); 59 for(int i = _next[0]; i <= n; i = _next[i]){ 60 if(_next[i] != N)printf("%d ", a[i]); 61 } 62 printf("\n"); 63 } 64 65 return 0; 66 }
标签:nts nbsp scribe positive tor algorithm struct contains ast
原文地址:http://www.cnblogs.com/Penn000/p/7554701.html