답안 #613445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
613445 2022-07-30T05:03:14 Z amunduzbaev Examination (JOI19_examination) C++17
22 / 100
3000 ms 436332 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 ST2{
	ST tree[N << 2];
	void add(int i, int v, int lx = 0, int rx = N, int x = 1){
		tree[x].add(v, 1);
		if(lx == rx) return;
		int m = (lx + rx) >> 1;
		if(i <= m) add(i, v, lx, m, x << 1);
		else add(i, v, m + 1, rx, x << 1 | 1);
	}
	
	int get(int l, int v, int lx = 0, int rx = N, int x = 1){
		if(rx < l) return 0;
		if(lx >= l){
			return tree[x].get(v, N);
		} int m = (lx + rx) >> 1;
		return get(l, v, lx, m, x << 1) + get(l, v, m + 1, rx, x << 1 | 1);
	}
}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";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 25348 KB Output is correct
2 Correct 36 ms 25284 KB Output is correct
3 Correct 29 ms 25412 KB Output is correct
4 Correct 45 ms 25312 KB Output is correct
5 Correct 45 ms 25388 KB Output is correct
6 Correct 40 ms 25336 KB Output is correct
7 Correct 86 ms 34992 KB Output is correct
8 Correct 66 ms 35160 KB Output is correct
9 Correct 74 ms 35044 KB Output is correct
10 Correct 61 ms 27928 KB Output is correct
11 Correct 76 ms 31148 KB Output is correct
12 Correct 61 ms 25596 KB Output is correct
13 Correct 90 ms 34992 KB Output is correct
14 Correct 96 ms 35000 KB Output is correct
15 Correct 102 ms 35064 KB Output is correct
16 Correct 75 ms 31188 KB Output is correct
17 Correct 59 ms 27376 KB Output is correct
18 Correct 39 ms 25540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2580 ms 435132 KB Output is correct
2 Correct 2357 ms 435632 KB Output is correct
3 Correct 2523 ms 435180 KB Output is correct
4 Correct 717 ms 73908 KB Output is correct
5 Correct 1552 ms 151568 KB Output is correct
6 Correct 486 ms 30784 KB Output is correct
7 Correct 2487 ms 435836 KB Output is correct
8 Correct 2411 ms 435544 KB Output is correct
9 Correct 2464 ms 435728 KB Output is correct
10 Correct 1714 ms 147448 KB Output is correct
11 Correct 642 ms 58076 KB Output is correct
12 Correct 424 ms 30396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2580 ms 435132 KB Output is correct
2 Correct 2357 ms 435632 KB Output is correct
3 Correct 2523 ms 435180 KB Output is correct
4 Correct 717 ms 73908 KB Output is correct
5 Correct 1552 ms 151568 KB Output is correct
6 Correct 486 ms 30784 KB Output is correct
7 Correct 2487 ms 435836 KB Output is correct
8 Correct 2411 ms 435544 KB Output is correct
9 Correct 2464 ms 435728 KB Output is correct
10 Correct 1714 ms 147448 KB Output is correct
11 Correct 642 ms 58076 KB Output is correct
12 Correct 424 ms 30396 KB Output is correct
13 Correct 2780 ms 435612 KB Output is correct
14 Correct 2801 ms 435692 KB Output is correct
15 Correct 2477 ms 435360 KB Output is correct
16 Correct 854 ms 72592 KB Output is correct
17 Correct 1829 ms 151752 KB Output is correct
18 Correct 474 ms 30760 KB Output is correct
19 Correct 2728 ms 436332 KB Output is correct
20 Correct 2749 ms 435668 KB Output is correct
21 Execution timed out 3003 ms 435648 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 25348 KB Output is correct
2 Correct 36 ms 25284 KB Output is correct
3 Correct 29 ms 25412 KB Output is correct
4 Correct 45 ms 25312 KB Output is correct
5 Correct 45 ms 25388 KB Output is correct
6 Correct 40 ms 25336 KB Output is correct
7 Correct 86 ms 34992 KB Output is correct
8 Correct 66 ms 35160 KB Output is correct
9 Correct 74 ms 35044 KB Output is correct
10 Correct 61 ms 27928 KB Output is correct
11 Correct 76 ms 31148 KB Output is correct
12 Correct 61 ms 25596 KB Output is correct
13 Correct 90 ms 34992 KB Output is correct
14 Correct 96 ms 35000 KB Output is correct
15 Correct 102 ms 35064 KB Output is correct
16 Correct 75 ms 31188 KB Output is correct
17 Correct 59 ms 27376 KB Output is correct
18 Correct 39 ms 25540 KB Output is correct
19 Correct 2580 ms 435132 KB Output is correct
20 Correct 2357 ms 435632 KB Output is correct
21 Correct 2523 ms 435180 KB Output is correct
22 Correct 717 ms 73908 KB Output is correct
23 Correct 1552 ms 151568 KB Output is correct
24 Correct 486 ms 30784 KB Output is correct
25 Correct 2487 ms 435836 KB Output is correct
26 Correct 2411 ms 435544 KB Output is correct
27 Correct 2464 ms 435728 KB Output is correct
28 Correct 1714 ms 147448 KB Output is correct
29 Correct 642 ms 58076 KB Output is correct
30 Correct 424 ms 30396 KB Output is correct
31 Correct 2780 ms 435612 KB Output is correct
32 Correct 2801 ms 435692 KB Output is correct
33 Correct 2477 ms 435360 KB Output is correct
34 Correct 854 ms 72592 KB Output is correct
35 Correct 1829 ms 151752 KB Output is correct
36 Correct 474 ms 30760 KB Output is correct
37 Correct 2728 ms 436332 KB Output is correct
38 Correct 2749 ms 435668 KB Output is correct
39 Execution timed out 3003 ms 435648 KB Time limit exceeded
40 Halted 0 ms 0 KB -