QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527830#8831. Chemistry ClassStayAloneWA 53ms9984kbC++142.2kb2024-08-22 20:02:162024-08-22 20:02:16

Judging History

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

  • [2024-08-22 20:02:16]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:9984kb
  • [2024-08-22 20:02:16]
  • 提交

answer

#include <bits/stdc++.h>
#define rep1(i, l, r) for (int i = l; i <= int(r); ++i)
#define rep2(i, l, r) for (int i = l; i >= int(r); --i)
#define rer(i, l, r, a) rep1(i, l, r) read(a[i])
#define ptc putchar
#define il inline
#define eb emplace_back
#define ef emplace_front
#define mp make_pair
#define fst first
#define snd second
#define sqr(x) ((x) * (x))
#define ls(x) x << 1
#define rs(x) x << 1 | 1
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// typedef __int128 bll;
// typedef unsigned __int128 ubll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 4e5 + 10;
const int LOGN = log2(MAXN) + 1, inf = ~0U >> 2, INF = ~0U >> 1;
const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
namespace stupid_lrc {
	template <typename T> il bool read(T &x) {
		x = 0; bool f = false; char ch;
		while (!isdigit(ch = getchar())) {
			f ^= !(ch ^ '-');
			if (ch == EOF) return false;
		}
		while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch & 15), ch = getchar();
		if (f) x = ~x + 1; return true;
	}
	il ll read() {ll x; read(x); return x;}

	template <typename T> il bool read(pair <T, T> &x) {return read(x.fst) && read(x.snd);}
	
	template <typename T> il void gmin(T &x, T y) {x = x < y ? x : y;}
	
	template <typename T> il void gmax(T &x, T y) {x = x > y ? x : y;}

	template <typename T, typename ...L>
	il bool read(T &x, L &...y) {return read(x) && read(y...);}

	template <typename T> il T lowbit(const T &x) {return x & -x;}
}
using namespace stupid_lrc;
int n, sum[MAXN], f[MAXN]; ll a[MAXN], A, B;

il void solve() {
	read(n, A, B); n <<= 1; rer(i, 1, n, a);
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; i += 2) if (a[i + 1] - a[i] > A) return puts("-1"), void();
	for (int i = 2; i <= n; ++i) sum[i] = sum[i - 2] + (a[i] - a[i - 1] <= B);
	deque <int> q; q.eb(0);
	for (int i = 2; i <= n; i += 2) {
		while (q.size() && a[i] - a[q.front() + 1] > A) q.pop_front();
		if (q.size()) f[i] = f[q.front()] - sum[q.front()] + sum[i - 1];
		gmax(f[i], f[i - 2] + (a[i] - a[i - 1] <= B));
		while (q.size() && f[q.back()] - sum[q.back()] < f[i] - sum[i]) q.pop_back();
		q.eb(i);
	} printf("%d\n", f[n]);
}

int main() {
	for (int T = read(); T--; ) solve();
	return 0;
}

詳細信息

Test #1:

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

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:

-1
2
1
4

result:

ok 4 number(s): "-1 2 1 4"

Test #2:

score: 0
Accepted
time: 45ms
memory: 9920kb

input:

1
199996 67013419502794 1
403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 53ms
memory: 9984kb

input:

1
199998 38987266278826 1
974183459404323858 517476981059568123 730207399881008603 532509909948600146 89227878552241675 16653300445469756 791674368913652595 92177901403222015 980536748304824579 581564387828767376 471919726893404451 759601909683722004 632340812998214017 818440789777778368 18845836031...

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 53ms
memory: 9916kb

input:

1
199996 54170919220045 1
968843690955781467 596307347951820347 406785475849275444 383666938223357986 725160735782817082 132577412512120631 891899794864087098 779434145671998619 932681297277907326 208765550447928461 385078857912267975 669360937040314510 917331948890514855 505938744714587815 47145437...

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: -100
Wrong Answer
time: 47ms
memory: 9984kb

input:

1
199998 35667463938291 8255384928693
770468016026697053 519790816750772730 110085058423772871 85144239858008037 782003096084947976 938498644167289660 693768718229582367 242186248813489674 155335549252315364 428982852761422230 890445026369869037 86401573937739054 9122788624365829 63351367715811463 1...

output:

21568176

result:

wrong answer 1st numbers differ - expected: '193326', found: '21568176'