답안 #126980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
126980 2019-07-08T17:31:10 Z Mahmoud_Adel Examination (JOI19_examination) C++14
100 / 100
994 ms 19012 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, 
tree_order_statistics_node_update> oset;
const int N = 1e5+5;
ll n, m, ans[N];
pair<ll, pair<ll, int>> p[N];
struct query
{
	ll A, B, C, idx, ins;
};
bool cmX(query a, query b)
{
	return a.ins < b.ins;
}
bool cmC(query a, query b)
{
	return a.C < b.C;
}
bool cmXY(pair<ll, pair<ll, int>> a, pair<ll, pair<ll, int>> b)
{
	return a.f+a.s.f < b.f+b.s.f;
}
query q[N];
oset s;
int main()
{
	cin >> n >> m;
	for(int i=0; i<n; i++) cin >> p[i].f >> p[i].s.f, p[i].s.s = i, s.insert({p[i].s.f, i});
	for(int i=0; i<m; i++) cin >> q[i].A >> q[i].B >> q[i].C, q[i].idx = i;
	sort(p, p+n);
	ll l = 0;
	for(int i=0; i<m; i++)
	{
		q[i].C = max(q[i].C, q[i].A+q[i].B);
		q[i].ins = q[i].C-q[i].B;
	}
	sort(q, q+m, cmX);
	for(int i=0; i<m; i++)
	{
		while(l < n && p[l].f < q[i].ins) s.erase(p[l].s), l++;
		ans[q[i].idx] = s.size()-s.order_of_key({q[i].B, -1});
		//cout << q[i].idx << " | " << s.size() << " " << s.order_of_key({q[i].B, N}) << endl;
	}
	sort(q, q+m, cmC);
	sort(p, p+n, cmXY);
	s.clear();
	for(int i=0; i<n; i++) s.insert({p[i].f, p[i].s.s});
	l = 0;
	for(int i=0; i<m; i++)
	{
		if(q[i].A+q[i].B >= q[i].C) continue;
		while(l < n && p[l].f+p[l].s.f < q[i].C) s.erase({p[l].f, p[l].s.s}), l++;
		ans[q[i].idx] += s.order_of_key({q[i].ins, -1})-s.order_of_key({q[i].A, -1});
		//cout << q[i].idx << " | " << q[i].ins << " " << q[i].A << " | " << s.order_of_key({q[i].ins+1, -1}) << " " << s.order_of_key({q[i].A, -1}) << endl;
	}
	for(int i=0; i<m; i++) cout << ans[i] << endl;
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 26 ms 760 KB Output is correct
8 Correct 26 ms 788 KB Output is correct
9 Correct 26 ms 760 KB Output is correct
10 Correct 22 ms 760 KB Output is correct
11 Correct 22 ms 760 KB Output is correct
12 Correct 18 ms 760 KB Output is correct
13 Correct 24 ms 760 KB Output is correct
14 Correct 25 ms 760 KB Output is correct
15 Correct 25 ms 760 KB Output is correct
16 Correct 20 ms 760 KB Output is correct
17 Correct 22 ms 760 KB Output is correct
18 Correct 17 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 778 ms 14136 KB Output is correct
2 Correct 788 ms 14308 KB Output is correct
3 Correct 779 ms 14240 KB Output is correct
4 Correct 666 ms 14140 KB Output is correct
5 Correct 740 ms 14308 KB Output is correct
6 Correct 584 ms 14260 KB Output is correct
7 Correct 750 ms 14280 KB Output is correct
8 Correct 775 ms 14288 KB Output is correct
9 Correct 722 ms 14312 KB Output is correct
10 Correct 691 ms 13960 KB Output is correct
11 Correct 702 ms 14012 KB Output is correct
12 Correct 568 ms 14028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 778 ms 14136 KB Output is correct
2 Correct 788 ms 14308 KB Output is correct
3 Correct 779 ms 14240 KB Output is correct
4 Correct 666 ms 14140 KB Output is correct
5 Correct 740 ms 14308 KB Output is correct
6 Correct 584 ms 14260 KB Output is correct
7 Correct 750 ms 14280 KB Output is correct
8 Correct 775 ms 14288 KB Output is correct
9 Correct 722 ms 14312 KB Output is correct
10 Correct 691 ms 13960 KB Output is correct
11 Correct 702 ms 14012 KB Output is correct
12 Correct 568 ms 14028 KB Output is correct
13 Correct 858 ms 14228 KB Output is correct
14 Correct 840 ms 14172 KB Output is correct
15 Correct 776 ms 14204 KB Output is correct
16 Correct 712 ms 14276 KB Output is correct
17 Correct 798 ms 14256 KB Output is correct
18 Correct 593 ms 14272 KB Output is correct
19 Correct 857 ms 14184 KB Output is correct
20 Correct 885 ms 14236 KB Output is correct
21 Correct 876 ms 14200 KB Output is correct
22 Correct 688 ms 14072 KB Output is correct
23 Correct 691 ms 13984 KB Output is correct
24 Correct 564 ms 13824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 26 ms 760 KB Output is correct
8 Correct 26 ms 788 KB Output is correct
9 Correct 26 ms 760 KB Output is correct
10 Correct 22 ms 760 KB Output is correct
11 Correct 22 ms 760 KB Output is correct
12 Correct 18 ms 760 KB Output is correct
13 Correct 24 ms 760 KB Output is correct
14 Correct 25 ms 760 KB Output is correct
15 Correct 25 ms 760 KB Output is correct
16 Correct 20 ms 760 KB Output is correct
17 Correct 22 ms 760 KB Output is correct
18 Correct 17 ms 760 KB Output is correct
19 Correct 778 ms 14136 KB Output is correct
20 Correct 788 ms 14308 KB Output is correct
21 Correct 779 ms 14240 KB Output is correct
22 Correct 666 ms 14140 KB Output is correct
23 Correct 740 ms 14308 KB Output is correct
24 Correct 584 ms 14260 KB Output is correct
25 Correct 750 ms 14280 KB Output is correct
26 Correct 775 ms 14288 KB Output is correct
27 Correct 722 ms 14312 KB Output is correct
28 Correct 691 ms 13960 KB Output is correct
29 Correct 702 ms 14012 KB Output is correct
30 Correct 568 ms 14028 KB Output is correct
31 Correct 858 ms 14228 KB Output is correct
32 Correct 840 ms 14172 KB Output is correct
33 Correct 776 ms 14204 KB Output is correct
34 Correct 712 ms 14276 KB Output is correct
35 Correct 798 ms 14256 KB Output is correct
36 Correct 593 ms 14272 KB Output is correct
37 Correct 857 ms 14184 KB Output is correct
38 Correct 885 ms 14236 KB Output is correct
39 Correct 876 ms 14200 KB Output is correct
40 Correct 688 ms 14072 KB Output is correct
41 Correct 691 ms 13984 KB Output is correct
42 Correct 564 ms 13824 KB Output is correct
43 Correct 979 ms 14180 KB Output is correct
44 Correct 994 ms 14136 KB Output is correct
45 Correct 955 ms 19012 KB Output is correct
46 Correct 781 ms 17548 KB Output is correct
47 Correct 860 ms 17620 KB Output is correct
48 Correct 600 ms 15016 KB Output is correct
49 Correct 969 ms 18912 KB Output is correct
50 Correct 988 ms 18996 KB Output is correct
51 Correct 987 ms 18908 KB Output is correct
52 Correct 854 ms 17344 KB Output is correct
53 Correct 763 ms 16676 KB Output is correct