#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 3e5+14;
struct point {ll x, y, z, v, i;};
struct cmp
{
bool operator() (point a, point b)
{
if (a.x != b.x) return a.x > b.x;
else if (a.v != b.v) return a.v > b.v;
else if (a.y != b.y) return a.y > b.y;
else if (a.z != b.z) return a.z < b.z;
return a.i < b.i;
}
};
struct binary_indexed_tree
{
ll b[mxn], n;
binary_indexed_tree() {}
binary_indexed_tree(ll _n) {n = _n; for (ll i = 0; i < mxn; i++) b[i] = 0;}
ll l_bit(ll x) {return x&(-x);}
void upd(ll x, ll v) {for (ll i = x; i > 0; i -= l_bit(i)) {b[i] += v;}}
ll get(ll x) {ll ans = 0; for (ll i = x; i <= mxn; i += l_bit(i)) {ans += b[i];} return ans;}
} bit;
vector<point> v;
ll n, mm, ans[mxn];
void cdq(ll l, ll r)
{
if (l+1 == r) return;
ll m = (r+l)>>1;
cdq(l,m); cdq(m,r);
ll a = l, b = m, sum = 0;
vector<pair<ll,ll>> record; vector<point> tmp;
while (a < m && b < r)
{
if (v[a].y >= v[b].y)
{
bit.upd(v[a].z,v[a].v); sum += v[a].v;
record.pb({v[a].z,v[a].v}); tmp.pb(v[a++]);
}
else
{
ans[v[b].i] += bit.get(v[b].z);
tmp.pb(v[b++]);
}
}
while (a < m) tmp.pb(v[a++]);
while (b < r) {ans[v[b].i] += bit.get(v[b].z); tmp.pb(v[b++]);}
for (ll i = l; i < r; i++) v[i] = tmp[i-l];
for (pair<ll,ll> i : record) bit.upd(i.fi,-i.se);
record.clear(); tmp.clear();
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
cin >> n >> mm;
vector<ll> sort_x, sort_y, sort_z;
for (ll i = 0; i < n; i++)
{
ll a, b; cin >> a >> b;
v.pb({a,b,a+b,1,i});
sort_x.pb(a); sort_y.pb(b); sort_z.pb(a+b);
}
for (ll i = n; i < n+mm; i++)
{
ll a, b, c; cin >> a >> b >> c;
v.pb({a,b,c,0,i});
sort_x.pb(a); sort_y.pb(b); sort_z.pb(c);
}
sort(sort_x.begin(),sort_x.end());
sort(sort_y.begin(),sort_y.end());
sort(sort_z.begin(),sort_z.end());
for (point& i : v)
{
i.x = lower_bound(sort_x.begin(),sort_x.end(),i.x)-sort_x.begin()+1;
i.y = lower_bound(sort_y.begin(),sort_y.end(),i.y)-sort_y.begin()+1;
i.z = lower_bound(sort_z.begin(),sort_z.end(),i.z)-sort_z.begin()+1;
// cerr << i.x << ' ' << i.y << ' ' << i.z << '\n';
}
bit = binary_indexed_tree(n+mm+7);
sort(v.begin(),v.end(),cmp()); cdq(0,n+mm);
for (ll i = n; i < n+mm; i++) cout << ans[i] << '\n';
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:62:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:62:43: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:62:75: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
515 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
602 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
602 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
515 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |