欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1841B.Keep it Beautiful
Keep it Beautiful
The array is called beautiful if it is possible to remove several (maybe zero) elements from the beginning of the array and insert all these elements to the back of the array in the same order in such a way that the resulting array is sorted in non-descending order.
In other words, the array is beautiful if there exists an integer such that the array $[a_{i+1}, a_{i+2}, \dots, a_{k-1}, a_k, a_1, a_2, \dots, a_i]$ is sorted in non-descending order.
For example:
- is beautiful: we can remove four first elements and insert them to the back in the same order, and we get the array , which is sorted in non-descending order;
- is beautiful: we can remove zero first elements and insert them to the back, and we get the array , which is sorted in non-descending order;
- is not beautiful.
Note that any array consisting of zero elements or one element is beautiful.
You are given an array , which is initially empty. You have to process queries to it. During the -th query, you will be given one integer , and you have to do the following:
- if you can append the integer to the back of the array so that the array stays beautiful, you have to append it;
- otherwise, do nothing.
After each query, report whether you appended the given integer , or not.
Input
The first line contains one integer () — the number of test cases.
Each test case consists of two lines. The first line contains one integer () — the number of queries. The second line contains integers ().
Additional constraint on the input: the sum of over all test cases does not exceed ).
Output
For each test case, print one string consisting of exactly characters. The -th character of the string should be 1 if you appended the integer during the -th query; otherwise, it should be 0.
Note
Consider the first test case of the example. Initially, the array is .
- trying to append an integer . The array is beautiful, so we append ;
- trying to append an integer . The array is beautiful, so we append ;
- trying to append an integer . The array is beautiful, so we append ;
- trying to append an integer . The array is beautiful, so we append ;
- trying to append an integer . The array is beautiful, so we append ;
- trying to append an integer . The array is not beautiful, so we don't append ;
- trying to append an integer . The array is not beautiful, so we don't append ;
- trying to append an integer . The array is beautiful, so we append ;
- trying to append an integer . The array is not beautiful, so we don't append .
Samples
3
9
3 7 7 9 2 4 6 3 4
5
1 1 1 1 1
5
3 2 1 2 3
111110010
11111
11011
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |