#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;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define endl '\n'
#define pb push_back
#define conts continue
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define ff first
#define ss second
#define ceil2(x,y) ((x+y-1) / (y))
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x <<" = "; print(x); cout << endl
#else
#define debug(x)
#endif
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define trav(i,a) for(auto &i : a)
bool iseven(ll n) {if ((n & 1) == 0) return true; return false;}
void print(ll t) {cout << t;}
void print(int t) {cout << t;}
void print(string t) {cout << t;}
void print(char t) {cout << t;}
void print(double t) {cout << t;}
void print(ld t) {cout << t;}
template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T, class V> void print(pair <T, V> p) {cout << "{"; print(p.ff); cout << ","; print(p.ss); cout << "}";}
template <class T> void print(vector <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T> void print(set <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T> void print(multiset <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T, class V> void print(map <T, V> v) {cout << "[ "; for (auto i : v) {print(i); cout << " ";} cout << "]";}
void usaco(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 5;
const int inf1 = 1e9 + 5;
const ll inf2 = ll(1e18) + 5;
template<typename T, int sp>
struct segtree {
/*=======================================================*/
struct data {
Tree<pair<int, int>> os;
};
data neutral = {};
void merge(data &curr, data &left, data &right) {
}
void create(int x, int lx, int rx, T v) {
}
void modify(int x, int lx, int rx, T v) {
}
/*=======================================================*/
int siz = 1;
vector<data> tr;
segtree(int n) {
init(n);
}
segtree() {
};
void init(int n) {
while (siz < n) siz *= 2;
tr.assign(2 * siz, neutral);
}
void build(vector<T> &a, int n, int x, int lx, int rx) {
if (rx - lx == 1) {
if (lx >= sp and lx < n) {
create(x, lx, rx, a[lx]);
}
return;
}
int mid = (lx + rx) / 2;
build(a, n, 2 * x + 1, lx, mid);
build(a, n, 2 * x + 2, mid, rx);
merge(tr[x], tr[2 * x + 1], tr[2 * x + 2]);
}
void build(vector<T> &a, int n) {
build(a, n, 0, 0, siz);
}
void pupd(int i, T v, int x, int lx, int rx) {
if (rx - lx == 1) {
tr[x].os.insert({v, i});
return;
}
int mid = (lx + rx) / 2;
if (i < mid) {
pupd(i, v, 2 * x + 1, lx, mid);
}
else {
pupd(i, v, 2 * x + 2, mid, rx);
}
tr[x].os.insert({v, i});
}
void pupd(int i, T v) {
pupd(i, v, 0, 0, siz);
}
int query(int l, int r, int k, int x, int lx, int rx) {
if (lx >= r or rx <= l) return 0;
if (lx >= l and rx <= r){
auto &curr = tr[x].os;
int less = curr.order_of_key({k, -inf1});
int res = sz(curr) - less;
return res;
}
int mid = (lx + rx) / 2;
int curr;
int left = query(l, r, k, 2 * x + 1, lx, mid);
int right = query(l, r, k, 2 * x + 2, mid, rx);
curr = left + right;
return curr;
}
int query(int l, int r, int k) {
return query(l, r + 1, k, 0, 0, siz);
}
};
void solve(int test_case)
{
int n, q; cin >> n >> q;
vector<pair<int, int>> a(n);
rep(i, n) cin >> a[i].ff >> a[i].ss;
auto comp = [&](pair<int, int> &p1, pair<int, int> &p2) {
if (p1.ff + p1.ss > p2.ff + p2.ss) {
return true;
}
return false;
};
sort(all(a), comp);
vector<array<int, 4>> queries(n);
rep(i, q) {
int x, y, z; cin >> x >> y >> z;
queries[i] = {z, x, y, i};
}
sort(rall(queries));
vector<int> b;
rep(i, n) b.pb(a[i].ff);
rep(i, q) b.pb(queries[i][1]);
sort(all(b));
auto it = unique(all(b));
b.resize(it - b.begin());
int siz = sz(b);
segtree<int,0> st(siz + 5);
int ptr = 0;
vector<int> ans(q);
rep(i, q) {
auto [z, x, y, id] = queries[i];
while (ptr < n) {
int sum = a[ptr].ff + a[ptr].ss;
if (sum < z) break;
int idx = lower_bound(all(b), a[ptr].ff) - b.begin();
st.pupd(idx, a[ptr].ss);
ptr++;
}
x = lower_bound(all(b), x) - b.begin();
int res = st.query(x, siz, y);
ans[id] = res;
}
rep(i, q) cout << ans[i] << endl;
}
int main()
{
fastio;
int t = 1;
// cin >> t;
rep1(i, t) {
solve(i);
}
return 0;
}
Compilation message
examination.cpp: In function 'void usaco(std::string)':
examination.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen((filename + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen((filename + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
21 ms |
4660 KB |
Output is correct |
8 |
Correct |
17 ms |
4684 KB |
Output is correct |
9 |
Correct |
17 ms |
4680 KB |
Output is correct |
10 |
Correct |
16 ms |
4632 KB |
Output is correct |
11 |
Correct |
7 ms |
1356 KB |
Output is correct |
12 |
Incorrect |
3 ms |
464 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1910 ms |
144188 KB |
Output is correct |
2 |
Correct |
1842 ms |
144304 KB |
Output is correct |
3 |
Correct |
1816 ms |
144268 KB |
Output is correct |
4 |
Incorrect |
916 ms |
138552 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1910 ms |
144188 KB |
Output is correct |
2 |
Correct |
1842 ms |
144304 KB |
Output is correct |
3 |
Correct |
1816 ms |
144268 KB |
Output is correct |
4 |
Incorrect |
916 ms |
138552 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
21 ms |
4660 KB |
Output is correct |
8 |
Correct |
17 ms |
4684 KB |
Output is correct |
9 |
Correct |
17 ms |
4680 KB |
Output is correct |
10 |
Correct |
16 ms |
4632 KB |
Output is correct |
11 |
Correct |
7 ms |
1356 KB |
Output is correct |
12 |
Incorrect |
3 ms |
464 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |