Submission #262390

# Submission time Handle Problem Language Result Execution time Memory
262390 2020-08-12T19:44:43 Z CaroLinda New Home (APIO18_new_home) C++14
12 / 100
3447 ms 12448 KB
#include <bits/stdc++.h>

#define lp(i,a,b) for(int i = a; i < b ; i++)
#define ff first
#define ss second
#define pb emplace_back
#define ll long long
#define mk make_pair
#define sz(x) x.size()
#define pii pair<int,int>
#define mkt make_tuple
#define debug printf
#define all(x) x.begin(),x.end()

const int MAXN = 6e4+10 ;
const int inf = 1e9+10 ;

using namespace std ;

struct Event
{

    int type , tempo , id ;

    Event(int a = 0 , int b = 0 , int c = 0 ) : type(a) , tempo(b) , id(c) {}
    bool operator < (Event other) const
    {
        if( tempo == other.tempo ) return type < other.type ;
        return tempo < other.tempo ;
    }

};

int N , Q , K ;
int loja[MAXN] , x_loja[MAXN] , x_query[MAXN] , ans[MAXN] ;
multiset<int> s[MAXN] ;
vector<Event> sweep ;

int main()
{

    scanf("%d%d%d", &N , &K , &Q )  ;
    assert( K <= 400 ) ;

    for(int i = 1 , a , b ; i <= N ; i++ )
    {
        scanf("%d%d%d%d", &x_loja[i] , &loja[i] , &a, &b ) ;
        sweep.pb( Event(0, a, i) ) ;
        sweep.pb( Event(2, b, i) ) ;
    }
    for(int i = 1 , a , b ; i <= Q ; i++ )
    {
        scanf("%d%d", &x_query[i], &a ) ;
        sweep.pb( Event(1, a, i) ) ;
    }

    sort(all(sweep)) ;

    for(auto e : sweep )
    {
        int type = e.type ;
        int id = e.id ;

        if(type == 0)
        {
            s[ loja[id] ].insert( x_loja[id] ) ;
            continue ;
        }
        if(type == 2)
        {
            auto it = s[ loja[id] ].find( x_loja[id] ) ;
            s[ loja[id] ].erase(it) ;
            continue ;
        }

        for(int i = 1 ;i  <= K ; i++ )
        {

            if(sz(s[i]) == 0 || ans[id] == -1 ) { ans[id] = -1 ; continue ; }

            auto it_menor = s[i].lower_bound( x_query[id] ) ;
            if(it_menor != s[i].begin() ) it_menor -- ;
            auto it_maior = s[i].lower_bound( x_query[id] ) ;

            int dist = inf ;
            if(it_menor != s[i].end() ) dist = min(dist, abs(x_query[id] - *it_menor )) ;
            if( it_maior != s[i].end() ) dist = min( dist, abs(*it_maior - x_query[id]) );


            ans[id] = max(ans[id] , dist ) ;

        }


    }

    for(int i = 1 ; i <= Q ; i++ ) printf("%d\n" , ans[i]) ;

}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:51:25: warning: unused variable 'b' [-Wunused-variable]
   51 |     for(int i = 1 , a , b ; i <= Q ; i++ )
      |                         ^
new_home.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |     scanf("%d%d%d", &N , &K , &Q )  ;
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |         scanf("%d%d%d%d", &x_loja[i] , &loja[i] , &a, &b ) ;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |         scanf("%d%d", &x_query[i], &a ) ;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3188 KB Output is correct
2 Correct 3 ms 3192 KB Output is correct
3 Correct 3 ms 3192 KB Output is correct
4 Correct 3 ms 3188 KB Output is correct
5 Correct 3 ms 3196 KB Output is correct
6 Correct 3 ms 3200 KB Output is correct
7 Correct 4 ms 3200 KB Output is correct
8 Correct 4 ms 3200 KB Output is correct
9 Correct 4 ms 3200 KB Output is correct
10 Correct 4 ms 3200 KB Output is correct
11 Correct 4 ms 3200 KB Output is correct
12 Correct 3 ms 3200 KB Output is correct
13 Correct 3 ms 3200 KB Output is correct
14 Correct 3 ms 3200 KB Output is correct
15 Correct 4 ms 3200 KB Output is correct
16 Correct 4 ms 3200 KB Output is correct
17 Correct 4 ms 3200 KB Output is correct
18 Correct 4 ms 3200 KB Output is correct
19 Correct 5 ms 3200 KB Output is correct
20 Correct 5 ms 3200 KB Output is correct
21 Correct 4 ms 3200 KB Output is correct
22 Correct 4 ms 3200 KB Output is correct
23 Correct 4 ms 3200 KB Output is correct
24 Correct 3 ms 3200 KB Output is correct
25 Correct 3 ms 3200 KB Output is correct
26 Correct 3 ms 3200 KB Output is correct
27 Correct 3 ms 3200 KB Output is correct
28 Correct 3 ms 3200 KB Output is correct
29 Correct 3 ms 3200 KB Output is correct
30 Correct 3 ms 3200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3188 KB Output is correct
2 Correct 3 ms 3192 KB Output is correct
3 Correct 3 ms 3192 KB Output is correct
4 Correct 3 ms 3188 KB Output is correct
5 Correct 3 ms 3196 KB Output is correct
6 Correct 3 ms 3200 KB Output is correct
7 Correct 4 ms 3200 KB Output is correct
8 Correct 4 ms 3200 KB Output is correct
9 Correct 4 ms 3200 KB Output is correct
10 Correct 4 ms 3200 KB Output is correct
11 Correct 4 ms 3200 KB Output is correct
12 Correct 3 ms 3200 KB Output is correct
13 Correct 3 ms 3200 KB Output is correct
14 Correct 3 ms 3200 KB Output is correct
15 Correct 4 ms 3200 KB Output is correct
16 Correct 4 ms 3200 KB Output is correct
17 Correct 4 ms 3200 KB Output is correct
18 Correct 4 ms 3200 KB Output is correct
19 Correct 5 ms 3200 KB Output is correct
20 Correct 5 ms 3200 KB Output is correct
21 Correct 4 ms 3200 KB Output is correct
22 Correct 4 ms 3200 KB Output is correct
23 Correct 4 ms 3200 KB Output is correct
24 Correct 3 ms 3200 KB Output is correct
25 Correct 3 ms 3200 KB Output is correct
26 Correct 3 ms 3200 KB Output is correct
27 Correct 3 ms 3200 KB Output is correct
28 Correct 3 ms 3200 KB Output is correct
29 Correct 3 ms 3200 KB Output is correct
30 Correct 3 ms 3200 KB Output is correct
31 Correct 3447 ms 12448 KB Output is correct
32 Correct 135 ms 8448 KB Output is correct
33 Correct 276 ms 10520 KB Output is correct
34 Correct 2472 ms 10756 KB Output is correct
35 Correct 1494 ms 12368 KB Output is correct
36 Correct 299 ms 12240 KB Output is correct
37 Correct 244 ms 9864 KB Output is correct
38 Correct 134 ms 9568 KB Output is correct
39 Correct 124 ms 9700 KB Output is correct
40 Correct 121 ms 9568 KB Output is correct
41 Correct 362 ms 9768 KB Output is correct
42 Correct 308 ms 9660 KB Output is correct
43 Correct 509 ms 12000 KB Output is correct
44 Correct 312 ms 9824 KB Output is correct
45 Correct 153 ms 9696 KB Output is correct
46 Correct 115 ms 9700 KB Output is correct
47 Correct 98 ms 9404 KB Output is correct
48 Correct 84 ms 9316 KB Output is correct
49 Correct 104 ms 9488 KB Output is correct
50 Correct 283 ms 9572 KB Output is correct
51 Correct 98 ms 9440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 6272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 6144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3188 KB Output is correct
2 Correct 3 ms 3192 KB Output is correct
3 Correct 3 ms 3192 KB Output is correct
4 Correct 3 ms 3188 KB Output is correct
5 Correct 3 ms 3196 KB Output is correct
6 Correct 3 ms 3200 KB Output is correct
7 Correct 4 ms 3200 KB Output is correct
8 Correct 4 ms 3200 KB Output is correct
9 Correct 4 ms 3200 KB Output is correct
10 Correct 4 ms 3200 KB Output is correct
11 Correct 4 ms 3200 KB Output is correct
12 Correct 3 ms 3200 KB Output is correct
13 Correct 3 ms 3200 KB Output is correct
14 Correct 3 ms 3200 KB Output is correct
15 Correct 4 ms 3200 KB Output is correct
16 Correct 4 ms 3200 KB Output is correct
17 Correct 4 ms 3200 KB Output is correct
18 Correct 4 ms 3200 KB Output is correct
19 Correct 5 ms 3200 KB Output is correct
20 Correct 5 ms 3200 KB Output is correct
21 Correct 4 ms 3200 KB Output is correct
22 Correct 4 ms 3200 KB Output is correct
23 Correct 4 ms 3200 KB Output is correct
24 Correct 3 ms 3200 KB Output is correct
25 Correct 3 ms 3200 KB Output is correct
26 Correct 3 ms 3200 KB Output is correct
27 Correct 3 ms 3200 KB Output is correct
28 Correct 3 ms 3200 KB Output is correct
29 Correct 3 ms 3200 KB Output is correct
30 Correct 3 ms 3200 KB Output is correct
31 Correct 3447 ms 12448 KB Output is correct
32 Correct 135 ms 8448 KB Output is correct
33 Correct 276 ms 10520 KB Output is correct
34 Correct 2472 ms 10756 KB Output is correct
35 Correct 1494 ms 12368 KB Output is correct
36 Correct 299 ms 12240 KB Output is correct
37 Correct 244 ms 9864 KB Output is correct
38 Correct 134 ms 9568 KB Output is correct
39 Correct 124 ms 9700 KB Output is correct
40 Correct 121 ms 9568 KB Output is correct
41 Correct 362 ms 9768 KB Output is correct
42 Correct 308 ms 9660 KB Output is correct
43 Correct 509 ms 12000 KB Output is correct
44 Correct 312 ms 9824 KB Output is correct
45 Correct 153 ms 9696 KB Output is correct
46 Correct 115 ms 9700 KB Output is correct
47 Correct 98 ms 9404 KB Output is correct
48 Correct 84 ms 9316 KB Output is correct
49 Correct 104 ms 9488 KB Output is correct
50 Correct 283 ms 9572 KB Output is correct
51 Correct 98 ms 9440 KB Output is correct
52 Runtime error 6 ms 6144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3188 KB Output is correct
2 Correct 3 ms 3192 KB Output is correct
3 Correct 3 ms 3192 KB Output is correct
4 Correct 3 ms 3188 KB Output is correct
5 Correct 3 ms 3196 KB Output is correct
6 Correct 3 ms 3200 KB Output is correct
7 Correct 4 ms 3200 KB Output is correct
8 Correct 4 ms 3200 KB Output is correct
9 Correct 4 ms 3200 KB Output is correct
10 Correct 4 ms 3200 KB Output is correct
11 Correct 4 ms 3200 KB Output is correct
12 Correct 3 ms 3200 KB Output is correct
13 Correct 3 ms 3200 KB Output is correct
14 Correct 3 ms 3200 KB Output is correct
15 Correct 4 ms 3200 KB Output is correct
16 Correct 4 ms 3200 KB Output is correct
17 Correct 4 ms 3200 KB Output is correct
18 Correct 4 ms 3200 KB Output is correct
19 Correct 5 ms 3200 KB Output is correct
20 Correct 5 ms 3200 KB Output is correct
21 Correct 4 ms 3200 KB Output is correct
22 Correct 4 ms 3200 KB Output is correct
23 Correct 4 ms 3200 KB Output is correct
24 Correct 3 ms 3200 KB Output is correct
25 Correct 3 ms 3200 KB Output is correct
26 Correct 3 ms 3200 KB Output is correct
27 Correct 3 ms 3200 KB Output is correct
28 Correct 3 ms 3200 KB Output is correct
29 Correct 3 ms 3200 KB Output is correct
30 Correct 3 ms 3200 KB Output is correct
31 Correct 3447 ms 12448 KB Output is correct
32 Correct 135 ms 8448 KB Output is correct
33 Correct 276 ms 10520 KB Output is correct
34 Correct 2472 ms 10756 KB Output is correct
35 Correct 1494 ms 12368 KB Output is correct
36 Correct 299 ms 12240 KB Output is correct
37 Correct 244 ms 9864 KB Output is correct
38 Correct 134 ms 9568 KB Output is correct
39 Correct 124 ms 9700 KB Output is correct
40 Correct 121 ms 9568 KB Output is correct
41 Correct 362 ms 9768 KB Output is correct
42 Correct 308 ms 9660 KB Output is correct
43 Correct 509 ms 12000 KB Output is correct
44 Correct 312 ms 9824 KB Output is correct
45 Correct 153 ms 9696 KB Output is correct
46 Correct 115 ms 9700 KB Output is correct
47 Correct 98 ms 9404 KB Output is correct
48 Correct 84 ms 9316 KB Output is correct
49 Correct 104 ms 9488 KB Output is correct
50 Correct 283 ms 9572 KB Output is correct
51 Correct 98 ms 9440 KB Output is correct
52 Runtime error 6 ms 6272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Halted 0 ms 0 KB -