QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#471820 | #4563. Radio Towers | A_programmer | 0 | 77ms | 44440kb | C++17 | 2.9kb | 2024-07-11 09:25:12 | 2024-07-11 09:25:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int inf = 1e9;
int a[maxn], n;
int stk[maxn], tp;
int L[maxn], R[maxn], d[maxn];
int nxt[18][maxn], pre[18][maxn];
struct ST
{
int mi[18], lg[maxn];
int f[18][maxn];
void build()
{
for (int i = 0; i <= 17; i++) mi[i] = 1 << i;
for (int i = 1, k = 0; i <= n; i++)
{
lg[i] = k; if (i == (1 << (k + 1))) lg[i] = ++k;
f[0][i] = a[i];
}
for (int j = 1; j <= 17; j++)
for (int i = 1; i + mi[j] - 1 <= n; i++)
f[j][i] = max(f[j - 1][i], f[j - 1][i + mi[j - 1]]);
}
int query(int l, int r)
{
if (l > r) return 0;
int k = lg[r - l + 1];
return max(f[k][l], f[k][r - mi[k] + 1]);
}
}st;
int rt[maxn], sum[maxn * 35], ls[maxn * 35], rs[maxn * 35], cnt;
void update(int &k, int p, int l, int r, int x)
{
k = ++cnt;
sum[k] = sum[p] + 1, ls[k] = ls[p], rs[k] = rs[p];
if (l == r) return;
int mid = (l + r) >> 1;
if (x <= mid) update(ls[k], ls[p], l, mid, x);
else update(rs[k], rs[p], mid + 1, r, x);
}
int ask(int k, int l, int r, int x)
{
if (!k) return 0;
if (l == r) return sum[k];
int mid = (l + r) >> 1;
if (x > mid) return ask(rs[k], mid + 1, r, x);
else return ask(ls[k], l, mid, x) + sum[rs[k]];
}
void init(int N, vector<int> H)
{
n = N;
for (int i = 1; i <= N; i++) a[i] = H[i - 1]; st.build();
tp = 0;
for (int i = 1; i <= N; i++)
{
while (tp && a[stk[tp]] > a[i]) tp--;
L[i] = tp ? stk[tp] + 1 : 1;
stk[++tp] = i;
}
tp = 0;
for (int i = N; i; i--)
{
while (tp && a[stk[tp]] > a[i]) tp--;
R[i] = tp ? stk[tp] - 1 : n;
d[i] = min(st.query(L[i], i - 1), st.query(i + 1, R[i])) - a[i];
stk[++tp] = i;
}
for (int i = 1; i <= N; i++)
if (d[i] > 0) update(rt[i], rt[i - 1], 1, inf, d[i]); else rt[i] = rt[i - 1];
for (int i = 1; i <= N; i++) nxt[0][i] = R[i] + 1; nxt[0][N + 1] = N + 1;
for (int j = 1; j <= 17; j++)
for (int i = 1; i <= N + 1; i++) nxt[j][i] = nxt[j - 1][nxt[j - 1][i]];
for (int i = 1; i <= N; i++) pre[0][i] = L[i] - 1;
for (int j = 1; j <= 17; j++)
for (int i = 1; i <= N; i++) pre[j][i] = pre[j - 1][pre[j - 1][i]];
}
int max_towers(int l, int r, int D)
{
l++, r++;
int ans = ask(rt[r], 1, inf, D) - ask(rt[l - 1], 1, inf, D);
int x1 = l;
for (int i = 17; ~i; i--)
if (nxt[i][x1] <= r && L[nxt[i][x1]] < l) x1 = nxt[i][x1];
if (d[x1] < D && st.query(x1 + 1, R[x1]) - a[x1] >= D) ans++;
int x2 = r;
for (int i = 17; ~i; i--)
if (pre[i][x2] >= l && R[pre[i][x2]] > r) x2 = pre[i][x2];
if (x2 != x1 && d[x2] < D && st.query(L[x2], x2 - 1) - a[x2] >= D) ans++;
return max(1, ans);
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 37ms
memory: 28436kb
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:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 14th lines differ - expected: '2', found: '1'
Subtask #2:
score: 0
Wrong Answer
Test #8:
score: 11
Accepted
time: 0ms
memory: 26380kb
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:
13
result:
ok 3 lines
Test #9:
score: 0
Accepted
time: 0ms
memory: 24828kb
input:
2000 510696791 617882876 373405425 518361747 407161508 435668375 559543221 465317236 38039460 717410075 714427583 977153243 679286738 23933545 750215417 37078782 973334934 244734879 243897181 603105656 981870220 85688930 807317304 901266308 225354691 737318933 824323690 365669439 111883771 153256479...
output:
292
result:
ok 3 lines
Test #10:
score: 0
Accepted
time: 0ms
memory: 26876kb
input:
2000 516351740 512181903 200723571 993230512 160881035 858124753 539677115 120758992 855511696 883443323 930303372 707938300 186981787 145199071 581235758 65550786 7197175 474759320 732341567 517832089 220614631 428681162 168642809 331743780 689236970 514407524 725936494 447118446 628858360 36946526...
output:
91
result:
ok 3 lines
Test #11:
score: 0
Accepted
time: 0ms
memory: 29020kb
input:
2000 9654673 812116916 373455422 816862897 353222263 785552601 262143032 654718863 361397545 763154940 79011466 983035671 46521930 654559175 371270845 610911343 19671952 831534324 157278884 850193672 83857278 600512673 91419235 820220378 19933790 959137813 447541847 957882585 47577396 981451791 2290...
output:
336
result:
ok 3 lines
Test #12:
score: 0
Accepted
time: 4ms
memory: 26952kb
input:
2000 101597651 901337214 94865893 515541321 223422476 791229261 361846447 652989994 147299317 644867197 32737606 525776949 182468296 547470985 330848340 873710937 392296086 971753844 156102346 764082424 254318166 685488259 221310405 521552461 481853974 868664461 300437861 938093383 466194541 6653033...
output:
176
result:
ok 3 lines
Test #13:
score: 0
Accepted
time: 0ms
memory: 26968kb
input:
2000 472936055 973169917 157888070 752944598 254539436 814034071 26698036 538887055 429236303 861439585 333049317 960563190 374468157 913310144 89434192 863875353 370790916 558434605 461824050 727741912 341709750 906272885 334496641 886737508 281651305 854169557 304260640 494128561 360711440 5339229...
output:
130
result:
ok 3 lines
Test #14:
score: -11
Wrong Answer
time: 0ms
memory: 26624kb
input:
2000 448125011 914906568 342296305 596847215 308205069 607246435 321988425 906263458 12754675 760166384 151837669 976756930 492753133 973159665 56759675 984884487 393926205 542913032 452064909 641120579 160301206 621818390 240470745 728458832 262255458 718912726 467544291 738536144 174343867 6066620...
output:
33
result:
wrong answer 3rd lines differ - expected: '34', found: '33'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #65:
score: 0
Wrong Answer
time: 77ms
memory: 44440kb
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:
11902 4770 14278 13956 570 9308 4389 9 22097 16784 26037 2813 8487 16601 2029 6158 17236 29707 19863 12083 20815 18090 4195 11612 4623 6657 7660 623 9837 13012 14474 11799 14795 6364 7308 5981 13613 14208 15922 17325 6019 10291 1819 29076 3116 6638 5810 28745 14944 9540 5498 1014 5001 20938 304 1993...
result:
wrong answer 3rd lines differ - expected: '11903', found: '11902'
Subtask #5:
score: 0
Wrong Answer
Test #86:
score: 0
Wrong Answer
time: 25ms
memory: 34420kb
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 149 5030 5227 7333 1777 6675 2011 5921 4878 7477 4598 2768 5360 6465 7660 7234 7794 2759 6321 7056 7302 4749 463 2028 5650 1972 6227 4900 4966 4990 3141 783 5818 3004 7705 6967 1939 5880 7201 4752 1277 6554 2950 892 6601 7019 7236 6076 5182 6579 2342 2069 4337 5744 4437 2261 6686 1738 7756...
result:
wrong answer 5th lines differ - expected: '150', found: '149'
Subtask #6:
score: 0
Wrong Answer
Test #97:
score: 0
Wrong Answer
time: 75ms
memory: 40656kb
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:
7293 18702 4922 19042 23488 1992 20886 9155 21248 15707 114 11736 8529 19157 9406 9139 5400 20113 1698 3993 22639 5925 17883 12913 5726 12378 21617 15763 645 5418 16982 7639 6140 1775 6288 619 766 3079 8805 11541 7217 2649 15833 2238 2023 9705 23983 4664 8898 5006 2392 20170 8340 14535 16454 6622 18...
result:
wrong answer 6th lines differ - expected: '19044', found: '19042'
Subtask #7:
score: 0
Skipped
Dependency #1:
0%