sacgajcvs

Untitled

Oct 8th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. /*
  2. _____ _ _ _ _
  3. |_ _| |__ ___ / \ _ __ ___| |__ _ _| |
  4. | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  5. | | | | | | __// ___ \| | | \__ \ | | | |_| | |
  6. |_| |_| |_|\___/_/ \_\_| |_|___/_| |_|\__,_|_|
  7.  
  8. */
  9. #include<bits/stdc++.h>
  10. #include <ext/pb_ds/assoc_container.hpp>
  11. #include <ext/pb_ds/tree_policy.hpp>
  12. #define ll long long
  13. #define pb push_back
  14. #define ppb pop_back
  15. #define endl '\n'
  16. #define mii map<ll,ll>
  17. #define msi map<string,ll>
  18. #define mis map<ll, string>
  19. #define rep(i,a,b) for(ll i=a;i<b;i++)
  20. #define repr(i,a,b) for(ll i=b-1;i>=a;i--)
  21. #define trav(a, x) for(auto& a : x)
  22. #define pii pair<ll,ll>
  23. #define vi vector<ll>
  24. #define vii vector<pair<ll, ll>>
  25. #define vs vector<string>
  26. #define all(a) (a).begin(),(a).end()
  27. #define F first
  28. #define S second
  29. #define sz(x) (ll)x.size()
  30. #define hell 1000000007
  31. #define lbnd lower_bound
  32. #define ubnd upper_bound
  33. #define max(a,b) (a>b?a:b)
  34. #define min(a,b) (a<b?a:b)
  35.  
  36. /* For Debugging */
  37. #define DEBUG cerr<<"\n>>>I'm Here<<<\n"<<endl;
  38. #define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
  39. #define what_is(x) cerr << #x << " is " << x << endl;
  40.  
  41. std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
  42. #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
  43. #define TIME cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
  44. #define DECIMAL(n) cout << fixed ; cout << setprecision(n);
  45. #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  46. using namespace __gnu_pbds;
  47. using namespace std;
  48. #define PI 3.141592653589793
  49. #define N 100005
  50.  
  51. vi v;
  52. ll n;
  53. ll dp[105][105][105];
  54. bool fun(ll i,ll num1,ll num2) {
  55. if(i>=n) {
  56. return 1;
  57. }
  58. if(dp[i][num1][num2]!=-1) {
  59. return dp[i][num1][num2];
  60. }
  61. ll& ans = dp[i][num1][num2];
  62. ans = 0;
  63. if(v[i]>num1) {
  64. ans |= fun(i+1,v[i],num2);
  65. if(ans) {
  66. return ans;
  67. }
  68. }
  69. if(v[i]<num2) {
  70. ans |= fun(i+1,num1,v[i]);
  71. if(ans) {
  72. return ans;
  73. }
  74. }
  75. return ans;
  76. }
  77.  
  78. void ansOut(ll num) {
  79. cerr<<"NO\n";
  80. rep(i,0,n+1) {
  81. rep(j,0,101) {
  82. rep(k,0,101) {
  83. dp[i][j][k] = -1;
  84. }
  85. }
  86. }
  87. if(fun(1,v[0],101) || fun(1,0,v[0])) {
  88. cout<<0<<endl;
  89. return;
  90. }
  91. cout<<1<<endl;
  92. return;
  93.  
  94. }
  95. void ansOut(ll num,vi a,vi b) {
  96. cerr<<"YES\n";
  97. rep(i,1,sz(a)) {
  98. if(a[i]<=a[i-1]) {
  99. cout<<0<<endl;
  100. return;
  101. }
  102. }
  103. rep(i,1,sz(b)) {
  104. if(b[i]>=b[i-1]) {
  105. cout<<0<<endl;
  106. return;
  107. }
  108. }
  109. cout<<1<<endl;
  110. return;
  111. }
  112.  
  113.  
  114. void solve()
  115. {
  116. cin>>n;
  117. v.resize(n);
  118. rep(i,0,n) {
  119. cin>>v[i];
  120. }
  121. vi a,b;
  122.  
  123. auto checkA = [&] (ll num) {
  124. if(a.empty() || a.back()<num) {
  125. return 1;
  126. }
  127. return 0;
  128. };
  129.  
  130. auto checkB = [&] (ll num) {
  131. if(b.empty() || b.back()>num) {
  132. return 1;
  133. }
  134. return 0;
  135. };
  136.  
  137. rep(i,0,n-1) {
  138. if(v[i]<v[i+1]) {
  139. if(checkA(v[i])) {
  140. a.pb(v[i]);
  141. } else if(checkB(v[i])) {
  142. b.pb(v[i]);
  143. } else {
  144. ansOut(0);
  145. return;
  146. }
  147. } else if(v[i]>v[i+1]) {
  148. if(checkB(v[i])) {
  149. b.pb(v[i]);
  150. } else if(checkA(v[i])) {
  151. a.pb(v[i]);
  152. } else {
  153. ansOut(0);
  154. return;
  155. }
  156. } else {
  157. if(checkA(v[i]) && checkB(v[i])) {
  158. a.pb(v[i]);
  159. b.pb(v[i]);
  160. i++;
  161. } else {
  162. ansOut(0);
  163. return;
  164. }
  165. }
  166. }
  167. if(checkA(v[n-1])) {
  168. a.pb(v[n-1]);
  169. } else if(checkB(v[n-1])) {
  170. b.pb(v[n-1]);
  171. } else {
  172. ansOut(0);
  173. return;
  174. }
  175. ansOut(1,a,b);
  176. return;
  177. }
  178. int main()
  179. {
  180. #ifndef ONLINE_JUDGE
  181. freopen ("input.txt","r",stdin);
  182. // freopen("output.txt","w",stdout);
  183. #endif
  184. FAST
  185. int TESTS=1;
  186. cin>>TESTS;
  187. rep(i,0,TESTS)
  188. {
  189. // cout<<"Case #"<<i+1<<": ";
  190. solve();
  191. }
  192. TIME
  193. return 0;
  194. }
Advertisement
Add Comment
Please, Sign In to add comment