QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#612051 | #29. Posters on the wall | avadhutgiri875 | 10 | 248ms | 10968kb | Python3 | 2.5kb | 2024-10-05 03:11:18 | 2024-10-05 03:11:18 |
Judging History
answer
from collections import defaultdict
def calculate_overlap_area(x1, y1, x2, y2, posters):
# Calculate area of overlap between query rectangle and each poster
total_overlap = 0
for px1, py1, px2, py2 in posters:
# Calculate overlap area between query rectangle and poster rectangle
overlap_x1 = max(min(x1, x2), min(px1, px2))
overlap_y1 = max(min(y1, y2), min(py1, py2))
overlap_x2 = min(max(x1, x2), max(px1, px2))
overlap_y2 = min(max(y1, y2), max(py1, py2))
if overlap_x1 < overlap_x2 and overlap_y1 < overlap_y2:
total_overlap += (overlap_x2 - overlap_x1) * (overlap_y2 - overlap_y1)
return total_overlap
def main():
r, c, n, q, m = map(int, input().split())
posters = []
grid = defaultdict(list)
grid_size = 1000 # Adjust based on wall size and number of posters for best results
for _ in range(n):
x1, y1, x2, y2 = map(int, input().split())
posters.append((x1, y1, x2, y2))
# Insert poster into relevant grid cells
min_x, max_x = min(x1, x2) // grid_size, max(x1, x2) // grid_size
min_y, max_y = min(y1, y2) // grid_size, max(y1, y2) // grid_size
for i in range(min_x, max_x + 1):
for j in range(min_y, max_y + 1):
grid[(i, j)].append((x1, y1, x2, y2))
last_answer = 0
cache = {}
for _ in range(q):
x1_p, y1_p, x2_p, y2_p, v = map(int, input().split())
x1 = (x1_p + last_answer * v) % m
y1 = (y1_p + last_answer * v) % m
x2 = (x2_p + last_answer * v) % m
y2 = (y2_p + last_answer * v) % m
query_rect = (x1, y1, x2, y2)
# Check cache first
if query_rect in cache:
total_overlap = cache[query_rect]
else:
# Get relevant posters from grid
min_x, max_x = min(x1, x2) // grid_size, max(x1, x2) // grid_size
min_y, max_y = min(y1, y2) // grid_size, max(y1, y2) // grid_size
relevant_posters = set()
for i in range(min_x, max_x + 1):
for j in range(min_y, max_y + 1):
relevant_posters.update(grid[(i, j)])
total_overlap = calculate_overlap_area(x1, y1, x2, y2, relevant_posters)
cache[query_rect] = total_overlap # Store in cache
print(total_overlap)
last_answer = total_overlap
if __name__ == "__main__":
main()
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 200ms
memory: 10968kb
input:
500 500 398 500 550 174 98 170 101 413 442 406 435 394 123 486 121 360 139 361 136 7 216 8 208 282 302 284 308 134 134 140 131 160 27 161 26 437 364 442 356 162 438 173 445 180 151 178 146 1 298 24 310 255 328 254 335 119 42 128 39 22 120 17 125 81 140 85 139 98 50 100 40 101 250 98 291 53 369 37 37...
output:
588 7261 508 3 134 398 6 707 16 997 16 2274 1472 874 2604 26 85 140 35 651 2009 1082 4253 904 4 256 4061 759 278 2768 1524 3276 87 249 589 4 979 646 469 192 322 9 163 609 5748 27 177 62 34 1662 4873 140 186 1139 110 681 2778 6089 617 84 6 360 9 2 88 619 6 1680 4 3 12 2 720 5674 363 995 2153 588 4236...
result:
ok 500 lines
Test #2:
score: 10
Accepted
time: 248ms
memory: 10928kb
input:
500 500 500 500 550 83 255 65 260 372 489 367 491 311 461 303 464 57 239 56 241 377 491 357 493 401 34 413 36 84 197 92 199 367 431 377 482 417 39 418 41 122 445 125 446 325 262 316 444 64 354 66 356 440 303 430 305 446 0 444 1 227 94 226 96 348 492 352 495 147 3 161 17 177 384 178 386 249 61 248 63...
output:
5548 1292 13607 9 15 50 56 99 72 6670 214 3910 8021 70 1085 27 1442 20 2 1795 19 3243 1432 36 317 5659 20 1 58 2468 6952 1369 975 5113 27 11 8852 8825 34 2236 10 20991 7972 249 140 11494 1313 12 226 2400 33 8930 0 196 13 1102 6357 2506 350 2076 1916 2744 39 11266 4522 27 241 3124 14 67 23224 96 3591...
result:
ok 500 lines
Test #3:
score: 10
Accepted
time: 233ms
memory: 10920kb
input:
500 500 450 500 550 224 121 226 113 214 388 215 379 0 77 3 76 296 47 297 61 227 6 229 8 450 231 452 226 155 214 166 200 129 433 130 419 16 56 19 44 408 320 410 317 377 163 379 175 330 401 332 411 339 25 341 24 496 152 498 141 194 347 200 338 349 75 350 80 455 410 459 413 444 32 485 29 308 259 310 24...
output:
55 627 2566 418 418 4112 3775 12682 2837 2570 5 2555 721 20 18 463 1086 1 1749 4553 290 5727 5898 260 126 175 3514 110 24 1296 2335 4066 34 60 1874 28 7031 22 14 4306 0 16993 12422 349 250 14 22 1004 11528 487 9985 4022 105 9848 10830 11 5 3516 2692 696 8585 34 7499 6439 12 5417 16907 2427 193 36 83...
result:
ok 500 lines
Subtask #2:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Test #4:
score: 0
Time Limit Exceeded
input:
5000 5000 4800 5000 5200 2710 3951 2735 3940 87 184 82 172 533 2512 541 2513 2563 512 2566 499 1615 4388 1580 4390 1833 3669 1889 3670 4039 4697 4049 4678 3699 3873 3689 3885 1224 2032 1229 2036 4986 1372 4991 1356 856 447 836 440 2588 3438 2586 3423 1966 3513 1910 3515 107 4499 139 4501 3725 4368 3...
output:
168781 1136262 187073 190667 412944 522 7454 64644 375 9665 167538 11 3550 13 474 228911 597329 447442 212422 12665 10 224326 96 617196 359988 21 138474 33 415034 7 452020 440886 927 278284 210766 1497677 6 250378 36 808436 9587 98550 826746 6995 3720 120 585529 36 56530 302556 8899 194199 192 26009...
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #6:
score: 0
Time Limit Exceeded
Test #25:
score: 0
Time Limit Exceeded
input:
100002 100002 50000 50000 100003 26929 99995 26935 100002 22715 99995 22721 100002 0 14154 6 14160 0 14203 6 14209 0 57260 6 57266 8057 0 8063 7 39109 99995 39115 100002 0 38521 6 38527 0 82355 6 82361 37037 99995 37043 100002 83083 99995 83089 100002 0 4746 6 4752 84357 99995 84363 100002 1659 0 16...
output:
1349982 1349972 1124973 1199974 1274979 1274970 1274978 1349973 1274978 1274970 1199974 1274968 1199974 1349972 1274978 1199974 1199976 1124973 1349982 1274968 1199976 1274968 1274978 1349973 1124973 1274979 1199974 1349973 1274970 1424976 1199974 1349972 1199976 1349982 1274970 1274968 1199976 1274...
result:
Subtask #7:
score: 0
Skipped
Dependency #6:
0%