QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#525540 | #4563. Radio Towers | green_gold_dog# | 0 | 111ms | 18548kb | C++20 | 3.2kb | 2024-08-20 17:57:31 | 2024-08-20 17:57:31 |
Judging History
answer
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll INF = 2'000'000'000;
struct segment_tree_max {
vector<pair<ll, ll>> tree;
ll size;
segment_tree_max(vector<ll> arr) {
size = 1;
while (size < arr.size()) {
size *= 2;
}
tree.resize(size * 2, make_pair(0, 0));
for (ll i = 0; i < arr.size(); i++) {
tree[i + size] = make_pair(arr[i], i);
}
for (ll i = size - 1; i > 0; i--) {
tree[i] = max(tree[i * 2], tree[i * 2 + 1]);
}
}
ll get(ll l, ll r) {
return get(1, 0, size, l, r).second;
}
pair<ll, ll> get(ll v, ll l, ll r, ll ql, ll qr) {
if (ql <= l && r <= qr) {
return tree[v];
}
if (qr <= l || r <= ql) {
return make_pair(0, 0);
}
ll mid = (l + r) / 2;
return max(get(v * 2, l, mid, ql, qr), get(v * 2 + 1, mid, r, ql, qr));
}
};
struct segment_tree_min {
vector<pair<ll, ll>> tree;
ll size;
segment_tree_min(vector<ll> arr) {
size = 1;
while (size < arr.size()) {
size *= 2;
}
tree.resize(size * 2, make_pair(INF, INF));
for (ll i = 0; i < arr.size(); i++) {
tree[i + size] = make_pair(arr[i], i);
}
for (ll i = size - 1; i > 0; i--) {
tree[i] = min(tree[i * 2], tree[i * 2 + 1]);
}
}
ll get(ll l, ll r) {
return get(1, 0, size, l, r).second;
}
pair<ll, ll> get(ll v, ll l, ll r, ll ql, ll qr) {
if (ql <= l && r <= qr) {
return tree[v];
}
if (qr <= l || r <= ql) {
return make_pair(INF, INF);
}
ll mid = (l + r) / 2;
return min(get(v * 2, l, mid, ql, qr), get(v * 2 + 1, mid, r, ql, qr));
}
};
ll rec(ll l, ll r, ll d, ll p, ll np, segment_tree_max& stma, segment_tree_min& stmi, vector<ll>& arr, ll& num, vector<ll>& cdd, vector<ll>& pnum, vector<pair<ll, ll>>& dt) {
if (r == l) {
return 0;
}
ll now = num;
num++;
cdd.push_back(0);
pnum.push_back(np);
if (r - l == 1) {
dt.emplace_back(p - arr[l] + 1, now);
return arr[l] + d <= p;
}
ll mid = stma.get(l, r);
ll al = rec(l, mid, d, arr[mid], now, stma, stmi, arr, num, cdd, pnum, dt);
ll ar = rec(mid + 1, r, d, arr[mid], now, stma, stmi, arr, num, cdd, pnum, dt);
ll ans = al + ar;
if (al == 0) {
cdd[now]++;
}
if (ar == 0) {
cdd[now]++;
}
ll mi = arr[stmi.get(l, r)];
if (mi + d <= p) {
dt.emplace_back(p - mi + 1, now);
ans = max(ans, 1);
}
return ans;
}
void make_dead(ll v, vector<ll>& pnum, vector<ll>& cdd, ll& ans) {
ans--;
if (pnum[v] != -1) {
cdd[pnum[v]]++;
if (cdd[pnum[v]] == 2) {
ans++;
}
}
}
map<ll, ll> anss;
void init(ll n, vector<ll> h) {
segment_tree_max stma(h);
segment_tree_min stmi(h);
vector<ll> cdd, pnum;
vector<pair<ll, ll>> dt;
ll num = 0;
ll ans = rec(0, n, 0, INF, -1, stma, stmi, h, num, cdd, pnum, dt);
sort(dt.begin(), dt.end());
anss[0] = ans;
for (auto[t, i] : dt) {
make_dead(i, pnum, cdd, ans);
anss[t] = ans;
}
}
ll max_towers(ll l, ll r, ll d) {
auto it = anss.lower_bound(d);
it--;
return it->second;
}
#ifdef LOCAL
int main() {
int N, Q;
assert(2 == scanf("%d %d", &N, &Q));
std::vector<int> H(N);
for (int i = 0; i < N; ++i) {
assert(1 == scanf("%d", &H[i]));
}
init(N, H);
for (int i = 0; i < Q; ++i) {
int L, R, D;
assert(3 == scanf("%d %d %d", &L, &R, &D));
printf("%d\n", max_towers(L, R, D));
}
return 0;
}
#endif
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 55ms
memory: 18548kb
input:
59640 49885 57346 58504 87383 113182 129676 204090 205404 259925 276583 300332 324014 333675 359377 364049 408489 414852 428310 438038 440113 458193 554789 643468 666525 683112 690791 707313 720088 741028 748785 789826 796576 800966 832867 851750 861044 862283 900756 926925 939560 955678 965636 9740...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
wrong answer 3rd lines differ - expected: '1', found: '2'
Subtask #2:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 1ms
memory: 3820kb
input:
425 753881706 405729786 890889563 29736246 598281970 208352067 357783003 663497023 178397034 4832890 562140755 510307001 354540290 538848551 436879256 86659033 42928516 24145404 749159097 118423198 506851985 204895765 719719998 726244368 991372008 681703480 799303017 657138050 88278945 417801236 260...
output:
131
result:
wrong answer 3rd lines differ - expected: '13', found: '131'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #65:
score: 0
Wrong Answer
time: 80ms
memory: 14616kb
input:
99308 491693640 24020487 317364185 726230755 737284540 951143270 709116045 641023337 360629062 964879440 47884022 532494780 803629825 635450854 688041998 573937055 113198481 191311841 929603572 636688 598629732 895342035 396521271 619919754 716589045 657789547 373121546 866402108 609316614 60046511 ...
output:
33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 33010 ...
result:
wrong answer 3rd lines differ - expected: '11903', found: '33010'
Subtask #5:
score: 0
Wrong Answer
Test #86:
score: 17
Accepted
time: 24ms
memory: 6092kb
input:
23881 605288257 422163932 155875880 339929874 76049859 196344969 958160745 767945284 469191956 997116006 387749577 15911341 920437918 367576975 800789357 351557615 283723284 369507452 841548133 643412903 309731505 256549694 370065644 699518122 559017597 347646657 469353381 575240521 501893001 454519...
output:
7197 7063 150 5030 5227 7333 1778 6675 2012 5921 4878 7477 4598 2769 5360 6465 7660 7234 7794 2760 6321 7056 7302 4749 464 2029 5650 1973 6227 4900 4966 4990 3142 785 5818 3005 7705 6967 1940 5880 7201 4752 1278 6554 2951 894 6601 7019 7236 6076 5182 6579 2343 2070 4337 5744 4437 2262 6686 1739 7756...
result:
ok 31567 lines
Test #87:
score: 0
Wrong Answer
time: 111ms
memory: 14440kb
input:
100000 187962236 252322706 659740540 756184857 615615021 870954164 997894181 924184575 178246679 206117936 948374169 611376809 940125697 583402158 621243496 179806768 420420048 261580744 495350370 179501503 624736464 865025098 132756697 396891347 254854635 384499314 232013282 699329403 718265326 972...
output:
21501 24099 33073 16936 24145 8440 674 23350 29618 2899 7659 19499 19027 10215 4083 14518 30601 23009 17970 7096 15472 32634 26673 29553 6232 11457 690 8753 7786 4078 28404 25386 28535 1752 5912 16456 18098 25382 30618 28242 30215 30920 19228 20981 27023 18696 16047 19091 7953 9832 13542 4224 26991 ...
result:
wrong answer 18776th lines differ - expected: '16198', found: '16199'
Subtask #6:
score: 0
Wrong Answer
Test #97:
score: 0
Wrong Answer
time: 63ms
memory: 13640kb
input:
88768 238644804 620122421 789364401 899010695 885388612 437964772 845379533 657562749 773925456 625793781 916240972 291506550 379611161 905077982 629848170 530056471 520438258 806293637 326792996 785404568 74285074 565304193 846963319 63529729 804909008 212070492 69936548 656129389 408708069 3070450...
output:
25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 25889 ...
result:
wrong answer 3rd lines differ - expected: '7293', found: '25889'
Subtask #7:
score: 0
Skipped
Dependency #1:
0%