Submission #808957

# Submission time Handle Problem Language Result Execution time Memory
808957 2023-08-05T12:47:17 Z LucaIlie Examination (JOI19_examination) C++17
100 / 100
2511 ms 257824 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef tree<
        pair<int, int>,
        null_type,
        less<pair<int, int>>,
        rb_tree_tag,
        tree_order_statistics_node_update> ordered_set;


struct query {
    int a, b, c;
};

const int MAX_N = 1e5;
const int MAX_Q = 1e5;
const int MAX_VAL = 2e5;
int x[MAX_N], y[MAX_N], z[MAX_N], a[MAX_Q], b[MAX_Q], c[MAX_Q], ans[MAX_Q];
map<int, vector<int>> updates, queries;
vector<int> vals;

struct SEG_TREE {
    ordered_set segTree[4 * MAX_VAL];

    void update( long long v, int l, int r, int pos, int val, int i ) {
        if ( l > pos || r < pos )
            return;

        segTree[v].insert( { val, i } );

        if ( l == r )
            return;

        int mid = (r - l) / 2 + l;
        update( v * 2 + 1, l, mid, pos, val, i );
        update( v * 2 + 2, mid + 1, r, pos, val, i );
    }

    int query( long long v, int l, int r, int lq, int rq, int val ) {
        if ( l > rq || r < lq )
            return 0;

        if ( lq <= l && r <= rq )
            return segTree[v].size() - segTree[v].order_of_key( { val, 0 } );

        int mid = (r - l) / 2 + l;
        return query( v * 2 + 1, l, mid, lq, rq, val ) + query( v * 2 + 2, mid + 1, r, lq, rq, val );
    }
};

SEG_TREE bambam;
map<int, int> normX, normY;

signed main() {
    int n, q;

    cin >> n >> q;
    for ( int i = 0; i < n; i++ ) {
        cin >> x[i] >> y[i];
        z[i] = x[i] + y[i];
    }
    for ( int i = 0; i < q; i++ )
        cin >> a[i] >> b[i] >> c[i];

    for ( int i = 0; i < n; i++ )
        updates[z[i]].push_back( i ), vals.push_back( z[i] );
    for ( int i = 0; i < q; i++ )
        queries[c[i]].push_back( i ), vals.push_back( c[i] );
    sort( vals.begin(), vals.end() );
    vals.resize( unique( vals.begin(), vals.end() ) - vals.begin() );
    reverse( vals.begin(), vals.end() );

    for ( int i = 0; i < n; i++ )
        normX[x[i]] = 1, normY[y[i]] = 1;
    for ( int i = 0; i < q; i++ )
        normX[a[i]] = 1, normY[b[i]] = 1;
    int valX = 0;
    for ( auto p: normX )
        normX[p.first] = valX++;
    int valY = 0;
    for ( auto p: normY )
        normY[p.first] = valY++;
    for ( int i = 0; i < n; i++ ) {
        x[i] = normX[x[i]];
        y[i] = normY[y[i]];
    }
    for ( int i = 0; i < n; i++ ) {
        a[i] = normX[a[i]];
        b[i] = normY[b[i]];
    }

    for ( int val: vals ) {
        for ( int i: updates[val] )
            bambam.update( 0, 0, MAX_VAL, x[i], y[i], i );
        for ( int i: queries[val] )
            ans[i] = bambam.query( 0, 0, MAX_VAL, a[i], MAX_VAL, b[i] );
    }

    for ( int i = 0; i < q; i++ )
        cout << ans[i] << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 48 ms 75480 KB Output is correct
2 Correct 44 ms 75460 KB Output is correct
3 Correct 46 ms 75372 KB Output is correct
4 Correct 45 ms 75460 KB Output is correct
5 Correct 46 ms 75420 KB Output is correct
6 Correct 66 ms 75364 KB Output is correct
7 Correct 70 ms 80904 KB Output is correct
8 Correct 70 ms 80848 KB Output is correct
9 Correct 70 ms 80804 KB Output is correct
10 Correct 66 ms 80584 KB Output is correct
11 Correct 78 ms 80620 KB Output is correct
12 Correct 71 ms 79284 KB Output is correct
13 Correct 71 ms 80360 KB Output is correct
14 Correct 70 ms 80256 KB Output is correct
15 Correct 70 ms 80360 KB Output is correct
16 Correct 63 ms 80036 KB Output is correct
17 Correct 71 ms 80588 KB Output is correct
18 Correct 86 ms 79216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2503 ms 218940 KB Output is correct
2 Correct 2427 ms 218964 KB Output is correct
3 Correct 2410 ms 218972 KB Output is correct
4 Correct 1617 ms 212984 KB Output is correct
5 Correct 1440 ms 213836 KB Output is correct
6 Correct 1153 ms 198368 KB Output is correct
7 Correct 2100 ms 218008 KB Output is correct
8 Correct 2194 ms 217992 KB Output is correct
9 Correct 1977 ms 217264 KB Output is correct
10 Correct 1329 ms 214808 KB Output is correct
11 Correct 1431 ms 212788 KB Output is correct
12 Correct 2068 ms 199068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2503 ms 218940 KB Output is correct
2 Correct 2427 ms 218964 KB Output is correct
3 Correct 2410 ms 218972 KB Output is correct
4 Correct 1617 ms 212984 KB Output is correct
5 Correct 1440 ms 213836 KB Output is correct
6 Correct 1153 ms 198368 KB Output is correct
7 Correct 2100 ms 218008 KB Output is correct
8 Correct 2194 ms 217992 KB Output is correct
9 Correct 1977 ms 217264 KB Output is correct
10 Correct 1329 ms 214808 KB Output is correct
11 Correct 1431 ms 212788 KB Output is correct
12 Correct 2068 ms 199068 KB Output is correct
13 Correct 2059 ms 228960 KB Output is correct
14 Correct 2288 ms 226900 KB Output is correct
15 Correct 2383 ms 219024 KB Output is correct
16 Correct 1377 ms 218288 KB Output is correct
17 Correct 1260 ms 219196 KB Output is correct
18 Correct 1094 ms 198648 KB Output is correct
19 Correct 2064 ms 228960 KB Output is correct
20 Correct 2165 ms 227636 KB Output is correct
21 Correct 1870 ms 228284 KB Output is correct
22 Correct 1275 ms 214864 KB Output is correct
23 Correct 1371 ms 213032 KB Output is correct
24 Correct 2142 ms 199328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 75480 KB Output is correct
2 Correct 44 ms 75460 KB Output is correct
3 Correct 46 ms 75372 KB Output is correct
4 Correct 45 ms 75460 KB Output is correct
5 Correct 46 ms 75420 KB Output is correct
6 Correct 66 ms 75364 KB Output is correct
7 Correct 70 ms 80904 KB Output is correct
8 Correct 70 ms 80848 KB Output is correct
9 Correct 70 ms 80804 KB Output is correct
10 Correct 66 ms 80584 KB Output is correct
11 Correct 78 ms 80620 KB Output is correct
12 Correct 71 ms 79284 KB Output is correct
13 Correct 71 ms 80360 KB Output is correct
14 Correct 70 ms 80256 KB Output is correct
15 Correct 70 ms 80360 KB Output is correct
16 Correct 63 ms 80036 KB Output is correct
17 Correct 71 ms 80588 KB Output is correct
18 Correct 86 ms 79216 KB Output is correct
19 Correct 2503 ms 218940 KB Output is correct
20 Correct 2427 ms 218964 KB Output is correct
21 Correct 2410 ms 218972 KB Output is correct
22 Correct 1617 ms 212984 KB Output is correct
23 Correct 1440 ms 213836 KB Output is correct
24 Correct 1153 ms 198368 KB Output is correct
25 Correct 2100 ms 218008 KB Output is correct
26 Correct 2194 ms 217992 KB Output is correct
27 Correct 1977 ms 217264 KB Output is correct
28 Correct 1329 ms 214808 KB Output is correct
29 Correct 1431 ms 212788 KB Output is correct
30 Correct 2068 ms 199068 KB Output is correct
31 Correct 2059 ms 228960 KB Output is correct
32 Correct 2288 ms 226900 KB Output is correct
33 Correct 2383 ms 219024 KB Output is correct
34 Correct 1377 ms 218288 KB Output is correct
35 Correct 1260 ms 219196 KB Output is correct
36 Correct 1094 ms 198648 KB Output is correct
37 Correct 2064 ms 228960 KB Output is correct
38 Correct 2165 ms 227636 KB Output is correct
39 Correct 1870 ms 228284 KB Output is correct
40 Correct 1275 ms 214864 KB Output is correct
41 Correct 1371 ms 213032 KB Output is correct
42 Correct 2142 ms 199328 KB Output is correct
43 Correct 2199 ms 257720 KB Output is correct
44 Correct 2286 ms 257724 KB Output is correct
45 Correct 2511 ms 257824 KB Output is correct
46 Correct 1521 ms 246700 KB Output is correct
47 Correct 1314 ms 247576 KB Output is correct
48 Correct 1153 ms 199096 KB Output is correct
49 Correct 2125 ms 257652 KB Output is correct
50 Correct 2052 ms 257652 KB Output is correct
51 Correct 1995 ms 257488 KB Output is correct
52 Correct 1224 ms 248576 KB Output is correct
53 Correct 1450 ms 227432 KB Output is correct