답안 #808863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
808863 2023-08-05T11:57:37 Z LucaIlie Examination (JOI19_examination) C++17
2 / 100
3000 ms 242604 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 = 2e9;
int s[MAX_N], t[MAX_N], a[MAX_Q], b[MAX_Q], c[MAX_Q], ans[MAX_Q];
map<int, vector<int>> updates, queries;
vector<int> vals;

struct node {
    node *left, *right;
    ordered_set bau;
};

struct SEG_TREE {
    node *createNode() {
        node *t = new node;
        t->left = t->right = NULL;
        return t;
    }

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

        v->bau.insert( { val, i } );

        if ( l == r )
            return;

        int mid = (r - l) / 2 + l;
        if ( v->left == NULL )
            v->left = createNode();
        if ( v->right == NULL )
            v->right = createNode();
        update( v->left, l, mid, pos, val, i );
        update( v->right, mid + 1, r, pos, val, i );
    }

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

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

        int mid = (r - l) / 2 + l;
        if ( v->left == NULL )
            v->left = createNode();
        if ( v->right == NULL )
            v->right = createNode();
        return query( v->left, l, mid, lq, rq, val ) + query( v->right, mid + 1, r, lq, rq, val );
    }
};

SEG_TREE bambam;

int main() {
    cin.tie( NULL );
    ios_base::sync_with_stdio( false );
    
    
    int n, q;

    cin >> n >> q;
    for ( int i = 0; i < n; i++ )
        cin >> s[i] >> t[i];
    for ( int i = 0; i < q; i++ )
        cin >> a[i] >> b[i] >> c[i];

    for ( int i = 0; i < n; i++ )
        updates[s[i] + t[i]].push_back( i ), vals.push_back( s[i] + t[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() );

    node *root = bambam.createNode();
    for ( int x: vals ) {
        for ( int i: updates[x] )
            bambam.update( root, 0, MAX_VAL, s[i], t[i], i );
        for ( int i: queries[x] )
            ans[i] = bambam.query( root, 0, MAX_VAL, a[i], MAX_VAL, b[i] );
    }

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

    return 0;
}
# 결과 실행 시간 메모리 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 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 40 ms 33036 KB Output is correct
8 Correct 39 ms 33032 KB Output is correct
9 Correct 35 ms 32988 KB Output is correct
10 Correct 35 ms 33096 KB Output is correct
11 Correct 29 ms 7528 KB Output is correct
12 Correct 21 ms 6428 KB Output is correct
13 Correct 33 ms 32540 KB Output is correct
14 Correct 32 ms 32468 KB Output is correct
15 Correct 36 ms 32468 KB Output is correct
16 Correct 26 ms 6940 KB Output is correct
17 Correct 45 ms 33084 KB Output is correct
18 Correct 63 ms 6448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2252 ms 242556 KB Output is correct
2 Correct 2165 ms 242496 KB Output is correct
3 Correct 2274 ms 242604 KB Output is correct
4 Correct 1465 ms 240592 KB Output is correct
5 Correct 1228 ms 216588 KB Output is correct
6 Correct 988 ms 205232 KB Output is correct
7 Correct 2220 ms 241600 KB Output is correct
8 Correct 1930 ms 242552 KB Output is correct
9 Correct 1817 ms 241612 KB Output is correct
10 Correct 936 ms 216472 KB Output is correct
11 Correct 1282 ms 240512 KB Output is correct
12 Execution timed out 3078 ms 173740 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2252 ms 242556 KB Output is correct
2 Correct 2165 ms 242496 KB Output is correct
3 Correct 2274 ms 242604 KB Output is correct
4 Correct 1465 ms 240592 KB Output is correct
5 Correct 1228 ms 216588 KB Output is correct
6 Correct 988 ms 205232 KB Output is correct
7 Correct 2220 ms 241600 KB Output is correct
8 Correct 1930 ms 242552 KB Output is correct
9 Correct 1817 ms 241612 KB Output is correct
10 Correct 936 ms 216472 KB Output is correct
11 Correct 1282 ms 240512 KB Output is correct
12 Execution timed out 3078 ms 173740 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 40 ms 33036 KB Output is correct
8 Correct 39 ms 33032 KB Output is correct
9 Correct 35 ms 32988 KB Output is correct
10 Correct 35 ms 33096 KB Output is correct
11 Correct 29 ms 7528 KB Output is correct
12 Correct 21 ms 6428 KB Output is correct
13 Correct 33 ms 32540 KB Output is correct
14 Correct 32 ms 32468 KB Output is correct
15 Correct 36 ms 32468 KB Output is correct
16 Correct 26 ms 6940 KB Output is correct
17 Correct 45 ms 33084 KB Output is correct
18 Correct 63 ms 6448 KB Output is correct
19 Correct 2252 ms 242556 KB Output is correct
20 Correct 2165 ms 242496 KB Output is correct
21 Correct 2274 ms 242604 KB Output is correct
22 Correct 1465 ms 240592 KB Output is correct
23 Correct 1228 ms 216588 KB Output is correct
24 Correct 988 ms 205232 KB Output is correct
25 Correct 2220 ms 241600 KB Output is correct
26 Correct 1930 ms 242552 KB Output is correct
27 Correct 1817 ms 241612 KB Output is correct
28 Correct 936 ms 216472 KB Output is correct
29 Correct 1282 ms 240512 KB Output is correct
30 Execution timed out 3078 ms 173740 KB Time limit exceeded
31 Halted 0 ms 0 KB -