QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140899#4563. Radio Towersvalerikk#0 1257ms79036kbC++173.9kb2023-08-16 22:41:002024-07-04 02:38:32

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 02:38:32]
  • 评测
  • 测评结果:0
  • 用时:1257ms
  • 内存:79036kb
  • [2023-08-16 22:41:00]
  • 提交

answer

#include "towers.h"

#include <vector>
#include <bits/stdc++.h>

using namespace std;

namespace {

const int N = 1e5 + 7;
const int L = 18;
const int T = 5e6 + 7;

int n;
int h[N];
int prv[N], nxt[N];
int stmx[L][N];
int dprv[N], dnxt[N];
int d1[N];
vector<int> xs;
vector<int> gprv[N], gnxt[N];
int rootpref[N], rootprv[N], rootnxt[N];
int emp, sz;
int vsum[T], vl[T], vr[T];
int vcnt = 1;

int copy(int v) {
	int u = vcnt++; 
	vsum[u] = vsum[v];
	vl[u] = vl[v];
	vr[u] = vr[v];
	return u;
}

int upd(int v, int tl, int tr, int ind, int val) {
	v = copy(v);
	if (tr - tl == 1) {
		vsum[v] += val;
		return v;
	} 
	int tm = (tl + tr) / 2;
	if (ind < tm) {
		vl[v] = upd(vl[v], tl, tm, ind, val);
	} else {
		vr[v] = upd(vr[v], tm, tr, ind, val);
	}
	vsum[v] = vsum[vl[v]] + vsum[vr[v]];
	return v;
}

int getsum(int v, int tl, int tr, int l, int r) {
	if (tl >= r || tr <= l) {
		return 0;
	}
	if (tl >= l && tr <= r) {
		return vsum[v];
	}
	int tm = (tl + tr) / 2;
	return getsum(vl[v], tl, tm, l, r) + getsum(vr[v], tm, tr, l, r);
}

int build(int tl, int tr) {
	int v = copy(0);
	if (tr - tl != 1) {
		int tm = (tl + tr) / 2;
		vl[v] = build(tl, tm);
		vr[v] = build(tm, tr);
	}
	return v;
}

int getmx(int l, int r) {
	int t = 31 - __builtin_clz(r - l);
	return max(stmx[t][l], stmx[t][r - (1 << t)]);
}

}

void init(int grdn, vector<int> grdh) {
	n = grdn;
	for (int i = 0; i < n; ++i) {
		h[i] = grdh[i];
	}
	{
		for (int i = 0; i < n; ++i) {
			nxt[i] = n;
		}
		vector<int> st;
		for (int i = 0; i < n; ++i) {
			while (!st.empty() && h[st.back()] > h[i]) {
				nxt[st.back()] = i;
				st.pop_back();
			}
			st.push_back(i);
		}
	}
	{
		for (int i = 0; i < n; ++i) {
			prv[i] = -1;
		}
		vector<int> st;
		for (int i = n - 1; i >= 0; --i) {
			while (!st.empty() && h[st.back()] > h[i]) {
				prv[st.back()] = i;
				st.pop_back();
			}
			st.push_back(i);
		}
	}
	for (int i = 0; i < n; ++i) {
		stmx[0][i] = h[i];
	}
	for (int t = 1; t < L; ++t) {
		int pw = 1 << t;
		for (int i = 0; i + pw <= n; ++i) {
			stmx[t][i] = max(stmx[t - 1][i], stmx[t - 1][i + pw / 2]);
		}
	}
	for (int i = 0; i < n; ++i) {
		dprv[i] = getmx(prv[i] + 1, i + 1) - h[i];
		dnxt[i] = getmx(i, nxt[i]) - h[i];
		d1[i] = min(dprv[i], dnxt[i]);
		xs.push_back(dprv[i]);
		xs.push_back(dnxt[i]);
		if (prv[i] != -1) {
			gprv[prv[i]].push_back(i);
		}
		if (nxt[i] != n) {
			gnxt[nxt[i]].push_back(i);
		}
	}
	xs.push_back(1e9 + 1);
	sort(xs.begin(), xs.end());
	xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
	sz = xs.size();
	for (int i = 0; i < n; ++i) {
		dprv[i] = lower_bound(xs.begin(), xs.end(), dprv[i]) - xs.begin();
		dnxt[i] = lower_bound(xs.begin(), xs.end(), dnxt[i]) - xs.begin();
		d1[i] = lower_bound(xs.begin(), xs.end(), d1[i]) - xs.begin();
	}
	emp = build(0, sz);
	rootpref[0] = emp;
	for (int i = 0; i < n; ++i) {
		rootpref[i + 1] = upd(rootpref[i], 0, sz, d1[i], 1);
	}
	for (int i = 0; i < n; ++i) {
		if (prv[i] == -1) {
			rootprv[i] = emp;
		} else {
			rootprv[i] = rootprv[prv[i]];
		}
		if (d1[i] < dprv[i]) {
			rootprv[i] = upd(rootprv[i], 0, sz, d1[i] + 1, 1);
			rootprv[i] = upd(rootprv[i], 0, sz, dprv[i] + 1, -1);
		}
	}
	for (int i = n - 1; i >= 0; --i) {
		if (nxt[i] == -1) {
			rootnxt[i] = emp;
		} else {
			rootnxt[i] = rootnxt[nxt[i]];
		}
		if (d1[i] < dnxt[i]) {
			rootnxt[i] = upd(rootnxt[i], 0, sz, d1[i] + 1, 1);
			rootnxt[i] = upd(rootnxt[i], 0, sz, dnxt[i] + 1, -1);
		}
	}
}

int max_towers(int grdl, int grdr, int grdd) {
	int l = grdl;
	int r = grdr;
	int d = grdd;
	d = lower_bound(xs.begin(), xs.end(), d) - xs.begin(); 
	++r;
	int ret = getsum(rootpref[r], 0, sz, d, sz) - getsum(rootpref[l], 0, sz, d, sz);
	{
		ret += getsum(rootnxt[l], 0, sz, 0, d);
		int ind = l;
		while (nxt[ind] < r) {
			ind = nxt[ind];
		}
		if (d1[ind] < d) {
			++ret;
		}
		ret -= getsum(rootnxt[ind], 0, sz, 0, d);
	}
	{
		ret += getsum(rootprv[r - 1], 0, sz, 0, d);
		int ind = r - 1;
		while (prv[ind] >= l) {
			ind = prv[ind];
		}
		ret -= getsum(rootprv[ind], 0, sz, 0, d);
	}
	return ret;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1257ms
memory: 62596kb

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
2
1
1
2
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
1
2
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
2
2
1
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
1
1
2
1
1
1
2
1
1
1
1
1
1
2
1
1
1
1
2
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

wrong answer 2195th lines differ - expected: '1', found: '2'

Subtask #2:

score: 0
Wrong Answer

Test #8:

score: 11
Accepted
time: 0ms
memory: 18356kb

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: 20764kb

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: 21052kb

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: 21148kb

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: 0ms
memory: 20924kb

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: 16812kb

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: 0
Accepted
time: 0ms
memory: 18860kb

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:

34

result:

ok 3 lines

Test #15:

score: 0
Accepted
time: 0ms
memory: 19156kb

input:

2000
63119 1763800 2560156 2577120 2947719 4220876 4493280 5257204 5695924 6255528 6688141 6874164 6986335 8608902 8655716 8667255 8733692 9297137 9612369 10639944 11677890 11850447 12123475 12942200 13292330 13630586 14006505 14704409 15864169 16065863 16090141 16348841 16582396 16707789 16914115 1...

output:

1

result:

ok 3 lines

Test #16:

score: 0
Accepted
time: 0ms
memory: 21100kb

input:

2000
999953545 999809722 999269748 998652085 998032618 997532818 996831561 996646538 995713640 994955665 994498039 993763043 993402749 993344498 992641411 991413401 991243813 990462579 989638909 988726451 988562857 985375670 983150768 982174289 982096151 981854907 981126710 980498905 979609052 97882...

output:

1

result:

ok 3 lines

Test #17:

score: 0
Accepted
time: 2ms
memory: 20836kb

input:

2000
513304 679545 683376 1330519 1389514 2537850 2773316 2812312 3237767 3896687 3989417 4104806 4468408 4893577 5094758 5322413 6269737 6564230 7102596 7379997 7942696 8362867 8543645 9336109 10288566 10317516 11169045 11188413 11774267 12334498 13040401 13398797 13472581 13524263 13682076 1493169...

output:

1

result:

ok 3 lines

Test #18:

score: 0
Accepted
time: 5ms
memory: 21116kb

input:

2000
999767480 999639155 999609042 998925691 998464928 996821425 996683829 996595059 996326912 996298094 995988614 995835236 995756420 994911243 994766270 994353107 994313741 994155172 994005150 993901305 993851772 993130682 993058863 992579160 992456330 992062631 991583495 991577017 991508098 99132...

output:

1

result:

ok 3 lines

Test #19:

score: -11
Wrong Answer
time: 0ms
memory: 14320kb

input:

5
1 3 5 4 2
1 3 1
-2 -2 -2
-2 -2 -2
-1 -1 -1

output:

1

result:

wrong answer 3rd lines differ - expected: '2', found: '1'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #65:

score: 0
Wrong Answer
time: 186ms
memory: 79036kb

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: 49ms
memory: 33756kb

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:

wrong answer 809th lines differ - expected: '78', found: '77'

Subtask #6:

score: 0
Wrong Answer

Test #97:

score: 0
Wrong Answer
time: 211ms
memory: 70420kb

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
19044
23488
1992
20887
9156
21248
15708
115
11736
8529
19157
9407
9139
5401
20114
1699
3993
22639
5925
17883
12913
5726
12378
21617
15763
646
5418
16982
7639
6140
1776
6289
619
766
3079
8806
11541
7217
2650
15835
2238
2024
9705
23983
4664
8898
5006
2392
20170
8341
14535
16454
6623
18...

result:

wrong answer 19733rd lines differ - expected: '6877', found: '6876'

Subtask #7:

score: 0
Skipped

Dependency #1:

0%