이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
const int N = 100001;
const int A = 200001;
const int INF = (int)1e9;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree <pair <int, int>, null_type, less <pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
struct query{
int A, B, ind;
};
int n, m, x[N], y[N], z[N];
vector <pair <int, int> > a;
ordered_set v[4 * N];
void insert(ordered_set &s, int v){
auto it = s.upper_bound(make_pair(v, INF));
if(it == s.begin()){
s.insert(make_pair(v, 0));
return;
}
it--;
if(it == s.end() || (*it).first != v) s.insert(make_pair(v, 0));
else s.insert(make_pair(v, (*it).second + 1));
}
void erase(ordered_set &s, int v){
auto it = s.upper_bound(make_pair(v, INF));
assert(it != s.begin());
it--;
assert((*it).first == v);
s.erase(it);
}
void update(int l, int r, int node, int ind, int val){
if(r < l || l > ind || r < ind) return;
insert(v[node], val);
if(l == r) return;
int mid = (l + r) / 2;
if(ind <= mid) update(l, mid, 2 * node, ind, val);
update(mid + 1, r, 2 * node + 1, ind, val);
}
int query(int l, int r, int node, int s, int e, int val){
if(r < l || r < s || l > e) return 0;
if(s <= l && r <= e){
return (int)v[node].size() - v[node].order_of_key(make_pair(val, -INF));
}
int mid = (l + r) / 2;
return query(l, mid, 2 * node, s, e, val) + query(mid + 1, r, 2 * node + 1, s, e, val);
}
void erase(int l, int r, int node, int ind){
if(r < l) return;
erase(v[node], a[ind].second);
if(l == r) return;
int mid = (l + r) / 2;
if(ind <= mid) erase(l, mid, 2 * node, ind);
else erase(mid + 1, r, 2 * node + 1, ind);
}
int query(int suffix, int val){
return query(0, n - 1, 1, suffix, n - 1, val);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
a.resize(n);
for(auto &i : a) cin >> i.first >> i.second;
sort(a.begin(), a.end());
for(int i = 0 ; i < n ; i++){
update(0, n - 1, 1, i, a[i].second);
}
vector <pair <int, pair <int, int> > > all;
for(int i = 0 ; i < n ; i++){
all.push_back(make_pair(a[i].first + a[i].second, make_pair(1, i)));
}
for(int i = 0 ; i < m ; i++){
cin >> x[i] >> y[i] >> z[i];
all.push_back(make_pair(z[i], make_pair(0, i)));
}
vector <int> ans(m);
sort(all.begin(), all.end());
for(auto &i : all){
if(i.second.first == 1) erase(0, n - 1, 1, i.second.second);
else{
int j = i.second.second;
int suff = lower_bound(a.begin(), a.end(), make_pair(x[j], -INF)) - a.begin();
if(suff == n) ans[j] = 0;
else ans[j] = query(suff, y[j]);
}
}
for(auto &i : ans) cout << i << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |