답안 #997865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997865 2024-06-13T03:57:04 Z _shr104 Examination (JOI19_examination) C++17
0 / 100
315 ms 20516 KB
#include <bits/stdc++.h>
using namespace std;
typedef 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.y != b.y) return a.y < b.y;
        else if (a.z != b.z) return a.z < b.z;
        else if (a.v != b.v) return a.v > b.v;
        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 <= n; i++) b[i] = 0;}
    ll l_bit(ll x) {return x&(-x);}
    void upd(ll x, ll v) {for (ll i = x; i <= n; i += l_bit(i)) {b[i] += v;}}
    ll get(ll x) {ll ans = 0; for (ll i = x; i > 0; 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] += sum-bit.get(v[b].z-1);
            tmp.pb(v[b++]);
        }
    }
    while (a < m) tmp.pb(v[a++]);
    while (b < r) {ans[v[b].i] += sum-bit.get(v[b].z-1); 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 1 ms 3672 KB Output is correct
2 Correct 1 ms 3672 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 1 ms 3676 KB Output is correct
6 Correct 1 ms 3928 KB Output is correct
7 Correct 7 ms 4220 KB Output is correct
8 Correct 7 ms 4188 KB Output is correct
9 Correct 8 ms 4188 KB Output is correct
10 Correct 7 ms 4188 KB Output is correct
11 Incorrect 6 ms 4224 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 315 ms 20516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 315 ms 20516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 1 ms 3672 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 1 ms 3676 KB Output is correct
6 Correct 1 ms 3928 KB Output is correct
7 Correct 7 ms 4220 KB Output is correct
8 Correct 7 ms 4188 KB Output is correct
9 Correct 8 ms 4188 KB Output is correct
10 Correct 7 ms 4188 KB Output is correct
11 Incorrect 6 ms 4224 KB Output isn't correct
12 Halted 0 ms 0 KB -