QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#518925 | #7757. Palm Island | QFshengxiu# | TL | 1ms | 5696kb | C++20 | 2.7kb | 2024-08-14 14:17:01 | 2024-08-14 14:17:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define lowbit(x) (x & (-x))
#define all(x) x.begin(), x.end()
#define inf 0x3f3f3f3f3f3f3f3f
#define int long long
#define pai 3.14
#define QF ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
// #define width cout << ""
using ll = long long;
using PII = pair<int, int>;
using LD = long double;
mt19937_64 rnd(chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count());
constexpr int N = 3e5 + 10;
map<int, int> mp;
int a[N], b[N];
void printer(list<int> v)
{
cout << endl;
for (auto x : v)
{
cout << x << " ";
}
cout << endl;
}
bool check(list<int> l)
{
int cnt = 1;
for (auto x : l)
{
if (x != b[cnt])
return false;
++cnt;
}
return true;
}
void solve(int caseT)
{
int n;
cin >> n;
list<int> l;
set<PII> vis;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
l.push_back(a[i]);
}
for (int i = 1; i <= n; i++)
{
cin >> b[i];
mp[b[i]] = i;
}
int cnt = 0;
while (true)
{
list<int>::iterator it = l.begin();
list<int>::iterator it2 = ++l.begin();
list<int>::iterator it3 = --l.end();
if (cnt >= n)
break;
if (mp[*(it2)] < mp[*(it)])
{
vector<int> v;
while (it2 != l.end())
{
// cnt++;
v.push_back(*it2);
auto it4 = it2++;
// cout << "这是" << (*it2) << endl;
if (it2 == l.end() || mp[*(it4)] != mp[*(it2)] - 1)
{
// cout << "退出了" << endl;
break;
}
}
bool flag = false;
if (it2 == l.end())
flag = true;
auto pos = ++l.begin();
for (auto x : v)
{
cout << 2;
l.push_back(x);
pos = l.erase(pos);
}
cnt = 0;
if (flag)
{
cout << 1;
return;
}
}
else
{
cnt++;
l.push_back(*it);
l.erase(it);
cout << 1;
}
// printer(l);
}
}
signed main()
{
QF;
int T = 1;
cin >> T;
for (int i = 1; i <= T; i++)
{
solve(i);
cout << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5696kb
input:
2 3 1 2 3 2 3 1 4 1 2 3 4 2 1 3 4
output:
221 2112221
result:
ok Correct. (2 test cases)
Test #2:
score: -100
Time Limit Exceeded
input:
200 3 3 1 2 2 3 1 4 2 4 1 3 2 1 4 3 4 1 4 2 3 2 1 3 4 5 4 3 2 1 5 2 4 5 3 1 5 2 1 5 4 3 5 2 4 1 3 4 4 3 1 2 1 2 4 3 3 1 2 3 3 1 2 4 1 4 2 3 2 1 4 3 4 1 3 2 4 1 4 3 2 3 3 2 1 1 3 2 3 2 3 1 1 3 2 4 1 4 3 2 3 1 2 4 3 1 2 3 1 3 2 3 3 2 1 2 3 1 5 5 1 3 2 4 2 4 5 1 3 4 4 3 1 2 1 4 3 2 4 1 3 4 2 2 4 3 1 3 ...
output:
1221 1212221 12222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...