Submission #403808

# Submission time Handle Problem Language Result Execution time Memory
403808 2021-05-13T13:28:48 Z pure_mem Examination (JOI19_examination) C++14
100 / 100
1189 ms 282652 KB
#include <bits/stdc++.h> 
 
#define X first
#define Y second
#define MP make_pair
#define ll long long
 
using namespace std;
 
const int N = 1e5 + 12;
const ll INF = 1e18;

struct node{
	int val = 0;
	node* to[2] = {nullptr, nullptr};
	node* getp(int v){
		if(!to[v])
			to[v] = new node();
		return to[v];
	}		
	void upd(int tl, int tr, int pos){
		val += 1;
		if(tl == tr)
			return;
		int tm = (tl + tr) / 2;
		if(pos <= tm)
			getp(0)->upd(tl, tm, pos);
		else
			getp(1)->upd(tm + 1, tr, pos);
	}
	int get(int tl, int tr, int l, int r){
		if(tl > r || l > tr)
			return 0;
		if(tl >= l && tr <= r)
			return val;
		int tm = (tl + tr) / 2;
		return (to[0] ? to[0]->get(tl, tm, l, r): 0) + (to[1] ? to[1]->get(tm + 1, tr, l, r): 0);
	}
};
node fw[N];

vector< int > sqA, sqB, sqC;
vector< pair< int, int > > todo[N];
vector< pair< pair< int, int >, int > > query[N];

int n, q, answer[N];
pair< int, int > p[N];

void add(int x, int y){
	for(;x <= sqA.size();x |= x + 1)
		fw[x].upd(1, sqB.size(), y);//, cerr << x << " " << y << "s\n";
}
int get(int x, int y){
	int r = 0;
	for(;x >= 0;x = (x & (x + 1)) - 1)
		r += fw[x].get(1, sqB.size(), 1, y);
	return r;
}

int main () {
	ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin >> n >> q;
	for(int i = 1;i <= n;i++){
		cin >> p[i].X >> p[i].Y;
		sqA.push_back(p[i].X), sqB.push_back(p[i].Y), sqC.push_back(p[i].X + p[i].Y);
	}
	sort(sqA.begin(), sqA.end()), sqA.erase(unique(sqA.begin(), sqA.end()), sqA.end());
	sort(sqB.begin(), sqB.end()), sqB.erase(unique(sqB.begin(), sqB.end()), sqB.end());
	sort(sqC.begin(), sqC.end()), sqC.erase(unique(sqC.begin(), sqC.end()), sqC.end());
	for(int i = 1;i <= n;i++){
		int it1 = lower_bound(sqA.begin(), sqA.end(), p[i].X) - sqA.begin();
		int it2 = lower_bound(sqB.begin(), sqB.end(), p[i].Y) - sqB.begin();		
		int it3 = lower_bound(sqC.begin(), sqC.end(), p[i].X + p[i].Y) - sqC.begin();
		todo[it3].push_back(MP(sqA.size() - it1, sqB.size() - it2));
	}
	for(int i = 1, x, y, z;i <= q;i++){
		cin >> x >> y >> z;
		int it1 = lower_bound(sqA.begin(), sqA.end(), x) - sqA.begin();
		int it2 = lower_bound(sqB.begin(), sqB.end(), y) - sqB.begin();		
		int it3 = lower_bound(sqC.begin(), sqC.end(), z) - sqC.begin();
		query[it3].push_back(MP(MP(sqA.size() - it1, sqB.size() - it2), i));
	}
	for(int i = (int)sqC.size() - 1;i >= 0;i--){
		for(pair<int, int> tmp: todo[i]){
		//	cerr << tmp.X << " " << tmp.Y << " " << i << "\n";
			add(tmp.X, tmp.Y);
		}	
		for(pair< pair<int, int>, int > tmp: query[i]){
		//	cerr << "was " << tmp.X.X << " " << tmp.X.Y << " " << i << "\n";
			answer[tmp.Y] = get(tmp.X.X, tmp.X.Y);
		}
	}
	for(int i = 1;i <= q;i++)
		cout << answer[i] << "\n";
}                

Compilation message

examination.cpp: In function 'void add(int, int)':
examination.cpp:50:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for(;x <= sqA.size();x |= x + 1)
      |       ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5024 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 16 ms 9548 KB Output is correct
8 Correct 16 ms 9516 KB Output is correct
9 Correct 17 ms 9496 KB Output is correct
10 Correct 9 ms 5964 KB Output is correct
11 Correct 9 ms 6092 KB Output is correct
12 Correct 6 ms 5196 KB Output is correct
13 Correct 17 ms 9476 KB Output is correct
14 Correct 16 ms 9496 KB Output is correct
15 Correct 17 ms 9496 KB Output is correct
16 Correct 8 ms 5452 KB Output is correct
17 Correct 7 ms 5452 KB Output is correct
18 Correct 5 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1114 ms 238348 KB Output is correct
2 Correct 1053 ms 238092 KB Output is correct
3 Correct 1032 ms 238332 KB Output is correct
4 Correct 239 ms 30768 KB Output is correct
5 Correct 242 ms 31792 KB Output is correct
6 Correct 86 ms 11508 KB Output is correct
7 Correct 975 ms 238376 KB Output is correct
8 Correct 943 ms 238000 KB Output is correct
9 Correct 824 ms 237900 KB Output is correct
10 Correct 159 ms 16692 KB Output is correct
11 Correct 146 ms 14640 KB Output is correct
12 Correct 60 ms 11252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1114 ms 238348 KB Output is correct
2 Correct 1053 ms 238092 KB Output is correct
3 Correct 1032 ms 238332 KB Output is correct
4 Correct 239 ms 30768 KB Output is correct
5 Correct 242 ms 31792 KB Output is correct
6 Correct 86 ms 11508 KB Output is correct
7 Correct 975 ms 238376 KB Output is correct
8 Correct 943 ms 238000 KB Output is correct
9 Correct 824 ms 237900 KB Output is correct
10 Correct 159 ms 16692 KB Output is correct
11 Correct 146 ms 14640 KB Output is correct
12 Correct 60 ms 11252 KB Output is correct
13 Correct 981 ms 239368 KB Output is correct
14 Correct 1121 ms 239324 KB Output is correct
15 Correct 1006 ms 238356 KB Output is correct
16 Correct 248 ms 32036 KB Output is correct
17 Correct 256 ms 32976 KB Output is correct
18 Correct 92 ms 12084 KB Output is correct
19 Correct 958 ms 239588 KB Output is correct
20 Correct 1083 ms 239544 KB Output is correct
21 Correct 799 ms 239724 KB Output is correct
22 Correct 160 ms 16692 KB Output is correct
23 Correct 142 ms 14656 KB Output is correct
24 Correct 70 ms 11256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5024 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 16 ms 9548 KB Output is correct
8 Correct 16 ms 9516 KB Output is correct
9 Correct 17 ms 9496 KB Output is correct
10 Correct 9 ms 5964 KB Output is correct
11 Correct 9 ms 6092 KB Output is correct
12 Correct 6 ms 5196 KB Output is correct
13 Correct 17 ms 9476 KB Output is correct
14 Correct 16 ms 9496 KB Output is correct
15 Correct 17 ms 9496 KB Output is correct
16 Correct 8 ms 5452 KB Output is correct
17 Correct 7 ms 5452 KB Output is correct
18 Correct 5 ms 5212 KB Output is correct
19 Correct 1114 ms 238348 KB Output is correct
20 Correct 1053 ms 238092 KB Output is correct
21 Correct 1032 ms 238332 KB Output is correct
22 Correct 239 ms 30768 KB Output is correct
23 Correct 242 ms 31792 KB Output is correct
24 Correct 86 ms 11508 KB Output is correct
25 Correct 975 ms 238376 KB Output is correct
26 Correct 943 ms 238000 KB Output is correct
27 Correct 824 ms 237900 KB Output is correct
28 Correct 159 ms 16692 KB Output is correct
29 Correct 146 ms 14640 KB Output is correct
30 Correct 60 ms 11252 KB Output is correct
31 Correct 981 ms 239368 KB Output is correct
32 Correct 1121 ms 239324 KB Output is correct
33 Correct 1006 ms 238356 KB Output is correct
34 Correct 248 ms 32036 KB Output is correct
35 Correct 256 ms 32976 KB Output is correct
36 Correct 92 ms 12084 KB Output is correct
37 Correct 958 ms 239588 KB Output is correct
38 Correct 1083 ms 239544 KB Output is correct
39 Correct 799 ms 239724 KB Output is correct
40 Correct 160 ms 16692 KB Output is correct
41 Correct 142 ms 14656 KB Output is correct
42 Correct 70 ms 11256 KB Output is correct
43 Correct 1038 ms 282552 KB Output is correct
44 Correct 1077 ms 282336 KB Output is correct
45 Correct 1189 ms 282312 KB Output is correct
46 Correct 278 ms 39284 KB Output is correct
47 Correct 290 ms 40776 KB Output is correct
48 Correct 86 ms 10944 KB Output is correct
49 Correct 1039 ms 282256 KB Output is correct
50 Correct 958 ms 282652 KB Output is correct
51 Correct 893 ms 282040 KB Output is correct
52 Correct 250 ms 22520 KB Output is correct
53 Correct 157 ms 17304 KB Output is correct