Submission #489428

# Submission time Handle Problem Language Result Execution time Memory
489428 2021-11-23T01:21:05 Z mdn2002 Examination (JOI19_examination) C++14
100 / 100
675 ms 13996 KB
#include<bits/stdc++.h>
using namespace std;
int n , q , ans [100005];
vector < pair < pair < int , int > , pair < int , int > > > v;
vector < pair < int , pair < int , int > > > e;
void goo ( int l , int r )
{
    if ( l == r ) return;
    int mid = ( l + r ) / 2;
    vector < int > c;
    for ( int i = mid + 1 ; i <= r ; i ++ )
    {
        int y = e [i] . second . first , id = e [i] . second . second;
        if ( id == 1e9 ) c . push_back ( y );
    }
    sort ( c . begin () , c . end () );
    for ( int i = l ; i <= mid ; i ++ )
    {
        int y = e [i] . second . first , id = e [i] . second . second;
        if ( id != 1e9 ) ans [id] += c . end () - lower_bound ( c . begin () , c . end () , y );
    }
    goo ( l , mid );
    goo ( mid + 1 , r );
}
void go ( int l , int r )
{
    if ( l == r ) return;
    int mid = ( l + r ) / 2;
    e . clear ();
    for ( int i = l ; i <= mid ; i ++ )
    {
        int x = v [i] . first . second , y = v [i] . second . first , id = v [i] . second . second;
        if ( id != 1e9 ) e . push_back ( { x , { y , id } } );
    }
    for ( int i = mid + 1 ; i <= r ; i ++ )
    {
        int x = v [i] . first . second , y = v [i] . second . first , id = v [i] . second . second;
        if ( id == 1e9 ) e . push_back ( { x , { y , id } } );
    }
    sort ( e . begin () , e . end () );
    if ( e . size () ) goo ( 0 , e . size () - 1 );
    go ( l , mid );
    go ( mid + 1 , r );
}
int main()
{
    //freopen ( "fence8.in" , "r" , stdin );
    //freopen ( "fence8.out" , "w" , stdout );
    cin >> n >> q;
    for ( int i = 0 ; i < n ; i ++ )
    {
        int x , y;
        cin >> x >> y;
        v . push_back ( { { x + y , x } , { y , 1e9 } } );
    }
    for ( int i = 0 ; i < q ; i ++ )
    {
        int x , y , z;
        cin >> x >> y >> z;
        v . push_back ( { { z , x } , { y , i + 1 } } );
    }
    sort ( v . begin () , v . end () );
    go ( 0 , v . size () - 1 );
    for ( int i = 1 ; i <= q ; i ++ ) cout << ans [i] << endl;
}
/*
1 1
1 1
1 1 2
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 16 ms 688 KB Output is correct
8 Correct 16 ms 588 KB Output is correct
9 Correct 17 ms 692 KB Output is correct
10 Correct 16 ms 648 KB Output is correct
11 Correct 13 ms 588 KB Output is correct
12 Correct 10 ms 588 KB Output is correct
13 Correct 14 ms 696 KB Output is correct
14 Correct 14 ms 708 KB Output is correct
15 Correct 14 ms 712 KB Output is correct
16 Correct 13 ms 696 KB Output is correct
17 Correct 12 ms 588 KB Output is correct
18 Correct 9 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 558 ms 12216 KB Output is correct
2 Correct 543 ms 12464 KB Output is correct
3 Correct 536 ms 12308 KB Output is correct
4 Correct 480 ms 11512 KB Output is correct
5 Correct 463 ms 11552 KB Output is correct
6 Correct 352 ms 10792 KB Output is correct
7 Correct 516 ms 12212 KB Output is correct
8 Correct 514 ms 12160 KB Output is correct
9 Correct 484 ms 12092 KB Output is correct
10 Correct 401 ms 11464 KB Output is correct
11 Correct 405 ms 11368 KB Output is correct
12 Correct 317 ms 6372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 558 ms 12216 KB Output is correct
2 Correct 543 ms 12464 KB Output is correct
3 Correct 536 ms 12308 KB Output is correct
4 Correct 480 ms 11512 KB Output is correct
5 Correct 463 ms 11552 KB Output is correct
6 Correct 352 ms 10792 KB Output is correct
7 Correct 516 ms 12212 KB Output is correct
8 Correct 514 ms 12160 KB Output is correct
9 Correct 484 ms 12092 KB Output is correct
10 Correct 401 ms 11464 KB Output is correct
11 Correct 405 ms 11368 KB Output is correct
12 Correct 317 ms 6372 KB Output is correct
13 Correct 583 ms 9976 KB Output is correct
14 Correct 624 ms 12032 KB Output is correct
15 Correct 531 ms 12256 KB Output is correct
16 Correct 514 ms 9184 KB Output is correct
17 Correct 533 ms 9152 KB Output is correct
18 Correct 364 ms 10060 KB Output is correct
19 Correct 587 ms 9992 KB Output is correct
20 Correct 619 ms 10160 KB Output is correct
21 Correct 590 ms 9956 KB Output is correct
22 Correct 412 ms 11372 KB Output is correct
23 Correct 409 ms 11524 KB Output is correct
24 Correct 304 ms 6372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 16 ms 688 KB Output is correct
8 Correct 16 ms 588 KB Output is correct
9 Correct 17 ms 692 KB Output is correct
10 Correct 16 ms 648 KB Output is correct
11 Correct 13 ms 588 KB Output is correct
12 Correct 10 ms 588 KB Output is correct
13 Correct 14 ms 696 KB Output is correct
14 Correct 14 ms 708 KB Output is correct
15 Correct 14 ms 712 KB Output is correct
16 Correct 13 ms 696 KB Output is correct
17 Correct 12 ms 588 KB Output is correct
18 Correct 9 ms 460 KB Output is correct
19 Correct 558 ms 12216 KB Output is correct
20 Correct 543 ms 12464 KB Output is correct
21 Correct 536 ms 12308 KB Output is correct
22 Correct 480 ms 11512 KB Output is correct
23 Correct 463 ms 11552 KB Output is correct
24 Correct 352 ms 10792 KB Output is correct
25 Correct 516 ms 12212 KB Output is correct
26 Correct 514 ms 12160 KB Output is correct
27 Correct 484 ms 12092 KB Output is correct
28 Correct 401 ms 11464 KB Output is correct
29 Correct 405 ms 11368 KB Output is correct
30 Correct 317 ms 6372 KB Output is correct
31 Correct 583 ms 9976 KB Output is correct
32 Correct 624 ms 12032 KB Output is correct
33 Correct 531 ms 12256 KB Output is correct
34 Correct 514 ms 9184 KB Output is correct
35 Correct 533 ms 9152 KB Output is correct
36 Correct 364 ms 10060 KB Output is correct
37 Correct 587 ms 9992 KB Output is correct
38 Correct 619 ms 10160 KB Output is correct
39 Correct 590 ms 9956 KB Output is correct
40 Correct 412 ms 11372 KB Output is correct
41 Correct 409 ms 11524 KB Output is correct
42 Correct 304 ms 6372 KB Output is correct
43 Correct 645 ms 12016 KB Output is correct
44 Correct 645 ms 11944 KB Output is correct
45 Correct 675 ms 13996 KB Output is correct
46 Correct 534 ms 10308 KB Output is correct
47 Correct 552 ms 10456 KB Output is correct
48 Correct 344 ms 6732 KB Output is correct
49 Correct 632 ms 13872 KB Output is correct
50 Correct 626 ms 11856 KB Output is correct
51 Correct 646 ms 13816 KB Output is correct
52 Correct 475 ms 10152 KB Output is correct
53 Correct 426 ms 12076 KB Output is correct