QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#875225#2747. MeetingsAlimkhan#17 59ms17780kbC++231.7kb2025-01-29 13:26:592025-01-29 13:27:00

Judging History

This is the latest submission verdict.

  • [2025-01-29 13:27:00]
  • Judged
  • Verdict: 17
  • Time: 59ms
  • Memory: 17780kb
  • [2025-01-29 13:26:59]
  • Submitted

answer

#include "meetings.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second

const int maxn = 1e6 + 10;

int n, q;
ll pref[maxn], a[maxn], t[maxn * 4];

void upd(int v, int tl, int tr, int p, int val) {
	if (tl == tr) {
		t[v] = val;
		return;
	}
	int tm = (tl + tr) / 2;
	if (p <= tm) {
		upd(v * 2, tl, tm, p, val);
	} else {
		upd(v * 2 + 1, tm + 1, tr, p, val);
	}
	t[v] = max(t[v * 2], t[v * 2 + 1]);
}

int get(int v, int tl, int tr, int l, int r) {
	if (tl > r || tr < l) {
		return 0;
	}
	if (tl >= l && tr <= r) {
		return t[v];
	}
	int tm = (tl + tr) / 2;
	return max(get(v * 2, tl, tm, l, r), get(v * 2 + 1, tm + 1, tr, l, r));
}

std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L, std::vector<int> R) {
	n = H.size();
	q = L.size();
	vector <ll> c(q);
	pref[0] = H[0];
	a[0] = (H[0] == 1);
	upd(1, 0, n - 1, 0, a[0]);
	for (int i = 1; i < n; i++) {
		pref[i] = pref[i - 1] + (H[i] == 1);
	}
	for (int i = 1; i < n; i++) {
		if (H[i] == 1) {
			a[i] = a[i - 1] + 1;
		} else {
			a[i] = 0;
		}
		upd(1, 0, n - 1, i, a[i]);
	}
	for (int i = 0; i < q; i++) {
		int mx = 0;
		if (H[L[i]] == 1) {
			int l = L[i], r = R[i] + 1;
			int x = 0;
			if (l > 0) {
				x = pref[l - 1];
			}
			while(r - l > 1) {
				int md = (l + r) / 2;
				if (pref[md] - x == md - L[i] + 1) {
					l = md;
				} else {
					r = md;
				}
			}
			mx = max(mx, l - L[i] + 1);
			if (r <= R[i]) {
				mx = max(mx, get(1, 0, n - 1, r, R[i]));
			}
		} else {
			mx = get(1, 0, n - 1, L[i], R[i]);
		}
		c[i] =  2 * (R[i] - L[i] + 1) - mx;
	}
	return c;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 8020kb

input:

1 1
877914575
0 0

output:

2

result:

wrong answer 1st lines differ - expected: '877914575', found: '2'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 17
Accepted

Test #16:

score: 17
Accepted
time: 1ms
memory: 8016kb

input:

1 1
2
0 0

output:

2

result:

ok single line: '2'

Test #17:

score: 17
Accepted
time: 19ms
memory: 8972kb

input:

8014 48643
2 2 1 2 2 1 2 1 1 1 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 2 2 1 2 1 1 2 1 1 2 1 2 2 1 1 2 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 2 2 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 2 2 1 1 2 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 1 2 2 1 2 1 1 2 2 2 2 2 2 1 2 2 1 1 1 2 1 1 1 1 2 1 2 2 1 1 1 1 1 1 2...

output:

3556
2463
7389
1531
8055
565
9221
4957
4500
11001
4663
6013
10655
426
331
1495
3961
2197
3543
2786
773
13953
13077
6111
9863
7113
1576
12305
9019
9511
1019
10123
412
8015
13491
9367
7363
2001
5417
8827
361
815
5863
4607
173
6827
5345
5214
3430
2512
11655
3621
9051
290
583
4363
4694
2789
2865
613
464...

result:

ok 48643 lines

Test #18:

score: 17
Accepted
time: 56ms
memory: 16052kb

input:

100000 100000
1 2 1 1 2 1 1 2 2 2 2 1 1 1 2 2 1 1 2 2 2 1 1 2 2 1 2 2 1 2 2 1 1 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 1 1 2 2 1 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 2 2 2 1 1 1 1 2 2 2 1 1 2 1 1 1 1 2 2 2 1 1 1 2 2 2 1 1 2 2 1 2 ...

output:

168406
42134
67627
116194
47354
158012
95896
13652
69190
25189
58555
5891
39157
57985
58625
46834
7568
171074
30777
12773
22617
39621
135830
150402
35852
12238
23716
47584
40985
14212
52815
38157
143640
123162
99249
55757
19360
150426
73095
166458
841
90320
77842
10383
191290
20379
115790
134622
474...

result:

ok 100000 lines

Test #19:

score: 17
Accepted
time: 59ms
memory: 17168kb

input:

100000 100000
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 ...

output:

15743
57781
66106
101101
36861
31252
10449
79635
92420
165205
146533
139493
39521
12850
137807
41264
58619
114891
26922
158531
14672
75092
23640
50018
50006
6319
4579
2374
88970
185401
102244
57954
54048
62615
29866
85908
129018
82033
95840
26771
14103
53794
61872
1189
95090
36596
29519
38167
41533
...

result:

ok 100000 lines

Test #20:

score: 17
Accepted
time: 33ms
memory: 17748kb

input:

100000 100000
2 2 2 1 2 2 2 1 2 1 2 1 1 2 2 2 2 1 2 2 1 1 2 2 1 1 2 1 1 2 2 2 1 2 1 2 1 2 1 2 2 1 2 2 1 1 1 1 2 1 1 1 2 2 2 2 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 1 2 1 1 2 1 2 2 2 2 1 2 1 2 2 1 2 1 2 1 2 1 1 1 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 1 2 2 2 2 2 2 2 1 1 1 ...

output:

2
1
1
1
1
1
2
1
1
2
1
2
2
2
1
2
2
2
2
1
1
2
2
1
1
1
1
1
1
2
1
2
2
2
1
2
1
2
2
2
2
1
2
2
2
2
2
1
1
1
1
2
2
1
2
2
1
2
2
2
2
2
1
2
2
1
1
2
1
1
2
1
2
1
2
1
1
2
1
2
1
2
1
1
2
1
2
2
2
2
1
2
2
1
2
2
1
2
1
1
1
1
2
1
2
1
1
2
1
1
1
1
2
2
1
1
1
2
2
1
1
2
1
2
2
2
2
2
1
2
2
1
1
1
1
2
2
2
2
2
2
1
2
2
2
1
2
2
1
1
...

result:

ok 100000 lines

Test #21:

score: 17
Accepted
time: 44ms
memory: 17708kb

input:

100000 100000
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 ...

output:

551
1102
1102
1102
619
551
551
784
1102
1102
898
1102
615
1102
1102
560
935
1102
1104
1102
1102
551
1102
551
1102
794
1102
765
551
1102
551
801
917
741
1102
1102
1102
1102
551
1047
726
748
1102
1102
551
660
551
1010
1102
551
1102
893
551
848
551
1102
551
1102
1102
551
1102
913
1013
733
575
1102
551
...

result:

ok 100000 lines

Test #22:

score: 17
Accepted
time: 51ms
memory: 17780kb

input:

100000 100000
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 ...

output:

93072
10048
127454
7287
10697
48837
23960
38279
52605
83423
38556
45086
41906
74620
12478
24472
18593
338
86059
43004
26175
49213
6017
3782
50721
48508
59681
112042
7237
42567
103692
32514
64561
6857
34165
33644
80940
62943
82703
78504
93112
5189
23728
84158
128054
49624
15315
45684
55108
54868
5523...

result:

ok 100000 lines

Subtask #4:

score: 0
Wrong Answer

Dependency #3:

100%
Accepted

Test #23:

score: 0
Wrong Answer
time: 55ms
memory: 17404kb

input:

100000 100000
7 8 10 1 18 12 13 14 17 15 9 5 1 15 15 9 20 15 9 16 11 16 20 13 14 5 20 8 16 12 20 1 12 11 11 5 13 12 17 20 7 2 11 17 15 13 7 14 19 17 14 9 20 20 3 15 2 19 11 17 8 14 16 10 5 13 8 15 8 15 20 4 13 3 7 4 9 18 6 20 2 18 7 4 13 6 3 16 3 4 6 17 12 9 19 2 7 1 6 8 15 20 8 6 19 2 14 5 4 8 2 5 ...

output:

24359
69949
64555
99883
3603
104351
79653
5556
24033
87979
3757
11906
58619
155457
43667
49667
99465
18908
60529
107951
45025
4294
121869
87871
70933
14791
78203
4617
55697
76421
27074
113645
76177
60295
41951
48393
28841
167565
17893
179289
6902
15860
15867
64211
13695
89113
1039
77203
168483
22883...

result:

wrong answer 1st lines differ - expected: '243321', found: '24359'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%