Submission #965721

# Submission time Handle Problem Language Result Execution time Memory
965721 2024-04-19T06:06:58 Z becaido Examination (JOI19_examination) C++17
100 / 100
189 ms 9340 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 2e5 + 5;

int n, q, sz;
int ans[SIZE];

int m;
vector<int> lis;

int bit[SIZE];
void upd(int pos, int x) {
    for (; pos <= m; pos += pos & -pos) bit[pos] += x;
}
int que(int pos) {
    int re = 0;
    for (; pos; pos -= pos & -pos) re += bit[pos];
    return re;
}

struct ds {
    int x, y, z, id;
    ds() {}
    ds(int x, int y, int z, int id) : x(x), y(y), z(z), id(id) {}
    bool operator < (const ds &o) const {
        return make_tuple(x, y, z, id) < make_tuple(o.x, o.y, o.z, o.id);
    }
} a[SIZE], tmp[SIZE];

bool cmp(ds a, ds b) {
    return make_tuple(a.y, a.z, a.id) < make_tuple(b.y, b.z, b.id);
}

void divide(int l, int r) {
    if (l == r) return;
    int mid = (l + r) / 2;
    divide(l, mid), divide(mid + 1, r);
    for (int i = l, il = l, ir = mid + 1; i <= r; i++) {
        if (ir > r || (il <= mid && cmp(a[il], a[ir]))) {
            if (a[il].id == 0) upd(a[il].z, 1);
            tmp[i] = a[il++];
        } else {
            if (a[ir].id) ans[a[ir].id] += que(a[ir].z);
            tmp[i] = a[ir++];
        }
    }
    FOR (i, l, mid) if (a[i].id == 0) upd(a[i].z, -1);
    FOR (i, l, r) a[i] = tmp[i];
}

void solve() {
    cin >> n >> q;
    FOR (i, 1, n) {
        int x, y;
        cin >> x >> y;
        x = -x, y = -y;
        a[++sz] = ds(x, y, x + y, 0);
    }
    FOR (i, 1, q) {
        int x, y, z;
        cin >> x >> y >> z;
        x = -x, y = -y, z = -z;
        a[++sz] = ds(x, y, z, i);
    }
    FOR (i, 1, sz) lis.pb(a[i].z);
    sort(lis.begin(), lis.end());
    lis.erase(unique(lis.begin(), lis.end()), lis.end());
    m = lis.size();
    FOR (i, 1, sz) a[i].z = lower_bound(lis.begin(), lis.end(), a[i].z) - lis.begin() + 1;
    sort(a + 1, a + sz + 1);
    divide(1, sz);
    FOR (i, 1, q) cout << ans[i] << '\n';
}

int main() {
    Waimai;
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 5 ms 4672 KB Output is correct
8 Correct 6 ms 2712 KB Output is correct
9 Correct 5 ms 4700 KB Output is correct
10 Correct 4 ms 2652 KB Output is correct
11 Correct 4 ms 4700 KB Output is correct
12 Correct 3 ms 4700 KB Output is correct
13 Correct 4 ms 2652 KB Output is correct
14 Correct 5 ms 4668 KB Output is correct
15 Correct 4 ms 2652 KB Output is correct
16 Correct 3 ms 2652 KB Output is correct
17 Correct 4 ms 4700 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 8788 KB Output is correct
2 Correct 149 ms 8656 KB Output is correct
3 Correct 170 ms 8784 KB Output is correct
4 Correct 129 ms 8784 KB Output is correct
5 Correct 131 ms 8812 KB Output is correct
6 Correct 69 ms 8652 KB Output is correct
7 Correct 132 ms 8904 KB Output is correct
8 Correct 136 ms 8808 KB Output is correct
9 Correct 132 ms 8904 KB Output is correct
10 Correct 118 ms 8624 KB Output is correct
11 Correct 118 ms 8656 KB Output is correct
12 Correct 70 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 8788 KB Output is correct
2 Correct 149 ms 8656 KB Output is correct
3 Correct 170 ms 8784 KB Output is correct
4 Correct 129 ms 8784 KB Output is correct
5 Correct 131 ms 8812 KB Output is correct
6 Correct 69 ms 8652 KB Output is correct
7 Correct 132 ms 8904 KB Output is correct
8 Correct 136 ms 8808 KB Output is correct
9 Correct 132 ms 8904 KB Output is correct
10 Correct 118 ms 8624 KB Output is correct
11 Correct 118 ms 8656 KB Output is correct
12 Correct 70 ms 8272 KB Output is correct
13 Correct 176 ms 9016 KB Output is correct
14 Correct 183 ms 8912 KB Output is correct
15 Correct 153 ms 8828 KB Output is correct
16 Correct 156 ms 8804 KB Output is correct
17 Correct 154 ms 8876 KB Output is correct
18 Correct 73 ms 8516 KB Output is correct
19 Correct 174 ms 8908 KB Output is correct
20 Correct 176 ms 9040 KB Output is correct
21 Correct 162 ms 9072 KB Output is correct
22 Correct 119 ms 8528 KB Output is correct
23 Correct 120 ms 8520 KB Output is correct
24 Correct 54 ms 8144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 5 ms 4672 KB Output is correct
8 Correct 6 ms 2712 KB Output is correct
9 Correct 5 ms 4700 KB Output is correct
10 Correct 4 ms 2652 KB Output is correct
11 Correct 4 ms 4700 KB Output is correct
12 Correct 3 ms 4700 KB Output is correct
13 Correct 4 ms 2652 KB Output is correct
14 Correct 5 ms 4668 KB Output is correct
15 Correct 4 ms 2652 KB Output is correct
16 Correct 3 ms 2652 KB Output is correct
17 Correct 4 ms 4700 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 173 ms 8788 KB Output is correct
20 Correct 149 ms 8656 KB Output is correct
21 Correct 170 ms 8784 KB Output is correct
22 Correct 129 ms 8784 KB Output is correct
23 Correct 131 ms 8812 KB Output is correct
24 Correct 69 ms 8652 KB Output is correct
25 Correct 132 ms 8904 KB Output is correct
26 Correct 136 ms 8808 KB Output is correct
27 Correct 132 ms 8904 KB Output is correct
28 Correct 118 ms 8624 KB Output is correct
29 Correct 118 ms 8656 KB Output is correct
30 Correct 70 ms 8272 KB Output is correct
31 Correct 176 ms 9016 KB Output is correct
32 Correct 183 ms 8912 KB Output is correct
33 Correct 153 ms 8828 KB Output is correct
34 Correct 156 ms 8804 KB Output is correct
35 Correct 154 ms 8876 KB Output is correct
36 Correct 73 ms 8516 KB Output is correct
37 Correct 174 ms 8908 KB Output is correct
38 Correct 176 ms 9040 KB Output is correct
39 Correct 162 ms 9072 KB Output is correct
40 Correct 119 ms 8528 KB Output is correct
41 Correct 120 ms 8520 KB Output is correct
42 Correct 54 ms 8144 KB Output is correct
43 Correct 182 ms 9208 KB Output is correct
44 Correct 188 ms 9260 KB Output is correct
45 Correct 189 ms 9296 KB Output is correct
46 Correct 167 ms 9324 KB Output is correct
47 Correct 166 ms 9332 KB Output is correct
48 Correct 78 ms 8356 KB Output is correct
49 Correct 168 ms 9316 KB Output is correct
50 Correct 180 ms 9320 KB Output is correct
51 Correct 178 ms 9340 KB Output is correct
52 Correct 163 ms 9168 KB Output is correct
53 Correct 121 ms 8760 KB Output is correct