QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768357#8831. Chemistry ClassczhTL 0ms0kbC++172.2kb2024-11-21 09:40:202024-11-21 09:40:20

Judging History

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

  • [2024-11-21 09:40:20]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-21 09:40:20]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef __int128 LLL;
typedef std::pair<int, int> pii;
typedef std::pair<LL, int> pli;
typedef std::pair<LL, LL> pll;
#define fi first
#define se second
#define MP std::make_pair
char buf[1<<20],*p1,*p2;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin), p1 == p2) ? 0 : *p1++)
LL read()
{
	LL s = 0; int f = 1;
	char c = getchar();
	while (!(c >= '0' && c <= '9'))
		f ^= (c == '-'), c = getchar();
	while (c >= '0' && c <= '9')
		s = s * 10 + (c ^ 48), c = getchar();
	return f ? s : -s;
} 
template<typename T> void write(T x, char end = '\n')
{
	if (x < 0) putchar('-'), x = -x;
	static int d[100], cur = 0;
	do{ d[++cur] = x % 10; } while (x /= 10);
	while (cur) putchar('0' + d[cur--]);
	putchar(end);
}
const int MAXN = 1000006, inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 998244353;
auto fplus = [](int x, int y){ return x + y >= MOD ? x + y - MOD : x + y; };
auto fminus = [](int x, int y){ return x >= y ? x - y : x + MOD - y; };
auto Fplus = [](int &x, int y){ return x = fplus(x, y); };
auto Fminus = [](int &x, int y){ return x = fminus(x, y); };
template<typename T> T& Fmax(T& x, T y){ return x = x < y ? y : x; };
template<typename T> T& Fmin(T& x, T y){ return x = x < y ? x : y; };
int fpow(int x, int y = MOD - 2)
{
	int res = 1;
	for (; y; y >>= 1, x = (LL)x * x % MOD)
		if (y & 1) res = (LL)res * x % MOD;
	return res;
}
int T, n;
LL a[MAXN], b[MAXN], A, B;
int mian()
{
	std::sort(a + 1, a + n * 2 + 1);
	int ans = 0;
	for (int i = 1; i <= n * 2; i += 2)
		if (a[i + 1] - a[i] > A) return -1;
	for (int i = 1, j; i <= n * 2; )
	{
		if (a[i + 1] - a[i] <= B){ ++ans, i += 2; continue; }
		for (j = i + 1; j + 2 <= n * 2 && a[j + 2] - a[i] <= A && a[j + 1] - a[j] <= B; j += 2)
			ans++;
		i = j + 1;
	}
	return ans;
}
int main()
{

	T = read(), n = read();
	for (int i = 1; i <= n * 2; i++) b[i] = read();
	while (T--)
	{
		int K = read();
		for (int _ = 1, x; _ <= K; _++)
			x = read(), b[x] = read();
		A = read(), B = read();
		memcpy(a + 1, b + 1, (n * 2) << 3);
		write(mian());
	}
	
	return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

4
1 2 1
42 69
2 3 1
1 2 3 4
2 5 1
6 1 3 4
5 19 1
1 7 8 9 10 11 12 13 14 20

output:


result: