Submission #557191

# Submission time Handle Problem Language Result Execution time Memory
557191 2022-05-04T20:44:08 Z lunchbox Food Court (JOI21_foodcourt) C++17
24 / 100
339 ms 32724 KB
#include <bits/stdc++.h>
using namespace std;

using LL = long long;
const int N = 250000, N_ = 1 << 18, INF = 0x3f3f3f3f;

int n_;

array<LL, 2> st1[N_ * 2];

array<LL, 2> join(array<LL, 2> a, array<LL, 2> b) {
	return { a[0] + b[0], max(a[1] + b[0], b[1]) };
}

void update1(int i, int x) {
	i |= n_;
	st1[i][0] = x;
	st1[i][1] = max(0, x);
	while (i >>= 1)
		st1[i] = join(st1[i << 1 | 0], st1[i << 1 | 1]);
}

LL query1(int l, int r) {
	vector<int> ll, rr;
	array<LL, 2> v = { 0, 0 };

	for (l |= n_, r |= n_; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			ll.push_back(l++);
		if ((r & 1) == 0)
			rr.push_back(r--);
	}
	for (int i : ll)
		v = join(v, st1[i]);
	reverse(rr.begin(), rr.end());
	for (int i : rr)
		v = join(v, st1[i]);
	return v[1];
}

LL st2[N_ * 2];

void update2(int i, int x) {
	st2[i |= n_] = x;
	while (i >>= 1)
		st2[i] = st2[i << 1 | 0] + st2[i << 1 | 1];
}

LL query2(int l, int r) {
	LL sum = 0;

	for (l |= n_, r |= n_; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			sum += st2[l++];
		if ((r & 1) == 0)
			sum += st2[r--];
	}
	return sum;
}

int query3(LL x) {
	int i = 1;

	while (i < n_) {
		if (st2[i << 1 | 0] >= x)
			i = i << 1 | 0;
		else {
			x -= st2[i << 1 | 0];
			i = i << 1 | 1;
		}
	}
	if (st2[i] < x)
		i--;
	return i ^ n_;
}

vector<pair<int, int>> uu[N], qq[N];

void run() {
	static int cc[N], ans[N];
	int n, m, q;

	scanf("%d%d%d", &n, &m, &q);
	n_ = 1;
	while (n_ < q)
		n_ <<= 1;
	for (int h = 0; h < q; h++) {
		int t;

		scanf("%d", &t);
		if (t == 1) {
			int l, r, k;

			scanf("%d%d%d%d", &l, &r, &cc[h], &k), l--;
			uu[l].push_back({ h << 1 | 0, k });
			uu[r].push_back({ h << 1 | 0, 0 });
		} else if (t == 2) {
			int l, r, k;

			scanf("%d%d%d", &l, &r, &k), l--;
			uu[l].push_back({ h << 1 | 1, -k });
			uu[r].push_back({ h << 1 | 1, 0 });
		} else {
			int i, k;

			scanf("%d%d", &i, &k), i--;
			qq[i].push_back({ h, k });
		}
	}
	memset(ans, -1, q * sizeof * ans);
	for (int i = 0; i < n; i++) {
		for (auto [h2, k] : uu[i]) {
			int h = h2 >> 1;

			update1(h, k);
			if ((h2 & 1) == 0)
				update2(h, k);
		}
		for (auto [h, k] : qq[i]) {
			LL x = query1(0, h);

			ans[h] = x < k ? 0 : cc[query3(query2(0, h) - x + k)];
		}
	}
	for (int h = 0; h < q; h++)
		if (ans[h] != -1)
			printf("%d\n", ans[h]);
}

int main() {
	run();
	return 0;
}

Compilation message

foodcourt.cpp: In function 'void run()':
foodcourt.cpp:83:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |  scanf("%d%d%d", &n, &m, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:90:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |   scanf("%d", &t);
      |   ~~~~~^~~~~~~~~~
foodcourt.cpp:94:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |    scanf("%d%d%d%d", &l, &r, &cc[h], &k), l--;
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:100:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |    scanf("%d%d%d", &l, &r, &k), l--;
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:106:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |    scanf("%d%d", &i, &k), i--;
      |    ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12116 KB Output is correct
2 Correct 10 ms 12184 KB Output is correct
3 Correct 7 ms 12088 KB Output is correct
4 Correct 8 ms 12244 KB Output is correct
5 Correct 7 ms 12116 KB Output is correct
6 Correct 7 ms 12208 KB Output is correct
7 Correct 8 ms 12116 KB Output is correct
8 Correct 7 ms 12244 KB Output is correct
9 Correct 9 ms 12216 KB Output is correct
10 Correct 7 ms 12116 KB Output is correct
11 Correct 7 ms 12244 KB Output is correct
12 Correct 7 ms 12172 KB Output is correct
13 Correct 7 ms 12200 KB Output is correct
14 Correct 7 ms 12116 KB Output is correct
15 Correct 8 ms 12116 KB Output is correct
16 Correct 7 ms 12116 KB Output is correct
17 Correct 8 ms 12116 KB Output is correct
18 Correct 8 ms 12252 KB Output is correct
19 Correct 8 ms 12116 KB Output is correct
20 Correct 9 ms 12244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12116 KB Output is correct
2 Correct 10 ms 12184 KB Output is correct
3 Correct 7 ms 12088 KB Output is correct
4 Correct 8 ms 12244 KB Output is correct
5 Correct 7 ms 12116 KB Output is correct
6 Correct 7 ms 12208 KB Output is correct
7 Correct 8 ms 12116 KB Output is correct
8 Correct 7 ms 12244 KB Output is correct
9 Correct 9 ms 12216 KB Output is correct
10 Correct 7 ms 12116 KB Output is correct
11 Correct 7 ms 12244 KB Output is correct
12 Correct 7 ms 12172 KB Output is correct
13 Correct 7 ms 12200 KB Output is correct
14 Correct 7 ms 12116 KB Output is correct
15 Correct 8 ms 12116 KB Output is correct
16 Correct 7 ms 12116 KB Output is correct
17 Correct 8 ms 12116 KB Output is correct
18 Correct 8 ms 12252 KB Output is correct
19 Correct 8 ms 12116 KB Output is correct
20 Correct 9 ms 12244 KB Output is correct
21 Incorrect 8 ms 12116 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 17864 KB Output is correct
2 Correct 64 ms 17812 KB Output is correct
3 Correct 59 ms 17904 KB Output is correct
4 Correct 62 ms 17876 KB Output is correct
5 Correct 88 ms 17916 KB Output is correct
6 Correct 76 ms 17908 KB Output is correct
7 Correct 36 ms 16428 KB Output is correct
8 Correct 40 ms 16532 KB Output is correct
9 Correct 57 ms 17388 KB Output is correct
10 Correct 61 ms 17840 KB Output is correct
11 Correct 82 ms 17744 KB Output is correct
12 Correct 70 ms 17868 KB Output is correct
13 Correct 48 ms 17148 KB Output is correct
14 Correct 55 ms 17880 KB Output is correct
15 Correct 54 ms 17636 KB Output is correct
16 Correct 63 ms 17820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 339 ms 32724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12116 KB Output is correct
2 Correct 10 ms 12184 KB Output is correct
3 Correct 7 ms 12088 KB Output is correct
4 Correct 8 ms 12244 KB Output is correct
5 Correct 7 ms 12116 KB Output is correct
6 Correct 7 ms 12208 KB Output is correct
7 Correct 8 ms 12116 KB Output is correct
8 Correct 7 ms 12244 KB Output is correct
9 Correct 9 ms 12216 KB Output is correct
10 Correct 7 ms 12116 KB Output is correct
11 Correct 7 ms 12244 KB Output is correct
12 Correct 7 ms 12172 KB Output is correct
13 Correct 7 ms 12200 KB Output is correct
14 Correct 7 ms 12116 KB Output is correct
15 Correct 8 ms 12116 KB Output is correct
16 Correct 7 ms 12116 KB Output is correct
17 Correct 8 ms 12116 KB Output is correct
18 Correct 8 ms 12252 KB Output is correct
19 Correct 8 ms 12116 KB Output is correct
20 Correct 9 ms 12244 KB Output is correct
21 Correct 62 ms 17864 KB Output is correct
22 Correct 64 ms 17812 KB Output is correct
23 Correct 59 ms 17904 KB Output is correct
24 Correct 62 ms 17876 KB Output is correct
25 Correct 88 ms 17916 KB Output is correct
26 Correct 76 ms 17908 KB Output is correct
27 Correct 36 ms 16428 KB Output is correct
28 Correct 40 ms 16532 KB Output is correct
29 Correct 57 ms 17388 KB Output is correct
30 Correct 61 ms 17840 KB Output is correct
31 Correct 82 ms 17744 KB Output is correct
32 Correct 70 ms 17868 KB Output is correct
33 Correct 48 ms 17148 KB Output is correct
34 Correct 55 ms 17880 KB Output is correct
35 Correct 54 ms 17636 KB Output is correct
36 Correct 63 ms 17820 KB Output is correct
37 Correct 56 ms 17356 KB Output is correct
38 Correct 56 ms 16764 KB Output is correct
39 Correct 33 ms 15932 KB Output is correct
40 Correct 44 ms 16452 KB Output is correct
41 Correct 69 ms 17272 KB Output is correct
42 Correct 58 ms 17936 KB Output is correct
43 Correct 57 ms 17832 KB Output is correct
44 Correct 61 ms 17612 KB Output is correct
45 Correct 67 ms 17848 KB Output is correct
46 Correct 63 ms 17844 KB Output is correct
47 Correct 50 ms 16944 KB Output is correct
48 Correct 58 ms 17396 KB Output is correct
49 Correct 40 ms 16212 KB Output is correct
50 Correct 48 ms 17068 KB Output is correct
51 Correct 56 ms 17872 KB Output is correct
52 Correct 65 ms 17856 KB Output is correct
53 Correct 45 ms 16592 KB Output is correct
54 Correct 86 ms 17732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 17292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12116 KB Output is correct
2 Correct 10 ms 12184 KB Output is correct
3 Correct 7 ms 12088 KB Output is correct
4 Correct 8 ms 12244 KB Output is correct
5 Correct 7 ms 12116 KB Output is correct
6 Correct 7 ms 12208 KB Output is correct
7 Correct 8 ms 12116 KB Output is correct
8 Correct 7 ms 12244 KB Output is correct
9 Correct 9 ms 12216 KB Output is correct
10 Correct 7 ms 12116 KB Output is correct
11 Correct 7 ms 12244 KB Output is correct
12 Correct 7 ms 12172 KB Output is correct
13 Correct 7 ms 12200 KB Output is correct
14 Correct 7 ms 12116 KB Output is correct
15 Correct 8 ms 12116 KB Output is correct
16 Correct 7 ms 12116 KB Output is correct
17 Correct 8 ms 12116 KB Output is correct
18 Correct 8 ms 12252 KB Output is correct
19 Correct 8 ms 12116 KB Output is correct
20 Correct 9 ms 12244 KB Output is correct
21 Incorrect 8 ms 12116 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12116 KB Output is correct
2 Correct 10 ms 12184 KB Output is correct
3 Correct 7 ms 12088 KB Output is correct
4 Correct 8 ms 12244 KB Output is correct
5 Correct 7 ms 12116 KB Output is correct
6 Correct 7 ms 12208 KB Output is correct
7 Correct 8 ms 12116 KB Output is correct
8 Correct 7 ms 12244 KB Output is correct
9 Correct 9 ms 12216 KB Output is correct
10 Correct 7 ms 12116 KB Output is correct
11 Correct 7 ms 12244 KB Output is correct
12 Correct 7 ms 12172 KB Output is correct
13 Correct 7 ms 12200 KB Output is correct
14 Correct 7 ms 12116 KB Output is correct
15 Correct 8 ms 12116 KB Output is correct
16 Correct 7 ms 12116 KB Output is correct
17 Correct 8 ms 12116 KB Output is correct
18 Correct 8 ms 12252 KB Output is correct
19 Correct 8 ms 12116 KB Output is correct
20 Correct 9 ms 12244 KB Output is correct
21 Incorrect 8 ms 12116 KB Output isn't correct
22 Halted 0 ms 0 KB -