답안 #929438

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
929438 2024-02-18T05:36:02 Z horiseun Examination (JOI19_examination) C++17
100 / 100
327 ms 17052 KB
#include <iostream>
#include <vector>
#include <tuple>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <array>
#include <random>
#include <climits>
#include <cassert>
#include <algorithm>
using namespace std;

template<typename A, typename B> ostream& operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator << (ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) { os << sep << x, sep = ", "; } return os << '}'; }
void D_out() { cerr << endl; }
template<typename Head, typename... Tail> void D_out(Head H, Tail... T) { cerr << ' ' << H; D_out(T...); }

#ifdef DEBUG
	#define D(...) cerr << '(' << #__VA_ARGS__ << "):", D_out(__VA_ARGS__)
#else
	#define D(...)
#endif

//#define int long long
#define ll long long
#define ld long double
#define f first
#define s second
#define sz(x) ((int) x.size())
#define all(x) (x).begin(), (x).end()
#define lowbit(x) (x & (-x))

const ll MOD = 1e9 + 7;
const ll INF = 1e18;

struct Event {
	int a, b, c, idx;

	Event (): a(0), b(0), c(0), idx(0) {}
	Event (int ta, int tb, int tc, int tidx): a(ta), b(tb), c(tc), idx(tidx) {}
}; 

struct BIT {
	int bit[200005];
	vector<int> nodes;
	
	void update(int x, int v) {
		nodes.push_back(x);
		for (; x; x -= lowbit(x)) {
			bit[x] += v;
		}
	}

	int query(int x) {
		int ret = 0;
		for (; x < 200005; x += lowbit(x)) {
			ret += bit[x];
		}
		return ret;
	}

	void reset() {
		for (int x : nodes) {
			for (; x; x -= lowbit(x)) {
				bit[x] = 0;
			}
		}
		nodes.clear();
	}
};

int n, q, sz, ans[100005];
Event events[200005];
vector<int> coordx, coordy, coordz;
BIT bt;

void cdq(int l, int r) {
	if (l == r) return;
	int m = (l + r) / 2;
	cdq(l, m);
	cdq(m + 1, r);
	for (int lidx = l, ridx = m; lidx <= m; lidx++) {
		while (ridx < r && events[lidx].b <= events[ridx + 1].b) {
			ridx++;
			if (!events[ridx].idx) {
				bt.update(events[ridx].c, 1);	
			}
		}
		if (events[lidx].idx) {
			ans[events[lidx].idx] += bt.query(events[lidx].c);
		}
	}
	bt.reset();
	inplace_merge(events + l, events + m + 1, events + r + 1, [&] (Event lft, Event rht) {
		return lft.b > rht.b;
	});
}

void solve() {
	cin >> n >> q;
	for (int i = 0, s, t; i < n; i++) {
		cin >> s >> t;
		events[sz++] = Event(s, t, s + t, 0);
		coordx.push_back(s);
		coordy.push_back(t);
		coordz.push_back(s + t);
	}
	for (int i = 1, x, y, z; i <= q; i++) {
		cin >> x >> y >> z;
		events[sz++] = Event(x, y, z, i);
		coordx.push_back(x);
		coordy.push_back(y);
		coordz.push_back(z);
	}
	sort(all(coordx));
	sort(all(coordy));
	sort(all(coordz));
	coordx.erase(unique(all(coordx)), coordx.end());
	coordy.erase(unique(all(coordy)), coordy.end());
	coordz.erase(unique(all(coordz)), coordz.end());
	for (int i = 0; i < sz; i++) {
		events[i].a = lower_bound(all(coordx), events[i].a) - coordx.begin() + 1;
		events[i].b = lower_bound(all(coordy), events[i].b) - coordy.begin() + 1;
		events[i].c = lower_bound(all(coordz), events[i].c) - coordz.begin() + 1;
	}
	sort(events, events + sz, [&] (Event lft, Event rht) {
		if (lft.a != rht.a) return lft.a < rht.a;
		else if (lft.b != rht.b) return lft.b < rht.b;
		else if (lft.c != rht.c) return lft.c < rht.c;
		return lft.idx > rht.idx;
	});
	cdq(0, sz - 1);
	for (int i = 1; i <= q; i++) {
		cout << ans[i] << "\n";
	}
}

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

	int t = 1; //cin >> t;
	for (int tc = 1; tc <= t; tc++) {
		//cout << "Case #" << tc << ": ";
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4600 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 8 ms 4956 KB Output is correct
8 Correct 9 ms 4956 KB Output is correct
9 Correct 7 ms 4840 KB Output is correct
10 Correct 9 ms 4704 KB Output is correct
11 Correct 6 ms 4696 KB Output is correct
12 Correct 5 ms 4924 KB Output is correct
13 Correct 7 ms 4700 KB Output is correct
14 Correct 7 ms 4852 KB Output is correct
15 Correct 7 ms 4700 KB Output is correct
16 Correct 5 ms 4700 KB Output is correct
17 Correct 6 ms 4700 KB Output is correct
18 Correct 5 ms 4576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 243 ms 11876 KB Output is correct
2 Correct 246 ms 14368 KB Output is correct
3 Correct 259 ms 14368 KB Output is correct
4 Correct 204 ms 13768 KB Output is correct
5 Correct 189 ms 13624 KB Output is correct
6 Correct 148 ms 12884 KB Output is correct
7 Correct 240 ms 14500 KB Output is correct
8 Correct 240 ms 14456 KB Output is correct
9 Correct 232 ms 14628 KB Output is correct
10 Correct 166 ms 13828 KB Output is correct
11 Correct 193 ms 13608 KB Output is correct
12 Correct 94 ms 13080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 243 ms 11876 KB Output is correct
2 Correct 246 ms 14368 KB Output is correct
3 Correct 259 ms 14368 KB Output is correct
4 Correct 204 ms 13768 KB Output is correct
5 Correct 189 ms 13624 KB Output is correct
6 Correct 148 ms 12884 KB Output is correct
7 Correct 240 ms 14500 KB Output is correct
8 Correct 240 ms 14456 KB Output is correct
9 Correct 232 ms 14628 KB Output is correct
10 Correct 166 ms 13828 KB Output is correct
11 Correct 193 ms 13608 KB Output is correct
12 Correct 94 ms 13080 KB Output is correct
13 Correct 278 ms 15008 KB Output is correct
14 Correct 276 ms 14892 KB Output is correct
15 Correct 244 ms 14352 KB Output is correct
16 Correct 224 ms 14184 KB Output is correct
17 Correct 220 ms 14164 KB Output is correct
18 Correct 109 ms 12688 KB Output is correct
19 Correct 284 ms 14968 KB Output is correct
20 Correct 271 ms 14776 KB Output is correct
21 Correct 256 ms 15184 KB Output is correct
22 Correct 178 ms 13988 KB Output is correct
23 Correct 170 ms 13620 KB Output is correct
24 Correct 109 ms 13080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4600 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 8 ms 4956 KB Output is correct
8 Correct 9 ms 4956 KB Output is correct
9 Correct 7 ms 4840 KB Output is correct
10 Correct 9 ms 4704 KB Output is correct
11 Correct 6 ms 4696 KB Output is correct
12 Correct 5 ms 4924 KB Output is correct
13 Correct 7 ms 4700 KB Output is correct
14 Correct 7 ms 4852 KB Output is correct
15 Correct 7 ms 4700 KB Output is correct
16 Correct 5 ms 4700 KB Output is correct
17 Correct 6 ms 4700 KB Output is correct
18 Correct 5 ms 4576 KB Output is correct
19 Correct 243 ms 11876 KB Output is correct
20 Correct 246 ms 14368 KB Output is correct
21 Correct 259 ms 14368 KB Output is correct
22 Correct 204 ms 13768 KB Output is correct
23 Correct 189 ms 13624 KB Output is correct
24 Correct 148 ms 12884 KB Output is correct
25 Correct 240 ms 14500 KB Output is correct
26 Correct 240 ms 14456 KB Output is correct
27 Correct 232 ms 14628 KB Output is correct
28 Correct 166 ms 13828 KB Output is correct
29 Correct 193 ms 13608 KB Output is correct
30 Correct 94 ms 13080 KB Output is correct
31 Correct 278 ms 15008 KB Output is correct
32 Correct 276 ms 14892 KB Output is correct
33 Correct 244 ms 14352 KB Output is correct
34 Correct 224 ms 14184 KB Output is correct
35 Correct 220 ms 14164 KB Output is correct
36 Correct 109 ms 12688 KB Output is correct
37 Correct 284 ms 14968 KB Output is correct
38 Correct 271 ms 14776 KB Output is correct
39 Correct 256 ms 15184 KB Output is correct
40 Correct 178 ms 13988 KB Output is correct
41 Correct 170 ms 13620 KB Output is correct
42 Correct 109 ms 13080 KB Output is correct
43 Correct 327 ms 16868 KB Output is correct
44 Correct 294 ms 16884 KB Output is correct
45 Correct 293 ms 17052 KB Output is correct
46 Correct 227 ms 15176 KB Output is correct
47 Correct 226 ms 15240 KB Output is correct
48 Correct 121 ms 12960 KB Output is correct
49 Correct 277 ms 16848 KB Output is correct
50 Correct 274 ms 16656 KB Output is correct
51 Correct 264 ms 16740 KB Output is correct
52 Correct 217 ms 15668 KB Output is correct
53 Correct 195 ms 14492 KB Output is correct