답안 #998252

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998252 2024-06-13T12:41:45 Z _shr104 Examination (JOI19_examination) C++17
100 / 100
434 ms 45300 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';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 2 ms 5212 KB Output is correct
3 Correct 2 ms 5116 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 9 ms 6268 KB Output is correct
8 Correct 10 ms 6352 KB Output is correct
9 Correct 9 ms 6352 KB Output is correct
10 Correct 8 ms 6352 KB Output is correct
11 Correct 8 ms 6300 KB Output is correct
12 Correct 7 ms 6352 KB Output is correct
13 Correct 9 ms 6328 KB Output is correct
14 Correct 10 ms 6380 KB Output is correct
15 Correct 9 ms 6384 KB Output is correct
16 Correct 7 ms 6368 KB Output is correct
17 Correct 9 ms 6416 KB Output is correct
18 Correct 6 ms 6160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 330 ms 44160 KB Output is correct
2 Correct 330 ms 42600 KB Output is correct
3 Correct 359 ms 41300 KB Output is correct
4 Correct 283 ms 42960 KB Output is correct
5 Correct 266 ms 40456 KB Output is correct
6 Correct 198 ms 43472 KB Output is correct
7 Correct 315 ms 41936 KB Output is correct
8 Correct 317 ms 43984 KB Output is correct
9 Correct 309 ms 44664 KB Output is correct
10 Correct 240 ms 42960 KB Output is correct
11 Correct 261 ms 40652 KB Output is correct
12 Correct 170 ms 42192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 330 ms 44160 KB Output is correct
2 Correct 330 ms 42600 KB Output is correct
3 Correct 359 ms 41300 KB Output is correct
4 Correct 283 ms 42960 KB Output is correct
5 Correct 266 ms 40456 KB Output is correct
6 Correct 198 ms 43472 KB Output is correct
7 Correct 315 ms 41936 KB Output is correct
8 Correct 317 ms 43984 KB Output is correct
9 Correct 309 ms 44664 KB Output is correct
10 Correct 240 ms 42960 KB Output is correct
11 Correct 261 ms 40652 KB Output is correct
12 Correct 170 ms 42192 KB Output is correct
13 Correct 434 ms 42928 KB Output is correct
14 Correct 412 ms 43948 KB Output is correct
15 Correct 360 ms 41164 KB Output is correct
16 Correct 352 ms 43364 KB Output is correct
17 Correct 352 ms 43952 KB Output is correct
18 Correct 195 ms 45000 KB Output is correct
19 Correct 405 ms 44220 KB Output is correct
20 Correct 419 ms 43824 KB Output is correct
21 Correct 419 ms 43204 KB Output is correct
22 Correct 232 ms 41936 KB Output is correct
23 Correct 255 ms 44108 KB Output is correct
24 Correct 179 ms 40396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 2 ms 5212 KB Output is correct
3 Correct 2 ms 5116 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 9 ms 6268 KB Output is correct
8 Correct 10 ms 6352 KB Output is correct
9 Correct 9 ms 6352 KB Output is correct
10 Correct 8 ms 6352 KB Output is correct
11 Correct 8 ms 6300 KB Output is correct
12 Correct 7 ms 6352 KB Output is correct
13 Correct 9 ms 6328 KB Output is correct
14 Correct 10 ms 6380 KB Output is correct
15 Correct 9 ms 6384 KB Output is correct
16 Correct 7 ms 6368 KB Output is correct
17 Correct 9 ms 6416 KB Output is correct
18 Correct 6 ms 6160 KB Output is correct
19 Correct 330 ms 44160 KB Output is correct
20 Correct 330 ms 42600 KB Output is correct
21 Correct 359 ms 41300 KB Output is correct
22 Correct 283 ms 42960 KB Output is correct
23 Correct 266 ms 40456 KB Output is correct
24 Correct 198 ms 43472 KB Output is correct
25 Correct 315 ms 41936 KB Output is correct
26 Correct 317 ms 43984 KB Output is correct
27 Correct 309 ms 44664 KB Output is correct
28 Correct 240 ms 42960 KB Output is correct
29 Correct 261 ms 40652 KB Output is correct
30 Correct 170 ms 42192 KB Output is correct
31 Correct 434 ms 42928 KB Output is correct
32 Correct 412 ms 43948 KB Output is correct
33 Correct 360 ms 41164 KB Output is correct
34 Correct 352 ms 43364 KB Output is correct
35 Correct 352 ms 43952 KB Output is correct
36 Correct 195 ms 45000 KB Output is correct
37 Correct 405 ms 44220 KB Output is correct
38 Correct 419 ms 43824 KB Output is correct
39 Correct 419 ms 43204 KB Output is correct
40 Correct 232 ms 41936 KB Output is correct
41 Correct 255 ms 44108 KB Output is correct
42 Correct 179 ms 40396 KB Output is correct
43 Correct 417 ms 43252 KB Output is correct
44 Correct 424 ms 44464 KB Output is correct
45 Correct 413 ms 43216 KB Output is correct
46 Correct 368 ms 41416 KB Output is correct
47 Correct 378 ms 42700 KB Output is correct
48 Correct 201 ms 41936 KB Output is correct
49 Correct 396 ms 45300 KB Output is correct
50 Correct 371 ms 44236 KB Output is correct
51 Correct 398 ms 43972 KB Output is correct
52 Correct 344 ms 44996 KB Output is correct
53 Correct 267 ms 42444 KB Output is correct