Submission #613485

# Submission time Handle Problem Language Result Execution time Memory
613485 2022-07-30T05:08:35 Z amunduzbaev Examination (JOI19_examination) C++17
100 / 100
1719 ms 56124 KB
#include "bits/stdc++.h"
using namespace std;

#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;

template<class T> using oset = tree<T, null_type, less_equal<T>, 
rb_tree_tag, tree_order_statistics_node_update>;

#define ar array
typedef int64_t ll;
#define sow cerr<<"here"<<endl;

const int N = 1e5 + 5;

//~ struct node{
	//~ int sum, L, R;
	//~ node(){
		//~ sum = L = R = 0;
	//~ }
//~ };

//~ struct ST{
	//~ vector<node> tree;
	//~ int last;
	//~ ST(){
		//~ last = 1;
		//~ tree.resize(1);
	//~ }
	
	//~ void pot(int x){
		//~ if(!tree[x].L) tree[x].L = last++, tree.resize(last);
		//~ if(!tree[x].R) tree[x].R = last++, tree.resize(last);
	//~ }
	
	//~ void add(int i, int v, int lx = 0, int rx = N, int x = 0){
		//~ if(lx == rx){
			//~ tree[x].sum += v;
			//~ return;
		//~ } int m = (lx + rx) >> 1;
		//~ pot(x);
		//~ if(i <= m) add(i, v, lx, m, tree[x].L);
		//~ else add(i, v, m + 1, rx, tree[x].R);
		//~ tree[x].sum = tree[tree[x].L].sum + tree[tree[x].R].sum;
	//~ }
	
	//~ int get(int l, int r, int lx = 0, int rx = N, int x = 0){
		//~ if(lx > r || rx < l) return 0;
		//~ if(lx >= l && rx <= r) return tree[x].sum;
		//~ int m = (lx + rx) >> 1, res = 0;
		//~ if(tree[x].L) res += get(l, r, lx, m, tree[x].L);
		//~ if(tree[x].R) res += get(l, r, m + 1, rx, tree[x].R);
		//~ return res;
	//~ }
//~ };

struct BIT{
	oset<int> tree[N];
	void add(int i, int v){
		i = N - i - 1;
		for(;i<N;i+=(i&-i)) tree[i].insert(v);
	}
	
	int get(int i, int v){
		int r = 0; i = N - i - 1;
		for(;i>0;i-=(i&-i)) r += (tree[i].size() - tree[i].order_of_key(v));
		return r;
	}
}T;

int s[N], t[N], x[N], y[N], z[N], res[N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, q; cin >> n >> q;
	vector<int> P(n), zh, zhs;
	for(int i=0;i<n;i++){
		cin >> s[i] >> t[i];
		P[i] = i;
		zh.push_back(t[i]);
		zhs.push_back(s[i] + t[i]);
	}
	
	sort(zh.begin(), zh.end());
	zh.erase(unique(zh.begin(), zh.end()), zh.end());
	sort(zhs.begin(), zhs.end());
	zhs.erase(unique(zhs.begin(), zhs.end()), zhs.end());
	
	vector<int> p(q);
	for(int i=0;i<q;i++){
		cin >> x[i] >> y[i] >> z[i];
		p[i] = i;
	}
	
	sort(p.begin(), p.end(), [&](int i, int j){
		return x[i] > x[j];
	});
	sort(P.begin(), P.end(), [&](int i, int j){
		return s[i] > s[j];
	});
	
	auto add = [&](int i){
		int x = lower_bound(zh.begin(), zh.end(), t[i]) - zh.begin();
		int y = lower_bound(zhs.begin(), zhs.end(), s[i] + t[i]) - zhs.begin();
		T.add(x, y);
	};
	
	int j = 0;
	for(auto i : p){
		while(j < n && s[P[j]] >= x[i]){
			add(P[j++]);
		}
		int k = lower_bound(zh.begin(), zh.end(), y[i]) - zh.begin();
		int l = lower_bound(zhs.begin(), zhs.end(), z[i]) - zhs.begin();
		res[i] = T.get(k, l);
	}
	
	for(int i=0;i<q;i++) cout<<res[i]<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8148 KB Output is correct
2 Correct 9 ms 8164 KB Output is correct
3 Correct 9 ms 8148 KB Output is correct
4 Correct 8 ms 8148 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 9 ms 8148 KB Output is correct
7 Correct 22 ms 9172 KB Output is correct
8 Correct 18 ms 9188 KB Output is correct
9 Correct 20 ms 9172 KB Output is correct
10 Correct 12 ms 8728 KB Output is correct
11 Correct 19 ms 9312 KB Output is correct
12 Correct 11 ms 8552 KB Output is correct
13 Correct 15 ms 9172 KB Output is correct
14 Correct 17 ms 9192 KB Output is correct
15 Correct 18 ms 9172 KB Output is correct
16 Correct 14 ms 9172 KB Output is correct
17 Correct 13 ms 8520 KB Output is correct
18 Correct 9 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1178 ms 53836 KB Output is correct
2 Correct 1012 ms 53920 KB Output is correct
3 Correct 1128 ms 53864 KB Output is correct
4 Correct 255 ms 24576 KB Output is correct
5 Correct 785 ms 53464 KB Output is correct
6 Correct 182 ms 23828 KB Output is correct
7 Correct 1165 ms 53872 KB Output is correct
8 Correct 1039 ms 53852 KB Output is correct
9 Correct 937 ms 53920 KB Output is correct
10 Correct 705 ms 53228 KB Output is correct
11 Correct 189 ms 18828 KB Output is correct
12 Correct 133 ms 17936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1178 ms 53836 KB Output is correct
2 Correct 1012 ms 53920 KB Output is correct
3 Correct 1128 ms 53864 KB Output is correct
4 Correct 255 ms 24576 KB Output is correct
5 Correct 785 ms 53464 KB Output is correct
6 Correct 182 ms 23828 KB Output is correct
7 Correct 1165 ms 53872 KB Output is correct
8 Correct 1039 ms 53852 KB Output is correct
9 Correct 937 ms 53920 KB Output is correct
10 Correct 705 ms 53228 KB Output is correct
11 Correct 189 ms 18828 KB Output is correct
12 Correct 133 ms 17936 KB Output is correct
13 Correct 1512 ms 53700 KB Output is correct
14 Correct 1224 ms 53784 KB Output is correct
15 Correct 1190 ms 53920 KB Output is correct
16 Correct 327 ms 24992 KB Output is correct
17 Correct 1056 ms 53804 KB Output is correct
18 Correct 262 ms 23896 KB Output is correct
19 Correct 1386 ms 53836 KB Output is correct
20 Correct 1240 ms 53836 KB Output is correct
21 Correct 1612 ms 53836 KB Output is correct
22 Correct 950 ms 53276 KB Output is correct
23 Correct 202 ms 18916 KB Output is correct
24 Correct 126 ms 17912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8148 KB Output is correct
2 Correct 9 ms 8164 KB Output is correct
3 Correct 9 ms 8148 KB Output is correct
4 Correct 8 ms 8148 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 9 ms 8148 KB Output is correct
7 Correct 22 ms 9172 KB Output is correct
8 Correct 18 ms 9188 KB Output is correct
9 Correct 20 ms 9172 KB Output is correct
10 Correct 12 ms 8728 KB Output is correct
11 Correct 19 ms 9312 KB Output is correct
12 Correct 11 ms 8552 KB Output is correct
13 Correct 15 ms 9172 KB Output is correct
14 Correct 17 ms 9192 KB Output is correct
15 Correct 18 ms 9172 KB Output is correct
16 Correct 14 ms 9172 KB Output is correct
17 Correct 13 ms 8520 KB Output is correct
18 Correct 9 ms 8404 KB Output is correct
19 Correct 1178 ms 53836 KB Output is correct
20 Correct 1012 ms 53920 KB Output is correct
21 Correct 1128 ms 53864 KB Output is correct
22 Correct 255 ms 24576 KB Output is correct
23 Correct 785 ms 53464 KB Output is correct
24 Correct 182 ms 23828 KB Output is correct
25 Correct 1165 ms 53872 KB Output is correct
26 Correct 1039 ms 53852 KB Output is correct
27 Correct 937 ms 53920 KB Output is correct
28 Correct 705 ms 53228 KB Output is correct
29 Correct 189 ms 18828 KB Output is correct
30 Correct 133 ms 17936 KB Output is correct
31 Correct 1512 ms 53700 KB Output is correct
32 Correct 1224 ms 53784 KB Output is correct
33 Correct 1190 ms 53920 KB Output is correct
34 Correct 327 ms 24992 KB Output is correct
35 Correct 1056 ms 53804 KB Output is correct
36 Correct 262 ms 23896 KB Output is correct
37 Correct 1386 ms 53836 KB Output is correct
38 Correct 1240 ms 53836 KB Output is correct
39 Correct 1612 ms 53836 KB Output is correct
40 Correct 950 ms 53276 KB Output is correct
41 Correct 202 ms 18916 KB Output is correct
42 Correct 126 ms 17912 KB Output is correct
43 Correct 1499 ms 55992 KB Output is correct
44 Correct 1563 ms 56024 KB Output is correct
45 Correct 1482 ms 56040 KB Output is correct
46 Correct 374 ms 25080 KB Output is correct
47 Correct 1076 ms 56068 KB Output is correct
48 Correct 266 ms 23676 KB Output is correct
49 Correct 1606 ms 56028 KB Output is correct
50 Correct 1454 ms 56004 KB Output is correct
51 Correct 1719 ms 56124 KB Output is correct
52 Correct 995 ms 55980 KB Output is correct
53 Correct 222 ms 19392 KB Output is correct