Submission #735139

# Submission time Handle Problem Language Result Execution time Memory
735139 2023-05-03T15:32:29 Z keisuke6 New Home (APIO18_new_home) C++14
12 / 100
5000 ms 69848 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,K,Q;
  cin>>N>>K>>Q;
  vector<int> X(N),T(N),A(N),B(N);
  vector<vector<tuple<int,int,int>>> G(K);
  vector<multiset<tuple<int,int,int>>> sta(K);
  vector<multiset<int>> Z(K);
  vector<int> I(K,0);
  for(int i=0;i<N;i++){
    cin>>X[i]>>T[i]>>A[i]>>B[i];
    T[i]--;
    G[T[i]].push_back({A[i],B[i],X[i]});
  }
  for(int i=0;i<K;i++){
    sort(G[i].begin(),G[i].end());
  }
  vector<pair<int,int>> Que(Q);
  for(int i=0;i<Q;i++) cin>>Que[i].second>>Que[i].first;
  vector<pair<int,int>> Que_ = Que;
  sort(Que.begin(),Que.end());
  map<pair<int,int>,int> m_ans;
  for(int i=0;i<Q;i++){
    int t = Que[i].first, x = Que[i].second;
    for(int j=0;j<K;j++){
      while(I[j] != G[j].size()){
        int aa,bb,cc;
        tie(aa,bb,cc) = G[j][I[j]];
        if(aa > t) break;
        sta[j].insert({bb,aa,cc});
        Z[j].insert(cc);
        I[j]++;
      }
    }
    for(int j=0;j<K;j++){
      while(!sta[j].empty()){
        auto pos = *sta[j].begin();
        int bb,aa,cc;
        tie(bb,aa,cc) = pos;
        if(bb >= t) break;
        sta[j].erase(sta[j].find(pos));
        Z[j].erase(Z[j].find(cc));
      }
    }
    int ans = 0;
    for(int j=0;j<K;j++){
      int now = 1e18;
      if(sta[j].empty()){
        ans = 1e18;
        continue;
      }
      auto a = Z[j].lower_bound(x);
      if(a != Z[j].end()){
        now = min(now,abs(x-(*a)));
      }
      if(a != Z[j].begin()){
        a--;
        now = min(now,abs(x-(*a)));
      }
      ans = max(ans,now);
    }
    if(ans == 1e18) ans = -1;
    m_ans[Que[i]] = ans;
  }
  for(int i=0;i<Q;i++) cout<<m_ans[Que_[i]]<<endl;
  cout<<endl;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:28:18: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |       while(I[j] != G[j].size()){
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 2 ms 420 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 312 KB Output is correct
14 Correct 2 ms 308 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 2 ms 312 KB Output is correct
21 Correct 3 ms 440 KB Output is correct
22 Correct 5 ms 468 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 3 ms 308 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 316 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 2 ms 420 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 312 KB Output is correct
14 Correct 2 ms 308 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 2 ms 312 KB Output is correct
21 Correct 3 ms 440 KB Output is correct
22 Correct 5 ms 468 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 3 ms 308 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 316 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3133 ms 18424 KB Output is correct
32 Correct 195 ms 9860 KB Output is correct
33 Correct 363 ms 14152 KB Output is correct
34 Correct 2472 ms 15320 KB Output is correct
35 Correct 1466 ms 17464 KB Output is correct
36 Correct 462 ms 17380 KB Output is correct
37 Correct 380 ms 13092 KB Output is correct
38 Correct 278 ms 12656 KB Output is correct
39 Correct 268 ms 12452 KB Output is correct
40 Correct 257 ms 12408 KB Output is correct
41 Correct 558 ms 12708 KB Output is correct
42 Correct 720 ms 13364 KB Output is correct
43 Correct 688 ms 15972 KB Output is correct
44 Correct 480 ms 13196 KB Output is correct
45 Correct 319 ms 12860 KB Output is correct
46 Correct 237 ms 12616 KB Output is correct
47 Correct 249 ms 12336 KB Output is correct
48 Correct 217 ms 12088 KB Output is correct
49 Correct 240 ms 12524 KB Output is correct
50 Correct 435 ms 13092 KB Output is correct
51 Correct 248 ms 12464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5059 ms 69848 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5041 ms 62064 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 2 ms 420 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 312 KB Output is correct
14 Correct 2 ms 308 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 2 ms 312 KB Output is correct
21 Correct 3 ms 440 KB Output is correct
22 Correct 5 ms 468 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 3 ms 308 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 316 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3133 ms 18424 KB Output is correct
32 Correct 195 ms 9860 KB Output is correct
33 Correct 363 ms 14152 KB Output is correct
34 Correct 2472 ms 15320 KB Output is correct
35 Correct 1466 ms 17464 KB Output is correct
36 Correct 462 ms 17380 KB Output is correct
37 Correct 380 ms 13092 KB Output is correct
38 Correct 278 ms 12656 KB Output is correct
39 Correct 268 ms 12452 KB Output is correct
40 Correct 257 ms 12408 KB Output is correct
41 Correct 558 ms 12708 KB Output is correct
42 Correct 720 ms 13364 KB Output is correct
43 Correct 688 ms 15972 KB Output is correct
44 Correct 480 ms 13196 KB Output is correct
45 Correct 319 ms 12860 KB Output is correct
46 Correct 237 ms 12616 KB Output is correct
47 Correct 249 ms 12336 KB Output is correct
48 Correct 217 ms 12088 KB Output is correct
49 Correct 240 ms 12524 KB Output is correct
50 Correct 435 ms 13092 KB Output is correct
51 Correct 248 ms 12464 KB Output is correct
52 Execution timed out 5026 ms 17992 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 2 ms 420 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 312 KB Output is correct
14 Correct 2 ms 308 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 2 ms 312 KB Output is correct
21 Correct 3 ms 440 KB Output is correct
22 Correct 5 ms 468 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 3 ms 308 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 316 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3133 ms 18424 KB Output is correct
32 Correct 195 ms 9860 KB Output is correct
33 Correct 363 ms 14152 KB Output is correct
34 Correct 2472 ms 15320 KB Output is correct
35 Correct 1466 ms 17464 KB Output is correct
36 Correct 462 ms 17380 KB Output is correct
37 Correct 380 ms 13092 KB Output is correct
38 Correct 278 ms 12656 KB Output is correct
39 Correct 268 ms 12452 KB Output is correct
40 Correct 257 ms 12408 KB Output is correct
41 Correct 558 ms 12708 KB Output is correct
42 Correct 720 ms 13364 KB Output is correct
43 Correct 688 ms 15972 KB Output is correct
44 Correct 480 ms 13196 KB Output is correct
45 Correct 319 ms 12860 KB Output is correct
46 Correct 237 ms 12616 KB Output is correct
47 Correct 249 ms 12336 KB Output is correct
48 Correct 217 ms 12088 KB Output is correct
49 Correct 240 ms 12524 KB Output is correct
50 Correct 435 ms 13092 KB Output is correct
51 Correct 248 ms 12464 KB Output is correct
52 Execution timed out 5059 ms 69848 KB Time limit exceeded
53 Halted 0 ms 0 KB -