QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#221171 | #6838. Assumption is All You Need | realIyxiang# | WA | 0ms | 5644kb | C++14 | 1.5kb | 2023-10-21 10:31:05 | 2023-10-21 10:31:05 |
Judging History
answer
#include <bits/stdc++.h>
#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)
using namespace std;
using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;
template < typename T > T read() {
T x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)) f |= ch == '-', ch = getchar();
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }
const int N = 1e6 + 10;
int n, a[N], b[N];
int get(int *a, int x) {
rep(i, 1, n) if(a[i] == x) return i;
return -1;
}
void solve() {
n = in; rep(i, 1, n) a[i] = in; rep(i, 1, n) b[i] = in;
veg ans;
rep(i, 1, n) {
int ta = get(a, i), tb = get(b, i);
if(ta < tb) return puts("-1"), void();
vec pot;
rep(j, tb, ta - 1) {
if(a[j] > i) {
if(!pot.size() || a[j] < a[pot.back()]) pot.eb(j);
}
}
reverse(pot.begin(), pot.end());
for(auto v : pot) swap(a[ta], a[v]), ans.eb(ta, v), ta = v;
assert(a[tb] == i);
}
printf("%lu\n", ans.size());
for(auto v : ans) printf("%d %d\n", v.fi, v.se);
}
int main() {
#ifdef YJR_2333_TEST
freopen("1.in", "r", stdin);
#endif
for(int T = in; T; T--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5644kb
input:
3 2 1 2 2 1 4 4 1 2 3 1 3 2 4 8 8 7 6 5 4 3 2 1 1 8 7 6 5 4 3 2
output:
-1 2 2 1 4 2 7 8 7 7 6 6 5 5 4 4 3 3 2 2 1
result:
wrong answer 1-th operation (2, 1) not valid: (x < y) == false