답안 #380808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380808 2021-03-23T03:47:59 Z 2qbingxuan Examination (JOI19_examination) C++14
100 / 100
307 ms 14236 KB
#include <bits/stdc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) qqbx(#a, a)
#define pary(a...) danb(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\033[1;32m[ " << s << " ] = [ ";
    for (auto it = L; it != R; ++it)
        std::cerr << *it << ' ';
    std::cerr << "]\033[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define pb emplace_back
#define sort_uni(v) sort(all(v)),v.erase(unique(all(v)), v.end())
#define get_pos(u,v) int(lower_bound(all(u), v) - u.begin())

using namespace std;
using ll = int64_t;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>;
const int maxn = 300025, inf = 1e9, MOD = 1000000007;
const ll INF = 1e18;

namespace cdq {
    struct Event {
        int t;
        int x, y, z;
        int id;
    } E[maxn];
    int cnt;
    int ans[maxn];
    struct Fenwick {
        int sum[maxn];
        void add(int p, int d) {
            for (; p < maxn; p += p & -p) sum[p] += d;
        }
        int query(int p) {
            int r = 0;
            for (; p > 0; p -= p & -p) r += sum[p];
            return r;
        }
    } fwt;
    void addEvent(int t, int x, int y, int z, int id) {
        E[cnt++] = { t, x, y, z, id };
    }
    bool cmpy(Event a, Event b) {
        return a.y != b.y ? a.y < b.y :
               a.z != b.z ? a.z < b.z :
               a.t < b.t;
    }
    void solve(int l, int r) {
        if (l+1 >= r) return;
        int m = l+(r-l)/2;
        solve(l, m);
        solve(m, r);
        int i = l, j = m;
        while (i < m || j < r) {
            if (j == r || (i < m && cmpy(E[i], E[j]))) {
                auto e = E[i++];
                if (e.t == 0) {
                    fwt.add(e.z, 1);
                }
            } else {
                auto e = E[j++];
                if (e.t == 1) {
                    ans[e.id] += fwt.query(e.z);
                }
            }
        }
        for (int i = l; i < m; i++) if (E[i].t == 0) fwt.add(E[i].z, -1);
        inplace_merge(E+l, E+m, E+r, cmpy);
    }
    void solve() {
        vector<int> u;
        for (int i = 0; i < cnt; i++) u.emplace_back(E[i].z);
        sort_uni(u);
        sort(E, E+cnt, [](Event a, Event b){
            return a.x != b.x ? a.x < b.x : 
                   a.y != b.y ? a.y < b.y :
                   a.z != b.z ? a.z < b.z :
                   a.t < b.t;
        });
        for (int i = 0; i < cnt; i++)
            E[i].z = get_pos(u, E[i].z) + 1;
        solve(0, cnt);
    }
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        x = -x, y = -y;
        cdq::addEvent(0, x, y, x+y, -1);
    }
    for (int i = 0; i < q; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x = -x, y = -y, z = -z;
        cdq::addEvent(1, x, y, z, i);
    }
    safe;
    cdq::solve();
    for (int i = 0; i < q; i++)
        cout << cdq::ans[i] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 8 ms 620 KB Output is correct
8 Correct 8 ms 620 KB Output is correct
9 Correct 8 ms 620 KB Output is correct
10 Correct 7 ms 620 KB Output is correct
11 Correct 7 ms 620 KB Output is correct
12 Correct 6 ms 620 KB Output is correct
13 Correct 7 ms 620 KB Output is correct
14 Correct 7 ms 620 KB Output is correct
15 Correct 7 ms 620 KB Output is correct
16 Correct 6 ms 620 KB Output is correct
17 Correct 7 ms 620 KB Output is correct
18 Correct 5 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 274 ms 9840 KB Output is correct
2 Correct 260 ms 11172 KB Output is correct
3 Correct 259 ms 11428 KB Output is correct
4 Correct 215 ms 10476 KB Output is correct
5 Correct 227 ms 10404 KB Output is correct
6 Correct 196 ms 9496 KB Output is correct
7 Correct 235 ms 11172 KB Output is correct
8 Correct 238 ms 11172 KB Output is correct
9 Correct 271 ms 11172 KB Output is correct
10 Correct 195 ms 10404 KB Output is correct
11 Correct 199 ms 10532 KB Output is correct
12 Correct 166 ms 9636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 274 ms 9840 KB Output is correct
2 Correct 260 ms 11172 KB Output is correct
3 Correct 259 ms 11428 KB Output is correct
4 Correct 215 ms 10476 KB Output is correct
5 Correct 227 ms 10404 KB Output is correct
6 Correct 196 ms 9496 KB Output is correct
7 Correct 235 ms 11172 KB Output is correct
8 Correct 238 ms 11172 KB Output is correct
9 Correct 271 ms 11172 KB Output is correct
10 Correct 195 ms 10404 KB Output is correct
11 Correct 199 ms 10532 KB Output is correct
12 Correct 166 ms 9636 KB Output is correct
13 Correct 287 ms 11940 KB Output is correct
14 Correct 288 ms 11812 KB Output is correct
15 Correct 272 ms 11248 KB Output is correct
16 Correct 261 ms 10916 KB Output is correct
17 Correct 240 ms 11000 KB Output is correct
18 Correct 188 ms 9508 KB Output is correct
19 Correct 289 ms 11812 KB Output is correct
20 Correct 290 ms 11812 KB Output is correct
21 Correct 274 ms 11812 KB Output is correct
22 Correct 207 ms 10532 KB Output is correct
23 Correct 196 ms 10532 KB Output is correct
24 Correct 165 ms 9380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 8 ms 620 KB Output is correct
8 Correct 8 ms 620 KB Output is correct
9 Correct 8 ms 620 KB Output is correct
10 Correct 7 ms 620 KB Output is correct
11 Correct 7 ms 620 KB Output is correct
12 Correct 6 ms 620 KB Output is correct
13 Correct 7 ms 620 KB Output is correct
14 Correct 7 ms 620 KB Output is correct
15 Correct 7 ms 620 KB Output is correct
16 Correct 6 ms 620 KB Output is correct
17 Correct 7 ms 620 KB Output is correct
18 Correct 5 ms 620 KB Output is correct
19 Correct 274 ms 9840 KB Output is correct
20 Correct 260 ms 11172 KB Output is correct
21 Correct 259 ms 11428 KB Output is correct
22 Correct 215 ms 10476 KB Output is correct
23 Correct 227 ms 10404 KB Output is correct
24 Correct 196 ms 9496 KB Output is correct
25 Correct 235 ms 11172 KB Output is correct
26 Correct 238 ms 11172 KB Output is correct
27 Correct 271 ms 11172 KB Output is correct
28 Correct 195 ms 10404 KB Output is correct
29 Correct 199 ms 10532 KB Output is correct
30 Correct 166 ms 9636 KB Output is correct
31 Correct 287 ms 11940 KB Output is correct
32 Correct 288 ms 11812 KB Output is correct
33 Correct 272 ms 11248 KB Output is correct
34 Correct 261 ms 10916 KB Output is correct
35 Correct 240 ms 11000 KB Output is correct
36 Correct 188 ms 9508 KB Output is correct
37 Correct 289 ms 11812 KB Output is correct
38 Correct 290 ms 11812 KB Output is correct
39 Correct 274 ms 11812 KB Output is correct
40 Correct 207 ms 10532 KB Output is correct
41 Correct 196 ms 10532 KB Output is correct
42 Correct 165 ms 9380 KB Output is correct
43 Correct 304 ms 14116 KB Output is correct
44 Correct 306 ms 14236 KB Output is correct
45 Correct 307 ms 13988 KB Output is correct
46 Correct 263 ms 12452 KB Output is correct
47 Correct 251 ms 12580 KB Output is correct
48 Correct 177 ms 9508 KB Output is correct
49 Correct 286 ms 14024 KB Output is correct
50 Correct 285 ms 13988 KB Output is correct
51 Correct 277 ms 13860 KB Output is correct
52 Correct 224 ms 12452 KB Output is correct
53 Correct 194 ms 11360 KB Output is correct