Submission #1102156

# Submission time Handle Problem Language Result Execution time Memory
1102156 2024-10-17T14:54:29 Z _shr104 Examination (JOI19_examination) C++14
100 / 100
455 ms 44964 KB
#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;
        return a.v > b.v;
    }
};
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';
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5204 KB Output is correct
2 Correct 4 ms 5204 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 3 ms 5204 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 3 ms 5092 KB Output is correct
7 Correct 12 ms 6500 KB Output is correct
8 Correct 14 ms 6304 KB Output is correct
9 Correct 15 ms 6344 KB Output is correct
10 Correct 12 ms 6356 KB Output is correct
11 Correct 11 ms 6452 KB Output is correct
12 Correct 9 ms 6256 KB Output is correct
13 Correct 11 ms 6408 KB Output is correct
14 Correct 11 ms 6224 KB Output is correct
15 Correct 12 ms 6224 KB Output is correct
16 Correct 9 ms 6316 KB Output is correct
17 Correct 11 ms 6424 KB Output is correct
18 Correct 9 ms 6164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 360 ms 42636 KB Output is correct
2 Correct 343 ms 42444 KB Output is correct
3 Correct 343 ms 42524 KB Output is correct
4 Correct 287 ms 41672 KB Output is correct
5 Correct 268 ms 41828 KB Output is correct
6 Correct 192 ms 40908 KB Output is correct
7 Correct 308 ms 42364 KB Output is correct
8 Correct 306 ms 42440 KB Output is correct
9 Correct 295 ms 42324 KB Output is correct
10 Correct 255 ms 41672 KB Output is correct
11 Correct 255 ms 41676 KB Output is correct
12 Correct 175 ms 40908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 360 ms 42636 KB Output is correct
2 Correct 343 ms 42444 KB Output is correct
3 Correct 343 ms 42524 KB Output is correct
4 Correct 287 ms 41672 KB Output is correct
5 Correct 268 ms 41828 KB Output is correct
6 Correct 192 ms 40908 KB Output is correct
7 Correct 308 ms 42364 KB Output is correct
8 Correct 306 ms 42440 KB Output is correct
9 Correct 295 ms 42324 KB Output is correct
10 Correct 255 ms 41672 KB Output is correct
11 Correct 255 ms 41676 KB Output is correct
12 Correct 175 ms 40908 KB Output is correct
13 Correct 428 ms 42880 KB Output is correct
14 Correct 434 ms 42952 KB Output is correct
15 Correct 370 ms 42412 KB Output is correct
16 Correct 396 ms 42176 KB Output is correct
17 Correct 395 ms 42184 KB Output is correct
18 Correct 263 ms 41164 KB Output is correct
19 Correct 455 ms 42964 KB Output is correct
20 Correct 428 ms 42840 KB Output is correct
21 Correct 437 ms 44000 KB Output is correct
22 Correct 278 ms 41672 KB Output is correct
23 Correct 274 ms 42128 KB Output is correct
24 Correct 182 ms 41012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5204 KB Output is correct
2 Correct 4 ms 5204 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 3 ms 5204 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 3 ms 5092 KB Output is correct
7 Correct 12 ms 6500 KB Output is correct
8 Correct 14 ms 6304 KB Output is correct
9 Correct 15 ms 6344 KB Output is correct
10 Correct 12 ms 6356 KB Output is correct
11 Correct 11 ms 6452 KB Output is correct
12 Correct 9 ms 6256 KB Output is correct
13 Correct 11 ms 6408 KB Output is correct
14 Correct 11 ms 6224 KB Output is correct
15 Correct 12 ms 6224 KB Output is correct
16 Correct 9 ms 6316 KB Output is correct
17 Correct 11 ms 6424 KB Output is correct
18 Correct 9 ms 6164 KB Output is correct
19 Correct 360 ms 42636 KB Output is correct
20 Correct 343 ms 42444 KB Output is correct
21 Correct 343 ms 42524 KB Output is correct
22 Correct 287 ms 41672 KB Output is correct
23 Correct 268 ms 41828 KB Output is correct
24 Correct 192 ms 40908 KB Output is correct
25 Correct 308 ms 42364 KB Output is correct
26 Correct 306 ms 42440 KB Output is correct
27 Correct 295 ms 42324 KB Output is correct
28 Correct 255 ms 41672 KB Output is correct
29 Correct 255 ms 41676 KB Output is correct
30 Correct 175 ms 40908 KB Output is correct
31 Correct 428 ms 42880 KB Output is correct
32 Correct 434 ms 42952 KB Output is correct
33 Correct 370 ms 42412 KB Output is correct
34 Correct 396 ms 42176 KB Output is correct
35 Correct 395 ms 42184 KB Output is correct
36 Correct 263 ms 41164 KB Output is correct
37 Correct 455 ms 42964 KB Output is correct
38 Correct 428 ms 42840 KB Output is correct
39 Correct 437 ms 44000 KB Output is correct
40 Correct 278 ms 41672 KB Output is correct
41 Correct 274 ms 42128 KB Output is correct
42 Correct 182 ms 41012 KB Output is correct
43 Correct 451 ms 44920 KB Output is correct
44 Correct 444 ms 44964 KB Output is correct
45 Correct 447 ms 44864 KB Output is correct
46 Correct 362 ms 43216 KB Output is correct
47 Correct 361 ms 43212 KB Output is correct
48 Correct 258 ms 41164 KB Output is correct
49 Correct 395 ms 44664 KB Output is correct
50 Correct 408 ms 44748 KB Output is correct
51 Correct 403 ms 44748 KB Output is correct
52 Correct 361 ms 43220 KB Output is correct
53 Correct 269 ms 42440 KB Output is correct