답안 #563492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
563492 2022-05-17T10:35:15 Z hgmhc Examination (JOI19_examination) C++17
100 / 100
252 ms 17632 KB
#include <bits/stdc++.h>
using namespace std; using ii = pair<int,int>; using ll = long long;
void o_o(){ cerr << endl; }
template <class H, class...T> void o_o(H h,T...t) { cerr << ' ' << h; o_o(t...); }
#define debug(...) cerr<<'['<<#__VA_ARGS__<<"]:",o_o(__VA_ARGS__)
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define all(x) (x).begin(), (x).end()
#define size(x) int((x).size())
#define fi first
#define se second

const int N = 1e5+3, Q = 1e5+3;
int n, q;
ll answer[Q];
struct point { int x, y, z, i; } P[N+Q];
template <const int N>
struct fenwick_tree {
    ll t[N+1] {0,};
    void clear() { fill(t,t+N+1,0); }
    void add(int k, ll x) {
        assert(0 <= k and k < N);
        for (++k; k <= N; k += k&-k) t[k] += x;
    }
    ll pfx(int k) {
        ll s = 0;
        for (++k; k >= 1; k -= k&-k) s += t[k];
        return s;
    }
    ll sum(int l, int r) {
        assert(0 <= l and l <= r and r < N);
        if (l == 0) return pfx(r);
        return pfx(r)-pfx(l-1);
    }
};
fenwick_tree<N+Q> ds;

void dnc(int a = 1, int b = n+q) {
    if (a == b) return;
    int m = (a+b)/2;
    dnc(a,m), dnc(m+1,b);
    // [a,m]: x-내림차순 정렬된 상태, [m+1,b]: x-내림차순 정렬된 상태.
    // [a,m]의 모든 점들은 [m+1,b]보다 z값이 크거나 같음.
    vector<point> tmp;
    int i = a, j = m+1;
    while (i <= m and j <= b) {
        if (P[i].x >= P[j].x) {
            if (P[i].i == 0) ds.add(P[i].y,+1);
            tmp.push_back(P[i++]);
        } else {
            if (P[j].i) answer[P[j].i] += ds.sum(P[j].y,N+Q-1);
            tmp.push_back(P[j++]);
        }
    }
    while (i <= m) {
        if (P[i].i == 0) ds.add(P[i].y,+1);
        tmp.push_back(P[i++]);
    }
    while (j <= b) {
        if (P[j].i) answer[P[j].i] += ds.sum(P[j].y,N+Q-1);
        tmp.push_back(P[j++]);
    }
    rep(k,a,m) if (P[k].i == 0) ds.add(P[k].y,-1);
    rep(k,a,b) P[k] = tmp[k-a];
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> q;
    vector<int> ys;
    rep(i,1,n) {
        cin >> P[i].x >> P[i].y;
        ys.push_back(P[i].y);
        P[i].z = P[i].x+P[i].y;
        P[i].i = 0;
    }
    rep(j,n+1,n+q) {
        cin >> P[j].x >> P[j].y >> P[j].z;
        ys.push_back(P[j].y);
        P[j].i = j-n;
    }
    sort(all(ys)), ys.erase(unique(all(ys)),end(ys));
    rep(k,1,n+q) P[k].y = lower_bound(all(ys),P[k].y)-begin(ys);
    sort(P+1,P+n+q+1,[](auto &e1, auto &e2) {
        if (e1.z != e2.z) return e1.z > e2.z;
        return e1.i < e2.i;
    });
    dnc();
    rep(j,1,q) cout << answer[j] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 7 ms 844 KB Output is correct
8 Correct 8 ms 848 KB Output is correct
9 Correct 7 ms 892 KB Output is correct
10 Correct 7 ms 852 KB Output is correct
11 Correct 6 ms 852 KB Output is correct
12 Correct 5 ms 724 KB Output is correct
13 Correct 6 ms 852 KB Output is correct
14 Correct 6 ms 852 KB Output is correct
15 Correct 6 ms 828 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 5 ms 848 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 14360 KB Output is correct
2 Correct 204 ms 14284 KB Output is correct
3 Correct 208 ms 14320 KB Output is correct
4 Correct 180 ms 12920 KB Output is correct
5 Correct 205 ms 13572 KB Output is correct
6 Correct 175 ms 12240 KB Output is correct
7 Correct 204 ms 14224 KB Output is correct
8 Correct 202 ms 14108 KB Output is correct
9 Correct 194 ms 13916 KB Output is correct
10 Correct 178 ms 13676 KB Output is correct
11 Correct 172 ms 12904 KB Output is correct
12 Correct 163 ms 12104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 14360 KB Output is correct
2 Correct 204 ms 14284 KB Output is correct
3 Correct 208 ms 14320 KB Output is correct
4 Correct 180 ms 12920 KB Output is correct
5 Correct 205 ms 13572 KB Output is correct
6 Correct 175 ms 12240 KB Output is correct
7 Correct 204 ms 14224 KB Output is correct
8 Correct 202 ms 14108 KB Output is correct
9 Correct 194 ms 13916 KB Output is correct
10 Correct 178 ms 13676 KB Output is correct
11 Correct 172 ms 12904 KB Output is correct
12 Correct 163 ms 12104 KB Output is correct
13 Correct 231 ms 14716 KB Output is correct
14 Correct 250 ms 14708 KB Output is correct
15 Correct 208 ms 14336 KB Output is correct
16 Correct 199 ms 13304 KB Output is correct
17 Correct 218 ms 13956 KB Output is correct
18 Correct 171 ms 12184 KB Output is correct
19 Correct 229 ms 14796 KB Output is correct
20 Correct 227 ms 14804 KB Output is correct
21 Correct 231 ms 14712 KB Output is correct
22 Correct 182 ms 13556 KB Output is correct
23 Correct 169 ms 12888 KB Output is correct
24 Correct 161 ms 12192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 7 ms 844 KB Output is correct
8 Correct 8 ms 848 KB Output is correct
9 Correct 7 ms 892 KB Output is correct
10 Correct 7 ms 852 KB Output is correct
11 Correct 6 ms 852 KB Output is correct
12 Correct 5 ms 724 KB Output is correct
13 Correct 6 ms 852 KB Output is correct
14 Correct 6 ms 852 KB Output is correct
15 Correct 6 ms 828 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 5 ms 848 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 205 ms 14360 KB Output is correct
20 Correct 204 ms 14284 KB Output is correct
21 Correct 208 ms 14320 KB Output is correct
22 Correct 180 ms 12920 KB Output is correct
23 Correct 205 ms 13572 KB Output is correct
24 Correct 175 ms 12240 KB Output is correct
25 Correct 204 ms 14224 KB Output is correct
26 Correct 202 ms 14108 KB Output is correct
27 Correct 194 ms 13916 KB Output is correct
28 Correct 178 ms 13676 KB Output is correct
29 Correct 172 ms 12904 KB Output is correct
30 Correct 163 ms 12104 KB Output is correct
31 Correct 231 ms 14716 KB Output is correct
32 Correct 250 ms 14708 KB Output is correct
33 Correct 208 ms 14336 KB Output is correct
34 Correct 199 ms 13304 KB Output is correct
35 Correct 218 ms 13956 KB Output is correct
36 Correct 171 ms 12184 KB Output is correct
37 Correct 229 ms 14796 KB Output is correct
38 Correct 227 ms 14804 KB Output is correct
39 Correct 231 ms 14712 KB Output is correct
40 Correct 182 ms 13556 KB Output is correct
41 Correct 169 ms 12888 KB Output is correct
42 Correct 161 ms 12192 KB Output is correct
43 Correct 245 ms 17592 KB Output is correct
44 Correct 247 ms 17596 KB Output is correct
45 Correct 252 ms 17468 KB Output is correct
46 Correct 205 ms 14492 KB Output is correct
47 Correct 229 ms 16020 KB Output is correct
48 Correct 167 ms 12464 KB Output is correct
49 Correct 243 ms 17388 KB Output is correct
50 Correct 243 ms 17496 KB Output is correct
51 Correct 230 ms 17632 KB Output is correct
52 Correct 216 ms 15948 KB Output is correct
53 Correct 178 ms 13636 KB Output is correct