QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#774144#9786. Magical Bagsucup-team3564#WA 2ms9972kbC++232.5kb2024-11-23 12:03:542024-11-23 12:03:55

Judging History

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

  • [2024-11-23 12:03:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9972kb
  • [2024-11-23 12:03:54]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\33[32m[" << __LINE__ << "]\33[m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = - f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = 5e5 + 10;
int n, p[N], m, tl[N], tr[N], info[N];
vector <int> v[N], g;
bool flag[N];
void modify(int x, int y) {
	for (; x < N; x += x & - x) chkmax(info[x], y);
}
int query(int x) {
	int mx = 0;
	for (; x; x ^= x & - x) chkmax(mx, info[x]);
	return mx;
}
signed main() {
	read(n);
	F(i, 1, n) {
		p[i] = i;
		int k; read(k);
		v[i].resize(k);
		for (int& j: v[i]) read(j), g.push_back(j);
		sort(all(v[i]));
		tl[i] = v[i].front();
		tr[i] = v[i].back();
	}
	sort(all(g));
	g.resize(m = unique(all(g)) - g.begin());
	F(i, 1, n)
		for (int& j: v[i])
			j = lower_bound(all(g), j) - g.begin() + 1;
	sort(p + 1, p + n + 1, [&] (int x, int y) {
		return v[x].back() < v[y].back();
	});
	set <int> w;
	int mx = 0;
	F(i, 1, n) {
		auto it = w.lower_bound(v[p[i]].front());
		if (it != w.end()) {
			chkmin(tr[p[i]], * it);
			chkmax(tl[p[i]], mx);
		}
		chkmax(mx, v[p[i]].front());
		w.insert(v[p[i]].back());
	}
	w.clear();
	// int mn = 1e9;
	DF(i, n, 1) {
		auto it = w.lower_bound(v[p[i]].back());
		if (it != w.begin()) {
			it--;
			chkmax(tl[p[i]], * it);
			// chkmin(tr[p[i]], mn);
		}
		// chkmin(mn, v[p[i]].front());
		w.insert(v[p[i]].front());
	}
	F(i, 1, n)
		for (int j: v[i]) flag[i] |= tl[i] <= j && j <= tr[i];
	int ans = 0;
	F(i, 1, n) {
		int g = query(v[i].front()) + 1;
		chkmax(ans, g);
		modify(v[i].back(), g);
	}
	cout << n * 2 - ans;
	return 0;
}
/* why?
*/

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7760kb

input:

4
3 4 7 10
2 1 9
4 11 2 8 14
3 6 12 13

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 2ms
memory: 9932kb

input:

4
1 1
1 2
1 3
1 4

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 2ms
memory: 9972kb

input:

4
3 4 7 10
2 1 9
4 11 2 8 14
3 6 12 13

output:

7

result:

ok 1 number(s): "7"

Test #4:

score: 0
Accepted
time: 0ms
memory: 9724kb

input:

4
1 1
1 2
1 3
1 4

output:

4

result:

ok 1 number(s): "4"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 9684kb

input:

100
4 372861091 407948190 424244630 359746969
6 568180757 527358812 494745349 665803213 674832670 586694351
4 696340797 775899164 919971335 716827187
4 123145962 344250363 122030550 251739234
4 342654413 368648894 150539766 255189030
1 194505887
3 755984448 736803561 745474041
4 709314938 498953418 ...

output:

191

result:

wrong answer 1st numbers differ - expected: '177', found: '191'