Submission #966300

# Submission time Handle Problem Language Result Execution time Memory
966300 2024-04-19T16:28:03 Z Trisanu_Das Examination (JOI19_examination) C++17
41 / 100
86 ms 17512 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define int long long
const int N = 2e5 + 5;
 
bool cmp(pair<int, int> a, pair<int, int> b){
	if(a == b) return 0;
	if(a.ff + a.ss > b.ff + b.ss) return 0;
	if(a.ff + a.ss < b.ff + b.ss) return 1;
	if(a.ff > b.ff) return 0;
	return 1;
}
 
int BIT[N], ans[N], cutoffs[N][3];
vector<pair<int, int> > a;
 
void upd(int idx, int val){
	for( ; idx < N; idx |= (idx + 1)) BIT[idx] += val;
}
 
int qry(int idx){
	int ans = 0;
	for(; idx >= 0; idx = (idx & (idx + 1)) - 1) ans += BIT[idx];
	return ans;
}
 
int sum(int l, int r){
	if(l > r) return 0;
	return qry(r) - qry(l - 1);
}
 
signed main(){
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	int n, q; cin >> n >> q;
	for(int i = 0; i < n; i++){
		int s, t; cin >> s >> t;
		a.pb({s, t});
	}
	sort(a.begin(), a.end());
	vector<pair<pair<int, int>, int> > c_sort1;
	for(int i = 0; i < q; i++) cin >> cutoffs[i][0] >> cutoffs[i][1] >> cutoffs[i][2];
	for(int i = 0; i < q; i++)
		if(cutoffs[i][0] + cutoffs[i][1] >= cutoffs[i][2])
			c_sort1.pb({{cutoffs[i][0], cutoffs[i][1]}, i});
	sort(c_sort1.begin(), c_sort1.end());
	int idx = n - 1;
	memset(BIT, 0, sizeof(BIT));
	while(!c_sort1.empty()){
		auto x = c_sort1.back(); c_sort1.pop_back();
		while(idx >= 0 and a[idx].ff >= x.ff.ff){
			upd(a[idx].ss, 1); idx--;
		}
		ans[x.ss] = sum(x.ff.ss, N - 1);
	}
	vector<pair<int, int> > c_sort2;
	for(int i = 0; i < q; i++)
		if(cutoffs[i][0] + cutoffs[i][1] < cutoffs[i][2])
			c_sort2.pb({cutoffs[i][2], i});
	sort(c_sort2.begin(), c_sort2.end());
	sort(a.begin(), a.end(), cmp);
	memset(BIT, 0, sizeof(BIT));
	idx = n - 1;
	for(int i = (int)c_sort2.size() - 1; i >= 0; i--){
		while(idx >= 0 and a[idx].ff + a[idx].ss >= c_sort2[i].ff){
			upd(a[idx].ff, 1);
			idx--;
		}
		ans[c_sort2[i].ss] += n - idx - 1;
		ans[c_sort2[i].ss] -= sum(0, cutoffs[c_sort2[i].ss][0] - 1);
	}
	memset(BIT, 0, sizeof(BIT));
	idx = n - 1;
	for(int i = (int)c_sort2.size() - 1; i >= 0; i--){
		while(idx >= 0 and a[idx].ff + a[idx].ss >= c_sort2[i].ff){
			upd(a[idx].ss, 1);
			idx--;
		}
		ans[c_sort2[i].ss] -= sum(0, cutoffs[c_sort2[i].ss][1] - 1);
	}
	for(int i = 0; i < q; i++) cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3928 KB Output is correct
2 Correct 2 ms 3996 KB Output is correct
3 Correct 1 ms 3932 KB Output is correct
4 Runtime error 4 ms 7600 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 66 ms 17088 KB Output is correct
2 Correct 66 ms 17512 KB Output is correct
3 Correct 68 ms 16612 KB Output is correct
4 Correct 58 ms 16068 KB Output is correct
5 Correct 74 ms 16004 KB Output is correct
6 Correct 52 ms 15268 KB Output is correct
7 Correct 67 ms 16832 KB Output is correct
8 Correct 66 ms 16692 KB Output is correct
9 Correct 67 ms 16612 KB Output is correct
10 Correct 58 ms 16060 KB Output is correct
11 Correct 74 ms 15812 KB Output is correct
12 Correct 46 ms 15044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 17088 KB Output is correct
2 Correct 66 ms 17512 KB Output is correct
3 Correct 68 ms 16612 KB Output is correct
4 Correct 58 ms 16068 KB Output is correct
5 Correct 74 ms 16004 KB Output is correct
6 Correct 52 ms 15268 KB Output is correct
7 Correct 67 ms 16832 KB Output is correct
8 Correct 66 ms 16692 KB Output is correct
9 Correct 67 ms 16612 KB Output is correct
10 Correct 58 ms 16060 KB Output is correct
11 Correct 74 ms 15812 KB Output is correct
12 Correct 46 ms 15044 KB Output is correct
13 Correct 82 ms 16072 KB Output is correct
14 Correct 75 ms 16828 KB Output is correct
15 Correct 66 ms 16632 KB Output is correct
16 Correct 65 ms 15492 KB Output is correct
17 Correct 86 ms 15476 KB Output is correct
18 Correct 74 ms 14872 KB Output is correct
19 Correct 74 ms 16072 KB Output is correct
20 Correct 76 ms 16328 KB Output is correct
21 Correct 75 ms 17348 KB Output is correct
22 Correct 60 ms 15784 KB Output is correct
23 Correct 64 ms 15696 KB Output is correct
24 Correct 47 ms 15040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3928 KB Output is correct
2 Correct 2 ms 3996 KB Output is correct
3 Correct 1 ms 3932 KB Output is correct
4 Runtime error 4 ms 7600 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -