Submission #998254

# Submission time Handle Problem Language Result Execution time Memory
998254 2024-06-13T12:42:45 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
424 ms 46284 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;
        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';
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 2 ms 5212 KB Output is correct
5 Correct 2 ms 5212 KB Output is correct
6 Correct 2 ms 5212 KB Output is correct
7 Correct 10 ms 6340 KB Output is correct
8 Correct 10 ms 6352 KB Output is correct
9 Correct 9 ms 6352 KB Output is correct
10 Correct 9 ms 6352 KB Output is correct
11 Correct 8 ms 6416 KB Output is correct
12 Correct 7 ms 6352 KB Output is correct
13 Correct 9 ms 6296 KB Output is correct
14 Correct 9 ms 6384 KB Output is correct
15 Correct 12 ms 6352 KB Output is correct
16 Correct 7 ms 6368 KB Output is correct
17 Correct 8 ms 6308 KB Output is correct
18 Correct 7 ms 6156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 347 ms 42152 KB Output is correct
2 Correct 346 ms 42444 KB Output is correct
3 Correct 340 ms 43980 KB Output is correct
4 Correct 299 ms 42388 KB Output is correct
5 Correct 263 ms 42192 KB Output is correct
6 Correct 198 ms 40392 KB Output is correct
7 Correct 316 ms 41720 KB Output is correct
8 Correct 315 ms 42828 KB Output is correct
9 Correct 310 ms 43888 KB Output is correct
10 Correct 240 ms 41928 KB Output is correct
11 Correct 265 ms 43980 KB Output is correct
12 Correct 168 ms 40144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 347 ms 42152 KB Output is correct
2 Correct 346 ms 42444 KB Output is correct
3 Correct 340 ms 43980 KB Output is correct
4 Correct 299 ms 42388 KB Output is correct
5 Correct 263 ms 42192 KB Output is correct
6 Correct 198 ms 40392 KB Output is correct
7 Correct 316 ms 41720 KB Output is correct
8 Correct 315 ms 42828 KB Output is correct
9 Correct 310 ms 43888 KB Output is correct
10 Correct 240 ms 41928 KB Output is correct
11 Correct 265 ms 43980 KB Output is correct
12 Correct 168 ms 40144 KB Output is correct
13 Correct 405 ms 44492 KB Output is correct
14 Correct 393 ms 41116 KB Output is correct
15 Correct 336 ms 44236 KB Output is correct
16 Correct 355 ms 42700 KB Output is correct
17 Correct 348 ms 43524 KB Output is correct
18 Correct 189 ms 41620 KB Output is correct
19 Correct 411 ms 42248 KB Output is correct
20 Correct 416 ms 44196 KB Output is correct
21 Correct 412 ms 42616 KB Output is correct
22 Correct 268 ms 43468 KB Output is correct
23 Correct 261 ms 42704 KB Output is correct
24 Correct 162 ms 44304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 2 ms 5212 KB Output is correct
5 Correct 2 ms 5212 KB Output is correct
6 Correct 2 ms 5212 KB Output is correct
7 Correct 10 ms 6340 KB Output is correct
8 Correct 10 ms 6352 KB Output is correct
9 Correct 9 ms 6352 KB Output is correct
10 Correct 9 ms 6352 KB Output is correct
11 Correct 8 ms 6416 KB Output is correct
12 Correct 7 ms 6352 KB Output is correct
13 Correct 9 ms 6296 KB Output is correct
14 Correct 9 ms 6384 KB Output is correct
15 Correct 12 ms 6352 KB Output is correct
16 Correct 7 ms 6368 KB Output is correct
17 Correct 8 ms 6308 KB Output is correct
18 Correct 7 ms 6156 KB Output is correct
19 Correct 347 ms 42152 KB Output is correct
20 Correct 346 ms 42444 KB Output is correct
21 Correct 340 ms 43980 KB Output is correct
22 Correct 299 ms 42388 KB Output is correct
23 Correct 263 ms 42192 KB Output is correct
24 Correct 198 ms 40392 KB Output is correct
25 Correct 316 ms 41720 KB Output is correct
26 Correct 315 ms 42828 KB Output is correct
27 Correct 310 ms 43888 KB Output is correct
28 Correct 240 ms 41928 KB Output is correct
29 Correct 265 ms 43980 KB Output is correct
30 Correct 168 ms 40144 KB Output is correct
31 Correct 405 ms 44492 KB Output is correct
32 Correct 393 ms 41116 KB Output is correct
33 Correct 336 ms 44236 KB Output is correct
34 Correct 355 ms 42700 KB Output is correct
35 Correct 348 ms 43524 KB Output is correct
36 Correct 189 ms 41620 KB Output is correct
37 Correct 411 ms 42248 KB Output is correct
38 Correct 416 ms 44196 KB Output is correct
39 Correct 412 ms 42616 KB Output is correct
40 Correct 268 ms 43468 KB Output is correct
41 Correct 261 ms 42704 KB Output is correct
42 Correct 162 ms 44304 KB Output is correct
43 Correct 424 ms 46284 KB Output is correct
44 Correct 416 ms 44024 KB Output is correct
45 Correct 421 ms 45004 KB Output is correct
46 Correct 367 ms 45004 KB Output is correct
47 Correct 356 ms 45008 KB Output is correct
48 Correct 195 ms 41420 KB Output is correct
49 Correct 401 ms 45860 KB Output is correct
50 Correct 408 ms 44492 KB Output is correct
51 Correct 372 ms 43980 KB Output is correct
52 Correct 345 ms 42704 KB Output is correct
53 Correct 267 ms 41576 KB Output is correct