답안 #531988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531988 2022-03-02T02:56:55 Z fhvirus Examination (JOI19_examination) C++17
100 / 100
344 ms 14036 KB
// Knapsack DP is harder than FFT.
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll; typedef pair<int, int> pii;
#define pb emplace_back
#define AI(x) begin(x),end(x)
#define ff first
#define ss second
#ifdef OWO
#define debug(args...) LKJ("\033[1;32m[ " + string(#args) + " ]\033[0m", args)
template <class I> void LKJ(I&&x) { cerr << x << endl; }
template <class I, class...T> void LKJ(I&&x, T&&...t) { cerr << x << ", "; LKJ(t...); }
template <class I> void OI(I a, I b) { while (a != b) cerr << *a << " \n"[(a = next(a)) == b]; }
#else
#define debug(...) 0
#define OI(...) 0
#endif

struct Lisan: vector<int> {
	void done() { sort(AI()); erase(unique(AI()), end()); }
	int operator () (const int& v) const { return lower_bound(AI(), v) - begin(); }
};
struct BIT {
	int n; vector<int> val;
	BIT (int _n): n(_n), val(_n + 1, 0) {}
	void modify(int p, int v) {
		for (; p > 0; p -= p & -p)
			val[p] += v;
	}
	int query(int p) {
		int r = 0;
		for (; p <= n; p += p & -p)
			r += val[p];
		return r;
	}
};
struct OBJ {
	int x, y, z, t;
	OBJ() = default;
	OBJ(int _x, int _y, int _z, int _t):
		x(_x), y(_y), z(_z), t(_t) {}
};
bool cmpX(const OBJ& a, const OBJ& b)
{ return a.x < b.x; }
bool cmpZ(const OBJ& a, const OBJ& b) {
	if (a.z != b.z) return a.z < b.z;
	return (a.t != 0) > (b.t != 0);
}

void solve(int lb, int rb, vector<OBJ>& objs, BIT& bit, vector<int>& ans) {
	if (lb + 1 >= rb) return;
	int mid = (lb + rb) / 2;
	solve(lb, mid, objs, bit, ans);
	solve(mid, rb, objs, bit, ans);

	int lp = mid - 1, rp = rb - 1;
	for (; lp >= lb; --lp) {
		while (rp >= mid and objs[rp].x >= objs[lp].x) {
			if (objs[rp].t == 0)
				bit.modify(objs[rp].y + 1, 1);
			--rp;
		}
		ans[objs[lp].t] += bit.query(objs[lp].y + 1);
	}
	for (++rp; rp < rb; ++rp)
		if (objs[rp].t == 0)
			bit.modify(objs[rp].y + 1, -1);
	inplace_merge(begin(objs) + lb, begin(objs) + mid, begin(objs) + rb, cmpX);
}

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

	int N, Q; cin >> N >> Q;

	Lisan lisanX, lisanY;
	vector<OBJ> objs;
	for (int S, T, i = 0; i < N; ++i) {
		cin >> S >> T;
		objs.pb(S, T, S + T, 0);
		lisanX.pb(S);
		lisanY.pb(T);
	}
	for (int X, Y, Z, i = 1; i <= Q; ++i) {
		cin >> X >> Y >> Z;
		objs.pb(X, Y, Z, i);
		lisanX.pb(X);
		lisanY.pb(Y);
	}

	lisanX.done();
	lisanY.done();
	for (auto &[x, y, z, t]: objs) {
		x = lisanX(x);
		y = lisanY(y);
	}

	sort(AI(objs), cmpZ);

	for (auto &[x, y, z, t]: objs)
		debug(x, y, z, t);

	BIT bit(lisanY.size());
	vector<int> ans(Q + 1, 0);
	solve(0, objs.size(), objs, bit, ans);

	for (int i = 1; i <= Q; ++i)
		cout << ans[i] << '\n';

	return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:15:20: warning: statement has no effect [-Wunused-value]
   15 | #define debug(...) 0
      |                    ^
examination.cpp:101:3: note: in expansion of macro 'debug'
  101 |   debug(x, y, z, t);
      |   ^~~~~
examination.cpp:100:13: warning: unused structured binding declaration [-Wunused-variable]
  100 |  for (auto &[x, y, z, t]: objs)
      |             ^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 224 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 7 ms 708 KB Output is correct
8 Correct 8 ms 716 KB Output is correct
9 Correct 8 ms 708 KB Output is correct
10 Correct 6 ms 652 KB Output is correct
11 Correct 5 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 9 ms 716 KB Output is correct
14 Correct 6 ms 664 KB Output is correct
15 Correct 6 ms 716 KB Output is correct
16 Correct 5 ms 612 KB Output is correct
17 Correct 5 ms 704 KB Output is correct
18 Correct 3 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 11124 KB Output is correct
2 Correct 271 ms 11388 KB Output is correct
3 Correct 265 ms 11168 KB Output is correct
4 Correct 174 ms 10004 KB Output is correct
5 Correct 213 ms 10384 KB Output is correct
6 Correct 115 ms 9280 KB Output is correct
7 Correct 296 ms 11056 KB Output is correct
8 Correct 269 ms 10664 KB Output is correct
9 Correct 274 ms 10572 KB Output is correct
10 Correct 202 ms 10368 KB Output is correct
11 Correct 157 ms 10004 KB Output is correct
12 Correct 123 ms 9224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 11124 KB Output is correct
2 Correct 271 ms 11388 KB Output is correct
3 Correct 265 ms 11168 KB Output is correct
4 Correct 174 ms 10004 KB Output is correct
5 Correct 213 ms 10384 KB Output is correct
6 Correct 115 ms 9280 KB Output is correct
7 Correct 296 ms 11056 KB Output is correct
8 Correct 269 ms 10664 KB Output is correct
9 Correct 274 ms 10572 KB Output is correct
10 Correct 202 ms 10368 KB Output is correct
11 Correct 157 ms 10004 KB Output is correct
12 Correct 123 ms 9224 KB Output is correct
13 Correct 301 ms 11556 KB Output is correct
14 Correct 292 ms 11544 KB Output is correct
15 Correct 292 ms 11160 KB Output is correct
16 Correct 205 ms 10400 KB Output is correct
17 Correct 280 ms 10784 KB Output is correct
18 Correct 147 ms 9284 KB Output is correct
19 Correct 319 ms 11592 KB Output is correct
20 Correct 312 ms 11552 KB Output is correct
21 Correct 313 ms 11548 KB Output is correct
22 Correct 196 ms 10320 KB Output is correct
23 Correct 159 ms 9988 KB Output is correct
24 Correct 105 ms 9228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 224 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 7 ms 708 KB Output is correct
8 Correct 8 ms 716 KB Output is correct
9 Correct 8 ms 708 KB Output is correct
10 Correct 6 ms 652 KB Output is correct
11 Correct 5 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 9 ms 716 KB Output is correct
14 Correct 6 ms 664 KB Output is correct
15 Correct 6 ms 716 KB Output is correct
16 Correct 5 ms 612 KB Output is correct
17 Correct 5 ms 704 KB Output is correct
18 Correct 3 ms 588 KB Output is correct
19 Correct 262 ms 11124 KB Output is correct
20 Correct 271 ms 11388 KB Output is correct
21 Correct 265 ms 11168 KB Output is correct
22 Correct 174 ms 10004 KB Output is correct
23 Correct 213 ms 10384 KB Output is correct
24 Correct 115 ms 9280 KB Output is correct
25 Correct 296 ms 11056 KB Output is correct
26 Correct 269 ms 10664 KB Output is correct
27 Correct 274 ms 10572 KB Output is correct
28 Correct 202 ms 10368 KB Output is correct
29 Correct 157 ms 10004 KB Output is correct
30 Correct 123 ms 9224 KB Output is correct
31 Correct 301 ms 11556 KB Output is correct
32 Correct 292 ms 11544 KB Output is correct
33 Correct 292 ms 11160 KB Output is correct
34 Correct 205 ms 10400 KB Output is correct
35 Correct 280 ms 10784 KB Output is correct
36 Correct 147 ms 9284 KB Output is correct
37 Correct 319 ms 11592 KB Output is correct
38 Correct 312 ms 11552 KB Output is correct
39 Correct 313 ms 11548 KB Output is correct
40 Correct 196 ms 10320 KB Output is correct
41 Correct 159 ms 9988 KB Output is correct
42 Correct 105 ms 9228 KB Output is correct
43 Correct 344 ms 14036 KB Output is correct
44 Correct 315 ms 13884 KB Output is correct
45 Correct 300 ms 13880 KB Output is correct
46 Correct 208 ms 11544 KB Output is correct
47 Correct 235 ms 12356 KB Output is correct
48 Correct 120 ms 9368 KB Output is correct
49 Correct 293 ms 13700 KB Output is correct
50 Correct 299 ms 13780 KB Output is correct
51 Correct 314 ms 13612 KB Output is correct
52 Correct 205 ms 12308 KB Output is correct
53 Correct 179 ms 10888 KB Output is correct