QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#875215#2747. MeetingsAlimkhan#0 17ms8868kbC++231.6kb2025-01-29 13:09:362025-01-29 13:09:36

Judging History

This is the latest submission verdict.

  • [2025-01-29 13:09:36]
  • Judged
  • Verdict: 0
  • Time: 17ms
  • Memory: 8868kb
  • [2025-01-29 13:09:36]
  • 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];
	}
	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 + 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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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: 0
Wrong Answer

Test #16:

score: 17
Accepted
time: 0ms
memory: 8012kb

input:

1 1
2
0 0

output:

2

result:

ok single line: '2'

Test #17:

score: 0
Wrong Answer
time: 17ms
memory: 8868kb

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:

wrong answer 299th lines differ - expected: '709', found: '707'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%