|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 7, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stdout", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "1\n", |
| 13 | + "6\n", |
| 14 | + "16 17 4 3 5 2\n", |
| 15 | + "17 5 2\n" |
| 16 | + ] |
| 17 | + } |
| 18 | + ], |
| 19 | + "source": [ |
| 20 | + "for _ in range(int(input())):\n", |
| 21 | + " n=int(input())\n", |
| 22 | + " a=list(map(int, input().split()))\n", |
| 23 | + " q=[a[-1]]\n", |
| 24 | + " for i in range(n-2,-1,-1):\n", |
| 25 | + " if a[i]>=q[-1]:\n", |
| 26 | + " q.append(a[i])\n", |
| 27 | + " print(*(q[::-1]) )" |
| 28 | + ] |
| 29 | + }, |
| 30 | + { |
| 31 | + "cell_type": "code", |
| 32 | + "execution_count": 8, |
| 33 | + "metadata": {}, |
| 34 | + "outputs": [ |
| 35 | + { |
| 36 | + "data": { |
| 37 | + "text/plain": [ |
| 38 | + "[2, 5, 17]" |
| 39 | + ] |
| 40 | + }, |
| 41 | + "execution_count": 8, |
| 42 | + "metadata": {}, |
| 43 | + "output_type": "execute_result" |
| 44 | + } |
| 45 | + ], |
| 46 | + "source": [ |
| 47 | + "q" |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "cell_type": "code", |
| 52 | + "execution_count": 6, |
| 53 | + "metadata": {}, |
| 54 | + "outputs": [ |
| 55 | + { |
| 56 | + "name": "stdout", |
| 57 | + "output_type": "stream", |
| 58 | + "text": [ |
| 59 | + "17 5 2\n" |
| 60 | + ] |
| 61 | + } |
| 62 | + ], |
| 63 | + "source": [ |
| 64 | + "print(*(q[::-1]))" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "code", |
| 69 | + "execution_count": 8, |
| 70 | + "metadata": {}, |
| 71 | + "outputs": [ |
| 72 | + { |
| 73 | + "name": "stdout", |
| 74 | + "output_type": "stream", |
| 75 | + "text": [ |
| 76 | + "2 5 17\n" |
| 77 | + ] |
| 78 | + } |
| 79 | + ], |
| 80 | + "source": [ |
| 81 | + "print(*q)" |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + "cell_type": "code", |
| 86 | + "execution_count": 4, |
| 87 | + "metadata": {}, |
| 88 | + "outputs": [], |
| 89 | + "source": [ |
| 90 | + "q.reverse()" |
| 91 | + ] |
| 92 | + }, |
| 93 | + { |
| 94 | + "cell_type": "code", |
| 95 | + "execution_count": 6, |
| 96 | + "metadata": {}, |
| 97 | + "outputs": [ |
| 98 | + { |
| 99 | + "data": { |
| 100 | + "text/plain": [ |
| 101 | + "2" |
| 102 | + ] |
| 103 | + }, |
| 104 | + "execution_count": 6, |
| 105 | + "metadata": {}, |
| 106 | + "output_type": "execute_result" |
| 107 | + } |
| 108 | + ], |
| 109 | + "source": [ |
| 110 | + "q[-1]" |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "cell_type": "code", |
| 115 | + "execution_count": 9, |
| 116 | + "metadata": {}, |
| 117 | + "outputs": [ |
| 118 | + { |
| 119 | + "name": "stdout", |
| 120 | + "output_type": "stream", |
| 121 | + "text": [ |
| 122 | + "1\n", |
| 123 | + "6\n", |
| 124 | + "16 17 4 3 5 2\n", |
| 125 | + "2 5 17\n", |
| 126 | + "\n" |
| 127 | + ] |
| 128 | + } |
| 129 | + ], |
| 130 | + "source": [ |
| 131 | + "for _ in range(int(input())):\n", |
| 132 | + " n=int(input())\n", |
| 133 | + " a=list(map(int,input().split()))\n", |
| 134 | + "# c=a.copy()\n", |
| 135 | + "# for i in range(len(a)-1):\n", |
| 136 | + "# for j in range(i+1,len(a)):\n", |
| 137 | + "# if a[i]<a[j]:\n", |
| 138 | + "# c.remove(a[i])\n", |
| 139 | + "# break\n", |
| 140 | + " c=[a[-1]]\n", |
| 141 | + " for i in range(len(a)-2,-1,-1):\n", |
| 142 | + " if a[i]>= c[-1]:\n", |
| 143 | + " c.append(a[i])\n", |
| 144 | + "# for i in c:\n", |
| 145 | + "# print(i,end=' ')\n", |
| 146 | + " print(*c)\n", |
| 147 | + " print()" |
| 148 | + ] |
| 149 | + }, |
| 150 | + { |
| 151 | + "cell_type": "code", |
| 152 | + "execution_count": 1, |
| 153 | + "metadata": {}, |
| 154 | + "outputs": [ |
| 155 | + { |
| 156 | + "data": { |
| 157 | + "text/plain": [ |
| 158 | + "3" |
| 159 | + ] |
| 160 | + }, |
| 161 | + "execution_count": 1, |
| 162 | + "metadata": {}, |
| 163 | + "output_type": "execute_result" |
| 164 | + } |
| 165 | + ], |
| 166 | + "source": [ |
| 167 | + "7//2" |
| 168 | + ] |
| 169 | + }, |
| 170 | + { |
| 171 | + "cell_type": "code", |
| 172 | + "execution_count": null, |
| 173 | + "metadata": {}, |
| 174 | + "outputs": [], |
| 175 | + "source": [ |
| 176 | + "if(7//2==0)" |
| 177 | + ] |
| 178 | + } |
| 179 | + ], |
| 180 | + "metadata": { |
| 181 | + "kernelspec": { |
| 182 | + "display_name": "Python 3", |
| 183 | + "language": "python", |
| 184 | + "name": "python3" |
| 185 | + }, |
| 186 | + "language_info": { |
| 187 | + "codemirror_mode": { |
| 188 | + "name": "ipython", |
| 189 | + "version": 3 |
| 190 | + }, |
| 191 | + "file_extension": ".py", |
| 192 | + "mimetype": "text/x-python", |
| 193 | + "name": "python", |
| 194 | + "nbconvert_exporter": "python", |
| 195 | + "pygments_lexer": "ipython3", |
| 196 | + "version": "3.7.5" |
| 197 | + } |
| 198 | + }, |
| 199 | + "nbformat": 4, |
| 200 | + "nbformat_minor": 2 |
| 201 | +} |
0 commit comments