数据范围求问
查看原帖
数据范围求问
1038334
wth2026楼主2025/1/20 20:57

此题的数据范围不是 2500250010410^4 吗? 为什么代码

#include <bits/stdc++.h>

#define endl '\n'
#define int long long
#define inf 0x3f3f3f3f
#define lnf 0x3f3f3f3f3f3f3f3f

#pragma GCC optimize (1)
#pragma GCC optimize (2)
#pragma GCC optimize (3)
#pragma GCC optimize (4)
#pragma GCC optimize (5)
#pragma GCC optimize ("Os")
#pragma GCC optimize ("Ofast")

using namespace std;

namespace WTH {
	const int N = 2500 + 5, M = 1e4 + 5;
	
	int n, m;
	int p[N], q[N];
	int cntp, _Ansp[N], cntq, _Ansq[N];
	
	void Main () {
		cin >> n >> m;
		
		for (register int i = 1; i <= n; ++ i) {
			cin >> p[i];
		}
		
		for (register int i = 1; i <= m; ++ i) {
			cin >> q[i];
		}
		
		for (register int i = 1; i <= n; ++ i) {
			if (i ^ p[i]) {
				for (register int j = i + 1; j <= n; ++ j) {
					if (! (i ^ p[j])) {
						_Ansp[++ cntp] = i;
						_Ansp[++ cntp] = j - i;
						_Ansp[++ cntp] = n - j + 1;
						p[i] ^= p[j] ^= p[i] ^= p[j];
						break ;
					}
				}
			}
		}
		
		for (register int i = 1; i <= m; ++ i) {
			if (i ^ q[i]) {
				for (register int j = i + 1; j <= m; ++ j) {
					if (! (i ^ q[j])) {
						_Ansq[++ cntq] = i;
						_Ansq[++ cntq] = j - i;
						_Ansq[++ cntq] = m - j + 1;
						q[i] ^= q[j] ^= q[i] ^= q[j];
						break ;
					}
				}
			}
		}
		
		if ((cntp & 1) ^ (cntq & 1)) {
			if (n & 1) {
				for (register int i = 1; i <= n; ++ i) {
					_Ansp[++ cntp] = 1;
				}
			} else if (m & 1) {
				for (register int i = 1; i <= m; ++ i) {
					_Ansq[++ cntq] = 1;
				}
			} else {
				cout << "-1" << endl;
				return ;
			}
		}
		
		while (cntp < cntq) {
			_Ansp[++ cntp] = 1;
			_Ansp[++ cntp] = n;
		}
		
		while (cntq < cntp) {
			_Ansq[++ cntq] = 1;
			_Ansq[++ cntq] = m;
		}
		
		cout << cntp << endl;
		
		for (register int i = 1; i <= cntp; ++ i) {
			cout << _Ansp[i] << ' ' << _Ansq[i] << endl;
		}
	}
}

signed main () {
	ios :: sync_with_stdio (false);
	cin.tie (0);
	cout.tie (0);

	int T = 1;
	//cin >> T;

	while (T --) {
		WTH :: Main ();
	}

	return 0;
}

过不了,但是

#include <bits/stdc++.h>

#define endl '\n'
#define int long long
#define inf 0x3f3f3f3f
#define lnf 0x3f3f3f3f3f3f3f3f

#pragma GCC optimize (1)
#pragma GCC optimize (2)
#pragma GCC optimize (3)
#pragma GCC optimize (4)
#pragma GCC optimize (5)
#pragma GCC optimize ("Os")
#pragma GCC optimize ("Ofast")

using namespace std;

namespace WTH {
	const int N = 25000 + 5, M = 1e5 + 5;
	
	int n, m;
	int p[N], q[N];
	int cntp, _Ansp[N], cntq, _Ansq[N];
	
	void Main () {
		cin >> n >> m;
		
		for (register int i = 1; i <= n; ++ i) {
			cin >> p[i];
		}
		
		for (register int i = 1; i <= m; ++ i) {
			cin >> q[i];
		}
		
		for (register int i = 1; i <= n; ++ i) {
			if (i ^ p[i]) {
				for (register int j = i + 1; j <= n; ++ j) {
					if (! (i ^ p[j])) {
						_Ansp[++ cntp] = i;
						_Ansp[++ cntp] = j - i;
						_Ansp[++ cntp] = n - j + 1;
						p[i] ^= p[j] ^= p[i] ^= p[j];
						break ;
					}
				}
			}
		}
		
		for (register int i = 1; i <= m; ++ i) {
			if (i ^ q[i]) {
				for (register int j = i + 1; j <= m; ++ j) {
					if (! (i ^ q[j])) {
						_Ansq[++ cntq] = i;
						_Ansq[++ cntq] = j - i;
						_Ansq[++ cntq] = m - j + 1;
						q[i] ^= q[j] ^= q[i] ^= q[j];
						break ;
					}
				}
			}
		}
		
		if ((cntp & 1) ^ (cntq & 1)) {
			if (n & 1) {
				for (register int i = 1; i <= n; ++ i) {
					_Ansp[++ cntp] = 1;
				}
			} else if (m & 1) {
				for (register int i = 1; i <= m; ++ i) {
					_Ansq[++ cntq] = 1;
				}
			} else {
				cout << "-1" << endl;
				return ;
			}
		}
		
		while (cntp < cntq) {
			_Ansp[++ cntp] = 1;
			_Ansp[++ cntp] = n;
		}
		
		while (cntq < cntp) {
			_Ansq[++ cntq] = 1;
			_Ansq[++ cntq] = m;
		}
		
		cout << cntp << endl;
		
		for (register int i = 1; i <= cntp; ++ i) {
			cout << _Ansp[i] << ' ' << _Ansq[i] << endl;
		}
	}
}

signed main () {
	ios :: sync_with_stdio (false);
	cin.tie (0);
	cout.tie (0);

	int T = 1;
	//cin >> T;

	while (T --) {
		WTH :: Main ();
	}

	return 0;
}

过了?

2025/1/20 20:57
加载中...