Submission #187354

# Submission time Handle Problem Language Result Execution time Memory
187354 2020-01-12T22:32:50 Z super_j6 Examination (JOI19_examination) C++14
100 / 100
1810 ms 469644 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define pii pair<pi, pi>

struct segTree{
	int l, r;
	segTree *left = 0, *right = 0;
	long val = 0;
	
	segTree(int a, int b){
		l = a;
		r = b;
	}
	
	void add(int x, int v){
		if(l == r){
			val += v;
			return;
		}
		
		int mid = (l + r) / 2;
		if(x <= mid){
			if(!left) left = new segTree(l, mid);
			left->add(x, v);
		}else{
			if(!right) right = new segTree(mid + 1, r);
			right->add(x, v);
		}
		
		val = (left ? left->val : 0) + (right ? right->val : 0);
	}
	
	long qry(int a, int b){
		if(r < a || b < l) return 0;
		if(a <= l && r <= b) return val;
		
		return (left ? left->qry(a, b) : 0) + (right ? right->qry(a, b) : 0);
	}
};

const int maxn = 300001;

struct BIT{
	segTree *bit[maxn];
	
	BIT(){
		memset(bit, 0, sizeof(bit));
	}
	
	void add(int x, int y, int v){
		for(x++; x < maxn; x += x & -x){
			if(!bit[x]) bit[x] = new segTree(0, maxn);
			bit[x]->add(y, v);
		}
	}
	
	int qry(int x, int y, int Y){
		int ret = 0;
		for(x++; x; x -= x & -x) if(bit[x]) ret += bit[x]->qry(y, Y);
		return ret;
	}
	
	int qry(int x, int X, int y, int Y){
		return qry(X, y, Y) - qry(x - 1, y, Y);
	}
};

int n, q;
pi a[maxn];
pii qry[maxn];
vector<int> v;
BIT bit;
int ans[maxn];

int id(int x){
	return lower_bound(v.begin(), v.end(), x, greater<int>()) - v.begin();
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> q;
	
	for(int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
	for(int i = 0; i < q; i++){
		cin >> qry[i].first.first >> qry[i].second.first >> qry[i].second.second;
		qry[i].first.second = i;
		v.push_back(qry[i].first.first);
		v.push_back(qry[i].second.first);
		v.push_back(qry[i].second.second);
	} 
	
	sort(a, a + n, greater<pi>());
	sort(qry, qry + q, greater<pii>());
	sort(v.begin(), v.end(), greater<int>());
	v.erase(unique(v.begin(), v.end()), v.end());
	
	for(int i = 0, j = 0; i < q; i++){
		for(; j < n && a[j].first >= qry[i].first.first; j++) bit.add(id(a[j].second), id(a[j].first + a[j].second), 1);
		ans[qry[i].first.second] = bit.qry(id(qry[i].second.first), 0, id(qry[i].second.second));
	}
	
	for(int i = 0; i < q; i++) cout << ans[i] << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 35 ms 13052 KB Output is correct
8 Correct 34 ms 13176 KB Output is correct
9 Correct 34 ms 13304 KB Output is correct
10 Correct 17 ms 6776 KB Output is correct
11 Correct 24 ms 9208 KB Output is correct
12 Correct 12 ms 2936 KB Output is correct
13 Correct 26 ms 10232 KB Output is correct
14 Correct 26 ms 10104 KB Output is correct
15 Correct 26 ms 10104 KB Output is correct
16 Correct 18 ms 7160 KB Output is correct
17 Correct 16 ms 6264 KB Output is correct
18 Correct 10 ms 2940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1042 ms 248532 KB Output is correct
2 Correct 1083 ms 250148 KB Output is correct
3 Correct 1048 ms 251372 KB Output is correct
4 Correct 296 ms 68456 KB Output is correct
5 Correct 585 ms 115008 KB Output is correct
6 Correct 248 ms 8292 KB Output is correct
7 Correct 1010 ms 225096 KB Output is correct
8 Correct 1008 ms 225060 KB Output is correct
9 Correct 362 ms 19204 KB Output is correct
10 Correct 401 ms 106824 KB Output is correct
11 Correct 257 ms 54248 KB Output is correct
12 Correct 215 ms 8144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1042 ms 248532 KB Output is correct
2 Correct 1083 ms 250148 KB Output is correct
3 Correct 1048 ms 251372 KB Output is correct
4 Correct 296 ms 68456 KB Output is correct
5 Correct 585 ms 115008 KB Output is correct
6 Correct 248 ms 8292 KB Output is correct
7 Correct 1010 ms 225096 KB Output is correct
8 Correct 1008 ms 225060 KB Output is correct
9 Correct 362 ms 19204 KB Output is correct
10 Correct 401 ms 106824 KB Output is correct
11 Correct 257 ms 54248 KB Output is correct
12 Correct 215 ms 8144 KB Output is correct
13 Correct 1710 ms 386908 KB Output is correct
14 Correct 1216 ms 258176 KB Output is correct
15 Correct 1050 ms 250196 KB Output is correct
16 Correct 484 ms 97256 KB Output is correct
17 Correct 739 ms 145528 KB Output is correct
18 Correct 254 ms 8420 KB Output is correct
19 Correct 1709 ms 386116 KB Output is correct
20 Correct 1580 ms 364504 KB Output is correct
21 Correct 1761 ms 351948 KB Output is correct
22 Correct 398 ms 107048 KB Output is correct
23 Correct 243 ms 49192 KB Output is correct
24 Correct 215 ms 8048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 35 ms 13052 KB Output is correct
8 Correct 34 ms 13176 KB Output is correct
9 Correct 34 ms 13304 KB Output is correct
10 Correct 17 ms 6776 KB Output is correct
11 Correct 24 ms 9208 KB Output is correct
12 Correct 12 ms 2936 KB Output is correct
13 Correct 26 ms 10232 KB Output is correct
14 Correct 26 ms 10104 KB Output is correct
15 Correct 26 ms 10104 KB Output is correct
16 Correct 18 ms 7160 KB Output is correct
17 Correct 16 ms 6264 KB Output is correct
18 Correct 10 ms 2940 KB Output is correct
19 Correct 1042 ms 248532 KB Output is correct
20 Correct 1083 ms 250148 KB Output is correct
21 Correct 1048 ms 251372 KB Output is correct
22 Correct 296 ms 68456 KB Output is correct
23 Correct 585 ms 115008 KB Output is correct
24 Correct 248 ms 8292 KB Output is correct
25 Correct 1010 ms 225096 KB Output is correct
26 Correct 1008 ms 225060 KB Output is correct
27 Correct 362 ms 19204 KB Output is correct
28 Correct 401 ms 106824 KB Output is correct
29 Correct 257 ms 54248 KB Output is correct
30 Correct 215 ms 8144 KB Output is correct
31 Correct 1710 ms 386908 KB Output is correct
32 Correct 1216 ms 258176 KB Output is correct
33 Correct 1050 ms 250196 KB Output is correct
34 Correct 484 ms 97256 KB Output is correct
35 Correct 739 ms 145528 KB Output is correct
36 Correct 254 ms 8420 KB Output is correct
37 Correct 1709 ms 386116 KB Output is correct
38 Correct 1580 ms 364504 KB Output is correct
39 Correct 1761 ms 351948 KB Output is correct
40 Correct 398 ms 107048 KB Output is correct
41 Correct 243 ms 49192 KB Output is correct
42 Correct 215 ms 8048 KB Output is correct
43 Correct 1760 ms 469548 KB Output is correct
44 Correct 1779 ms 469644 KB Output is correct
45 Correct 1456 ms 340968 KB Output is correct
46 Correct 545 ms 132328 KB Output is correct
47 Correct 858 ms 192136 KB Output is correct
48 Correct 243 ms 8180 KB Output is correct
49 Correct 1426 ms 320708 KB Output is correct
50 Correct 1810 ms 444628 KB Output is correct
51 Correct 1444 ms 271288 KB Output is correct
52 Correct 623 ms 191796 KB Output is correct
53 Correct 320 ms 80136 KB Output is correct