QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#505999#6429. Let's Play CurlingGrunrayAC ✓92ms5192kbC++203.1kb2024-08-05 14:32:132024-08-05 14:32:14

Judging History

你现在查看的是最新测评结果

  • [2024-08-05 14:32:14]
  • 评测
  • 测评结果:AC
  • 用时:92ms
  • 内存:5192kb
  • [2024-08-05 14:32:13]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#define itn int
#define PII pair<int, int>
#define PLI pair<long long, int>
#define fep(i, a, b) for(int i = (a); i >= (b); --i)
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#include<bits/stdc++.h>
#include<unordered_map>
using ll = long long;
using ldou = long double;
using unll = unsigned long long;
using namespace std;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch)) { f = ch != '-'; ch = getchar(); }
	while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
	return f ? x : -x;
}

ll gcd(ll a, ll b) { // 最大公约数
	while (b ^= a ^= b ^= a %= b)
		;
	return a;
}
ll lcm(ll a, ll b) { // 最小公倍数
	return a / gcd(a, b) * b;
}
ll qmi(ll m, ll k, ll p) { // 快速幂
	//求 m^k mod p,时间复杂度 O(logk)。
	//m为底数,k为幂
	ll res = 1 % p, t = m;
	while (k) {
		if (k & 1) res = res * t % p;
		t = t * t % p;
		k >>= 1;
	}
	return res;
}
unll qmi(unll m, unll k, unll p) { //龟速乘
	ll res = 0, t = m;
	while (k) {
		if (k & 1) res = (res + t) % p;
		k >>= 1;
		t = (t << 1) % p;
	}
	return res;
}

////////////////////////////////////////////////////////////////////////////////


const int N = 1e5 + 50;
const int M = 2e5 + 50;
const ll INF = 0x3f3f3f3f;
const ll MODE = ll(998244353);
const double Pi = 3.1415926;
const double eps = 1e-8;
const int dx[4] = { 1,-1, 0, 0 };
const int dy[4] = { 0, 0, 1,-1 };
//priority_queue<int> p;//这是一个大根堆q
//priority_queue<int, vector<int>, greater<int> >q;//这是一个小根堆q
//priority_queue<ll, vector<ll>, greater<ll> >pq; // 小根

ll n, m;
string str;

ll a[N], b[N];
//set<ll>sa;
//set<ll>sb;

void solve() {
	
	cin >> n >> m;

	/*rep(i, 1, n) cin >> a[i];
	rep(j, 1, m) cin >> b[j];*/
	//ll x;
	rep(i, 1, n) {
		//cin >> x;
		cin >> a[i];
		//sa.insert(x);
	}
	rep(i, 1, m) {
		//cin >> x;
		//sb.insert(x);
		cin >> b[i];
	}

	//set<ll>::iterator it;
	//int pos = 1;
	/*for (it = sa.begin(); it != sa.end(); it++) {
		a[pos++] = (*it);
	}
	n = pos - 1;*/
	sort(a + 1, a + n + 1);
	sort(b + 1, b + m + 1);
	/*pos = 1;
	for (it = sb.begin(); it != sb.end(); it++) {
		b[pos++] = (*it);
	}
	m = pos;*/
	m = ll(unique(b + 1, b + m + 1) - b) - 1;
	/*cout << "  a   ";
	for (int i = 1; i <= n; i++)cout << a[i] << ' ';
	cout << '\n';
	cout << "  b   ";
	for (int i = 1; i <= m; i++)cout << b[i] << ' ';
	cout << '\n';*/

	b[0] = 0;
	b[++m] = INF;

	ll res = 0;
	ll l, r;
	ll mid;
	rep(i, 1, m) {
		l = ll(upper_bound(a + 1, a + n + 1, b[i - 1]) - a);
		r = ll(lower_bound(a + 1, a + n + 1, b[i]) - a) - 1;

		mid = r - l + 1;

		res = max(res, mid);
	}
	//cout << "******   ";
	if (!res) cout << "Impossible\n";
	else cout << res << '\n';

	/*sa.clear();
	sb.clear();*/
}

signed main() {
	std::ios::sync_with_stdio(false); std::cin.tie(0), std::cout.tie(0);
	/*freopen("out.txt", "r", stdin);
	freopen("wrt.txt", "w", stdout);*/
	int TTT = 1; cin >> TTT;
	while (TTT--) {
		solve();
	}
	/*while (cin >> n >> m) {
		solve();
	}*/

	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3724kb

input:

3
2 2
2 3
1 4
6 5
2 5 3 7 1 7
3 4 3 1 10
1 1
7
7

output:

2
3
Impossible

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 92ms
memory: 5192kb

input:

5553
12 19
8 8 11 18 12 9 15 38 6 32 30 30
17 28 33 2 37 20 11 38 36 18 18 30 20 33 13 31 33 37 8
12 6
7 12 14 2 19 2 17 7 4 20 1 13
7 18 23 22 1 16
8 7
5 2 4 2 4 5 8 12
13 16 6 6 5 16 11
5 7
5 13 3 8 3
11 6 9 11 13 8 11
17 19
944782509 244117333 140979583 661724696 617847780 321687699 418677763 725...

output:

1
3
4
3
4
8
11
4
2
4
5
2
4
1
11
3
2
4
2
3
5
4
1
4
9
1
3
9
2
2
1
4
5
12
2
3
4
5
4
4
11
4
5
7
3
5
4
4
5
1
3
2
4
5
5
2
6
8
3
4
3
2
2
7
2
5
3
4
1
2
5
3
6
5
1
4
1
1
2
3
4
7
9
1
2
3
16
5
5
4
3
4
3
4
3
1
2
3
3
2
2
2
5
2
7
1
1
2
4
7
2
3
7
12
1
1
1
5
3
4
1
3
2
4
3
2
3
5
4
8
10
6
2
6
2
1
6
1
3
6
2
1
9
8
1
2
3...

result:

ok 5553 lines