답안 #1099968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099968 2024-10-12T09:35:37 Z Nurislam Examination (JOI19_examination) C++17
0 / 100
86 ms 58856 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>  
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define ordst tree<int,  null_type,  less_equal<int>,  rb_tree_tag ,  tree_order_statistics_node_update >
template <class F, class _S>
bool chmin(F &u, const _S &v){
	bool flag = false;
	if ( u > v ){
		u = v; flag |= true;
	}
	return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
	bool flag = false;
	if ( u < v ){
		u = v; flag |= true;
	}
	return flag;
}

const int N = 2e5+50, inf = LLONG_MAX;
//int mod = 998244353;
//int mod = 1000000007;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)
vector<ordst> t(N);
void upd(int i, int v){
	i = N-i-1;
	for(; i < N; i+= (i&-i))t[i].insert(v);
}
int get(int i, int v){
	int r = 0;
	i = N-i-1;
	for(;i; i+= (i&-i))r += (t[i].size() - t[i].order_of_key(v));
	return r;
}
void solve(){
	int n, m;
	cin >> n >> m;
	
	vector<array<int,2>>v(n);
	vector<int>a,b;
	vector<int>r,rt;
	for(int i = 0;i<n;i++){
		cin >> v[i][0] >> v[i][1];
		r.pb(v[i][1]);
		rt.pb(v[i][0]+v[i][1]);
	}
	
	sort(all(v));
	sort(all(r));
	sort(all(rt));
	for(int i = 0;i<n;i++){
		a.pb(v[i][1]);
		b.pb(v[i][1]+v[i][0]);
	}
	
	vector<array<int,4>>q(m);
	for(int i = 0;i<m;i++){
		cin >> q[i][0] >> q[i][1] >> q[i][2];
		q[i][3] = i; 
	}
	vector<int>ans(m);
	sort(rall(q));
	
	int cur = n - 1;
	
	for(int i = 0;i<m;i++){
		while(cur >= 0 && v[cur][0] >= q[i][0]){
			int x = lower_bound(all(r), a[cur]) - r.begin();
			int y = lower_bound(all(rt), b[cur]) - rt.begin();
			upd(x, y);
			cur -= 1;
		}
		int k = lower_bound(all(r), q[i][1]) - r.begin();
		int l = lower_bound(all(rt), q[i][2]) - rt.begin();
		ans[q[i][3]] = get(k, l);
		
	}
	
	for(auto to:ans)cout << to << "\n";
	
	
}
signed main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);cout.tie(NULL);
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 38484 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 58856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 58856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 38484 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -