Submission #1043319

# Submission time Handle Problem Language Result Execution time Memory
1043319 2024-08-04T08:14:41 Z vjudge1 New Home (APIO18_new_home) C++17
12 / 100
5000 ms 114056 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int S = 1, E = 1e8 + 1;
const int Q =  3 * 1e5 + 10, N = Q, T = Q;
int ans[Q], Closed = 0;
map<int, vector<pair<int,int> > > add, rem, qry;
vector<int> events;
multiset<int> st[T];
int n, k, q;

void query(int l, int i)
{
  if(Closed > 0)
    {
      ans[i] = -1;
      return;
    }
  
  ans[i] = 0;
  for(int j = 1; j <= k; j++)
    {
      auto it = st[j].upper_bound(l);
      int d = E;
      if(it != st[j].end())
	d = min(d, *it - l);
      if(it != st[j].begin())
	{
	  it--;
	  d = min(d, l - *it);
	}
      ans[i] = max(ans[i], d);
    }
}

void Add(int x, int t) {
  if(st[t].empty()) Closed--;
  st[t].insert(x);
}

void remove(int x, int t)
{
  st[t].erase(st[t].find(x));
  if(st[t].empty())
    Closed++;
}


int main()
{
  cin >> n >> k >> q;
  Closed = k;
  
  for(int i = 0; i < n; i ++)
    {
      int x, t, a, b;
      cin >> x >> t >> a >> b;
      
      events.push_back(a);
      events.push_back(b);

      add[a].push_back({x, t});
      rem[b].push_back({x, t});
    }

  for(int i = 0; i < q; i ++)
    {
      int l, y;
      cin >> l >> y;
      events.push_back(y);
      qry[y].push_back({l, i});
    }

  sort(events.begin(), events.end());
  events.resize(unique(events.begin(), events.end()) - events.begin());

  for(int e : events)
    {
      // cerr << endl;
      // cerr << "Event time : " << e << endl;
      if(add.find(e) != add.end())
	{
	  vector<pair<int,int> > &vec = add[e];
	  for(auto [x, t] : vec)
	    Add(x, t);
	}

      if(qry.find(e) != qry.end())
	{
	  vector<pair<int,int> > &vec = qry[e];
	  for(auto [l, i] : vec)
	    query(l, i);
	}

      if(rem.find(e) != rem.end())
	{
	  vector<pair<int,int> > &vec = rem[e];
	  for(auto [x, t] : vec)
	    remove(x, t);
	}
    }
  

  for(int i = 0; i < q; i ++)
    cout << ans[i] << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14440 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 7 ms 14700 KB Output is correct
7 Correct 5 ms 14684 KB Output is correct
8 Correct 6 ms 14544 KB Output is correct
9 Correct 6 ms 14712 KB Output is correct
10 Correct 6 ms 14680 KB Output is correct
11 Correct 7 ms 14680 KB Output is correct
12 Correct 5 ms 14684 KB Output is correct
13 Correct 5 ms 14520 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
15 Correct 6 ms 14684 KB Output is correct
16 Correct 6 ms 14684 KB Output is correct
17 Correct 7 ms 14680 KB Output is correct
18 Correct 6 ms 14680 KB Output is correct
19 Correct 7 ms 14684 KB Output is correct
20 Correct 6 ms 14680 KB Output is correct
21 Correct 6 ms 14544 KB Output is correct
22 Correct 7 ms 14540 KB Output is correct
23 Correct 7 ms 14680 KB Output is correct
24 Correct 6 ms 14624 KB Output is correct
25 Correct 6 ms 14684 KB Output is correct
26 Correct 6 ms 14544 KB Output is correct
27 Correct 6 ms 14424 KB Output is correct
28 Correct 5 ms 14476 KB Output is correct
29 Correct 8 ms 14684 KB Output is correct
30 Correct 6 ms 14536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14440 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 7 ms 14700 KB Output is correct
7 Correct 5 ms 14684 KB Output is correct
8 Correct 6 ms 14544 KB Output is correct
9 Correct 6 ms 14712 KB Output is correct
10 Correct 6 ms 14680 KB Output is correct
11 Correct 7 ms 14680 KB Output is correct
12 Correct 5 ms 14684 KB Output is correct
13 Correct 5 ms 14520 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
15 Correct 6 ms 14684 KB Output is correct
16 Correct 6 ms 14684 KB Output is correct
17 Correct 7 ms 14680 KB Output is correct
18 Correct 6 ms 14680 KB Output is correct
19 Correct 7 ms 14684 KB Output is correct
20 Correct 6 ms 14680 KB Output is correct
21 Correct 6 ms 14544 KB Output is correct
22 Correct 7 ms 14540 KB Output is correct
23 Correct 7 ms 14680 KB Output is correct
24 Correct 6 ms 14624 KB Output is correct
25 Correct 6 ms 14684 KB Output is correct
26 Correct 6 ms 14544 KB Output is correct
27 Correct 6 ms 14424 KB Output is correct
28 Correct 5 ms 14476 KB Output is correct
29 Correct 8 ms 14684 KB Output is correct
30 Correct 6 ms 14536 KB Output is correct
31 Correct 1544 ms 41260 KB Output is correct
32 Correct 78 ms 19140 KB Output is correct
33 Correct 267 ms 39372 KB Output is correct
34 Correct 1176 ms 39448 KB Output is correct
35 Correct 809 ms 41268 KB Output is correct
36 Correct 304 ms 41160 KB Output is correct
37 Correct 222 ms 38592 KB Output is correct
38 Correct 200 ms 38340 KB Output is correct
39 Correct 179 ms 38344 KB Output is correct
40 Correct 177 ms 38344 KB Output is correct
41 Correct 294 ms 38596 KB Output is correct
42 Correct 257 ms 38336 KB Output is correct
43 Correct 174 ms 22460 KB Output is correct
44 Correct 261 ms 38596 KB Output is correct
45 Correct 192 ms 38592 KB Output is correct
46 Correct 156 ms 38336 KB Output is correct
47 Correct 148 ms 37392 KB Output is correct
48 Correct 138 ms 37312 KB Output is correct
49 Correct 159 ms 37828 KB Output is correct
50 Correct 189 ms 38084 KB Output is correct
51 Correct 152 ms 37832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5071 ms 84452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5040 ms 114056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14440 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 7 ms 14700 KB Output is correct
7 Correct 5 ms 14684 KB Output is correct
8 Correct 6 ms 14544 KB Output is correct
9 Correct 6 ms 14712 KB Output is correct
10 Correct 6 ms 14680 KB Output is correct
11 Correct 7 ms 14680 KB Output is correct
12 Correct 5 ms 14684 KB Output is correct
13 Correct 5 ms 14520 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
15 Correct 6 ms 14684 KB Output is correct
16 Correct 6 ms 14684 KB Output is correct
17 Correct 7 ms 14680 KB Output is correct
18 Correct 6 ms 14680 KB Output is correct
19 Correct 7 ms 14684 KB Output is correct
20 Correct 6 ms 14680 KB Output is correct
21 Correct 6 ms 14544 KB Output is correct
22 Correct 7 ms 14540 KB Output is correct
23 Correct 7 ms 14680 KB Output is correct
24 Correct 6 ms 14624 KB Output is correct
25 Correct 6 ms 14684 KB Output is correct
26 Correct 6 ms 14544 KB Output is correct
27 Correct 6 ms 14424 KB Output is correct
28 Correct 5 ms 14476 KB Output is correct
29 Correct 8 ms 14684 KB Output is correct
30 Correct 6 ms 14536 KB Output is correct
31 Correct 1544 ms 41260 KB Output is correct
32 Correct 78 ms 19140 KB Output is correct
33 Correct 267 ms 39372 KB Output is correct
34 Correct 1176 ms 39448 KB Output is correct
35 Correct 809 ms 41268 KB Output is correct
36 Correct 304 ms 41160 KB Output is correct
37 Correct 222 ms 38592 KB Output is correct
38 Correct 200 ms 38340 KB Output is correct
39 Correct 179 ms 38344 KB Output is correct
40 Correct 177 ms 38344 KB Output is correct
41 Correct 294 ms 38596 KB Output is correct
42 Correct 257 ms 38336 KB Output is correct
43 Correct 174 ms 22460 KB Output is correct
44 Correct 261 ms 38596 KB Output is correct
45 Correct 192 ms 38592 KB Output is correct
46 Correct 156 ms 38336 KB Output is correct
47 Correct 148 ms 37392 KB Output is correct
48 Correct 138 ms 37312 KB Output is correct
49 Correct 159 ms 37828 KB Output is correct
50 Correct 189 ms 38084 KB Output is correct
51 Correct 152 ms 37832 KB Output is correct
52 Correct 199 ms 41156 KB Output is correct
53 Correct 182 ms 39444 KB Output is correct
54 Correct 218 ms 41152 KB Output is correct
55 Execution timed out 5039 ms 38988 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14440 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 7 ms 14700 KB Output is correct
7 Correct 5 ms 14684 KB Output is correct
8 Correct 6 ms 14544 KB Output is correct
9 Correct 6 ms 14712 KB Output is correct
10 Correct 6 ms 14680 KB Output is correct
11 Correct 7 ms 14680 KB Output is correct
12 Correct 5 ms 14684 KB Output is correct
13 Correct 5 ms 14520 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
15 Correct 6 ms 14684 KB Output is correct
16 Correct 6 ms 14684 KB Output is correct
17 Correct 7 ms 14680 KB Output is correct
18 Correct 6 ms 14680 KB Output is correct
19 Correct 7 ms 14684 KB Output is correct
20 Correct 6 ms 14680 KB Output is correct
21 Correct 6 ms 14544 KB Output is correct
22 Correct 7 ms 14540 KB Output is correct
23 Correct 7 ms 14680 KB Output is correct
24 Correct 6 ms 14624 KB Output is correct
25 Correct 6 ms 14684 KB Output is correct
26 Correct 6 ms 14544 KB Output is correct
27 Correct 6 ms 14424 KB Output is correct
28 Correct 5 ms 14476 KB Output is correct
29 Correct 8 ms 14684 KB Output is correct
30 Correct 6 ms 14536 KB Output is correct
31 Correct 1544 ms 41260 KB Output is correct
32 Correct 78 ms 19140 KB Output is correct
33 Correct 267 ms 39372 KB Output is correct
34 Correct 1176 ms 39448 KB Output is correct
35 Correct 809 ms 41268 KB Output is correct
36 Correct 304 ms 41160 KB Output is correct
37 Correct 222 ms 38592 KB Output is correct
38 Correct 200 ms 38340 KB Output is correct
39 Correct 179 ms 38344 KB Output is correct
40 Correct 177 ms 38344 KB Output is correct
41 Correct 294 ms 38596 KB Output is correct
42 Correct 257 ms 38336 KB Output is correct
43 Correct 174 ms 22460 KB Output is correct
44 Correct 261 ms 38596 KB Output is correct
45 Correct 192 ms 38592 KB Output is correct
46 Correct 156 ms 38336 KB Output is correct
47 Correct 148 ms 37392 KB Output is correct
48 Correct 138 ms 37312 KB Output is correct
49 Correct 159 ms 37828 KB Output is correct
50 Correct 189 ms 38084 KB Output is correct
51 Correct 152 ms 37832 KB Output is correct
52 Execution timed out 5071 ms 84452 KB Time limit exceeded
53 Halted 0 ms 0 KB -