#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
struct Store
{
long pos;
long oYear;
long cYear;
bool open(long year)
{
return year >= oYear && year <= cYear;
}
long dist(long x)
{
return std::abs(x - pos);
}
};
struct StoreType
{
std::vector<Store> stores;
};
int main()
{
long numStores, numTypes, numQ;
std::cin >> numStores;
std::cin >> numTypes;
std::cin >> numQ;
std::vector<StoreType> types(numTypes);
for (long s = 0; s < numStores; s++)
{
long pos, type, oYear, cYear;
std::cin >> pos;
std::cin >> type;
std::cin >> oYear;
std::cin >> cYear;
types[type - 1].stores.push_back(Store { pos, oYear, cYear });
}
for (StoreType& type : types)
{
std::sort(ALL(type.stores), [&] (const Store& a, const Store& b)
{
return a.pos < b.pos;
});
}
std::vector<long> minDist(numTypes);
for (long i = 0; i < numQ; i++)
{
long pos, year;
std::cin >> pos;
std::cin >> year;
std::fill(ALL(minDist), -1);
long inconv = -1;
for (StoreType& type : types)
{
auto it = std::lower_bound(ALL(type.stores), pos, [&] (const Store& a, long b)
{
return a.pos < b;
});
long mid = it - type.stores.begin();
int64_t closest = INT64_MAX;
long l = 0;
long r = 1;
while (closest != -1)
{
int64_t lDist = INT64_MAX;
int64_t rDist = INT64_MAX;
if (mid - l >= 0)
{
lDist = type.stores[mid - l].dist(pos);
if (type.stores[mid - l].open(year))
closest = std::min(closest, lDist);
}
if (mid + r < type.stores.size())
{
rDist = type.stores[mid + r].dist(pos);
if (type.stores[mid + r].open(year))
closest = std::min(closest, rDist);
}
if (lDist == INT64_MAX && rDist == INT64_MAX)
break;
if (lDist <= rDist)
l++;
if (rDist <= lDist)
r++;
}
if (closest == INT64_MAX)
{
inconv = -1;
break;
}
inconv = std::max(inconv, closest);
}
std::cout << inconv << std::endl;
}
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:89:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (mid + r < type.stores.size())
~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Runtime error |
3 ms |
560 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Runtime error |
3 ms |
560 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5080 ms |
13804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5092 ms |
13804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Runtime error |
3 ms |
560 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Runtime error |
3 ms |
560 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |