답안 #518571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
518571 2022-01-24T07:01:49 Z starchan Examination (JOI19_examination) C++17
100 / 100
194 ms 22364 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF 1e17
#define zero (int)0
#define MX (int)3e5+5
#define LMX (int)5e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
const int mod = 1e9+7; //may change to that 99.. number.
struct segment_tree
{
	vector<int> tree;
	void init()
	{
		tree.assign(LMX, 0);
		return;
	}
	void upd(int x, int id, int l, int r)
	{
		int m = (l+r)/2;
		if(l == r)
		{
			tree[id]++;
			return;
		}
		if(x <= m)
			upd(x, 2*id, l, m);
		else
			upd(x, 2*id+1, m+1, r);
		tree[id] = tree[2*id]+tree[2*id+1];
		return;
	}
	int sum(int ql, int qr, int id, int l, int r)
	{
		int m = (l+r)/2;
		if(l > qr || ql > r)
			return 0;
		if(ql <= l && r <= qr)
			return tree[id];
		int sum1 = sum(ql, qr, 2*id, l, m);
		int sum2 = sum(ql, qr, 2*id+1, m+1, r);
		return sum1+sum2;
	}
};
vector<int> solve(vector<in> queries, vector<int> a, int n, int q)
{
	segment_tree work;
	work.init();
	vector<in> ok(n+2);
	ok[n+1] = {INF, INF}; 
	vector<pair<in, int>> quer(q);
	for(int i = 0; i < q; i++)
	{
		quer[i].f.f = queries[i].s;
		quer[i].f.s = queries[i].f;
		quer[i].s = i;
	}
	for(int i = 1; i <= n; i++)
		ok[i] = {a[i], i};
	ok[0] = {-INF, -1};
	int curr = 1;
	sort(ok.begin(), ok.end());
	vector<int> ans(q);
	sort(quer.begin(), quer.end());
	for(int i = 0; i < q; i++)
	{		
		if(quer[i].f.s == 0)
		{
			ans[quer[i].s] = 0;
			continue;
		}
		while(ok[curr].f < quer[i].f.f)
		{
			work.upd(ok[curr].s, 1, 1, n);
			curr++;
		}
		ans[quer[i].s] = work.sum(1, quer[i].f.s, 1, 1, n);
	}
	return ans;
}
signed main()
{
	fast();
	int n, q;
	cin >> n >> q;
	vector<pair<int, in>> values(n+1);
	vector<int> a(n+1);
	vector<int> b(n+1);
	vector<int> c(n+1);
	for(int i = 1; i <= n; i++)
	{
		int a, b;
		cin >> a >> b;
		values[i] = {-a-b, {a, b}};
	}
	values[0] = {-INF, {0, 0}};
	sort(values.begin(), values.end());
	for(int i = 1; i <= n; i++)
	{
		c[i] = -values[i].f;
		a[i] = values[i].s.f;
		b[i] = values[i].s.s;
	}
	vector<int> oh(q);
	vector<in> queries_a(q);
	vector<in> queries_b(q);
	for(int i = 0; i < q; i++)
	{
		int z;
		cin >> queries_a[i].s >> queries_b[i].s >> z;
		z = max(z, queries_a[i].s+queries_b[i].s);
		int l = 1;
		int r = n+1;
		while(l < r)
		{
			int m = (l+r)/2;
			if(c[m] < z)
				r = m;
			else
				l = m+1;
		}
		l--;
		oh[i] = queries_a[i].f = queries_b[i].f = l;
	}
	vector<int> ans_a = solve(queries_a, a, n, q);
	vector<int> ans_b = solve(queries_b, b, n, q);
	for(int i = 0; i < q; i++)
		cout << oh[i]-ans_a[i]-ans_b[i] << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4224 KB Output is correct
2 Correct 3 ms 4212 KB Output is correct
3 Correct 4 ms 4212 KB Output is correct
4 Correct 4 ms 4208 KB Output is correct
5 Correct 3 ms 4232 KB Output is correct
6 Correct 3 ms 4232 KB Output is correct
7 Correct 7 ms 4876 KB Output is correct
8 Correct 9 ms 4872 KB Output is correct
9 Correct 8 ms 4864 KB Output is correct
10 Correct 9 ms 4784 KB Output is correct
11 Correct 7 ms 4772 KB Output is correct
12 Correct 6 ms 4772 KB Output is correct
13 Correct 7 ms 4872 KB Output is correct
14 Correct 7 ms 4812 KB Output is correct
15 Correct 7 ms 4848 KB Output is correct
16 Correct 9 ms 4744 KB Output is correct
17 Correct 7 ms 4784 KB Output is correct
18 Correct 5 ms 4672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 175 ms 22140 KB Output is correct
2 Correct 170 ms 22256 KB Output is correct
3 Correct 173 ms 22308 KB Output is correct
4 Correct 142 ms 22248 KB Output is correct
5 Correct 150 ms 22212 KB Output is correct
6 Correct 114 ms 22248 KB Output is correct
7 Correct 154 ms 22288 KB Output is correct
8 Correct 175 ms 22276 KB Output is correct
9 Correct 129 ms 22276 KB Output is correct
10 Correct 139 ms 22092 KB Output is correct
11 Correct 130 ms 22000 KB Output is correct
12 Correct 80 ms 21892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 175 ms 22140 KB Output is correct
2 Correct 170 ms 22256 KB Output is correct
3 Correct 173 ms 22308 KB Output is correct
4 Correct 142 ms 22248 KB Output is correct
5 Correct 150 ms 22212 KB Output is correct
6 Correct 114 ms 22248 KB Output is correct
7 Correct 154 ms 22288 KB Output is correct
8 Correct 175 ms 22276 KB Output is correct
9 Correct 129 ms 22276 KB Output is correct
10 Correct 139 ms 22092 KB Output is correct
11 Correct 130 ms 22000 KB Output is correct
12 Correct 80 ms 21892 KB Output is correct
13 Correct 181 ms 22212 KB Output is correct
14 Correct 175 ms 22260 KB Output is correct
15 Correct 171 ms 22220 KB Output is correct
16 Correct 151 ms 22188 KB Output is correct
17 Correct 151 ms 22364 KB Output is correct
18 Correct 118 ms 22264 KB Output is correct
19 Correct 194 ms 22192 KB Output is correct
20 Correct 172 ms 22148 KB Output is correct
21 Correct 159 ms 22180 KB Output is correct
22 Correct 139 ms 22000 KB Output is correct
23 Correct 140 ms 22048 KB Output is correct
24 Correct 71 ms 21828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4224 KB Output is correct
2 Correct 3 ms 4212 KB Output is correct
3 Correct 4 ms 4212 KB Output is correct
4 Correct 4 ms 4208 KB Output is correct
5 Correct 3 ms 4232 KB Output is correct
6 Correct 3 ms 4232 KB Output is correct
7 Correct 7 ms 4876 KB Output is correct
8 Correct 9 ms 4872 KB Output is correct
9 Correct 8 ms 4864 KB Output is correct
10 Correct 9 ms 4784 KB Output is correct
11 Correct 7 ms 4772 KB Output is correct
12 Correct 6 ms 4772 KB Output is correct
13 Correct 7 ms 4872 KB Output is correct
14 Correct 7 ms 4812 KB Output is correct
15 Correct 7 ms 4848 KB Output is correct
16 Correct 9 ms 4744 KB Output is correct
17 Correct 7 ms 4784 KB Output is correct
18 Correct 5 ms 4672 KB Output is correct
19 Correct 175 ms 22140 KB Output is correct
20 Correct 170 ms 22256 KB Output is correct
21 Correct 173 ms 22308 KB Output is correct
22 Correct 142 ms 22248 KB Output is correct
23 Correct 150 ms 22212 KB Output is correct
24 Correct 114 ms 22248 KB Output is correct
25 Correct 154 ms 22288 KB Output is correct
26 Correct 175 ms 22276 KB Output is correct
27 Correct 129 ms 22276 KB Output is correct
28 Correct 139 ms 22092 KB Output is correct
29 Correct 130 ms 22000 KB Output is correct
30 Correct 80 ms 21892 KB Output is correct
31 Correct 181 ms 22212 KB Output is correct
32 Correct 175 ms 22260 KB Output is correct
33 Correct 171 ms 22220 KB Output is correct
34 Correct 151 ms 22188 KB Output is correct
35 Correct 151 ms 22364 KB Output is correct
36 Correct 118 ms 22264 KB Output is correct
37 Correct 194 ms 22192 KB Output is correct
38 Correct 172 ms 22148 KB Output is correct
39 Correct 159 ms 22180 KB Output is correct
40 Correct 139 ms 22000 KB Output is correct
41 Correct 140 ms 22048 KB Output is correct
42 Correct 71 ms 21828 KB Output is correct
43 Correct 190 ms 22212 KB Output is correct
44 Correct 179 ms 22208 KB Output is correct
45 Correct 180 ms 22232 KB Output is correct
46 Correct 160 ms 22208 KB Output is correct
47 Correct 173 ms 22208 KB Output is correct
48 Correct 107 ms 22016 KB Output is correct
49 Correct 164 ms 22224 KB Output is correct
50 Correct 180 ms 22232 KB Output is correct
51 Correct 151 ms 22292 KB Output is correct
52 Correct 153 ms 21988 KB Output is correct
53 Correct 138 ms 22016 KB Output is correct