Submission #810932

# Submission time Handle Problem Language Result Execution time Memory
810932 2023-08-06T17:44:01 Z parsadox2 Food Court (JOI21_foodcourt) C++14
68 / 100
1000 ms 62988 KB
#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn = 25e4 + 10;
int n , m , q , k[maxn] , c[maxn] , ans[maxn];
vector <int> ask[maxn] , all[2][maxn];

struct nod{
	int sum , sum_neg , suf_sum;
	nod()
	{
		sum = 0;
		sum_neg = 0;
		suf_sum = 0;
	}
} tree[maxn << 2];

nod Merge(nod a , nod b)
{
	nod res;
	res.sum_neg = a.sum_neg + b.sum_neg;
	res.sum = a.sum + b.sum;
	res.suf_sum = max(b.suf_sum , b.sum + a.suf_sum);
	return res;
}

void Add(int ind , int val , int ty = 1 , int node = 1 , int nl = 0 , int nr = q)
{
	if(nr - nl == 1)
	{
		tree[node].sum = 1LL * ty * val;
		tree[node].sum_neg = min(0LL , tree[node].sum);
		tree[node].suf_sum = max(tree[node].sum , 0LL);
		return;
	}
	int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
	if(ind < mid)
		Add(ind , val , ty , lc , nl , mid);
	else
		Add(ind , val , ty , rc , mid , nr);
	tree[node] = Merge(tree[lc] , tree[rc]);
}

nod Get(int l , int r , int node = 1 , int nl = 0 , int nr = q)
{
	if(r <= nl || nr <= l)
	{
		nod tmp;
		return tmp;
	}
	if(l <= nl && nr <= r)
		return tree[node];
	int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
	return Merge(Get(l , r , lc , nl , mid) , Get(l , r , rc , mid , nr));
}

int solve(int ind)
{
	nod check = Get(0 , ind);
	int val = k[ind];
	if(check.suf_sum < val)
		return 0;
	int low = -1 , high = ind - 1;
	while(high - low > 1)
	{
		int mid = (high + low) >> 1;
		nod g1 = Get(0 , mid + 1) , g2 = Get(mid + 1 , ind);
		int tmp = g1.suf_sum + g2.sum_neg;
		if(tmp >= val)
			high = mid;
		else
			low = mid;
	}
	return c[high];
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout.tie(0);
	memset(ans , -1 , sizeof ans);
	cin >> n >> m >> q;
	for(int i = 0 ; i < q ; i++)
	{
		int ty;  cin >> ty;
		if(ty == 1)
		{
			int l , r;  cin >> l >> r >> c[i] >> k[i];
			all[0][l].push_back(i);
			all[1][r].push_back(i);
		}
		else if(ty == 2)
		{
			int l , r;  cin >> l >> r >> k[i];
			k[i] = -1LL * k[i];
			all[0][l].push_back(i);
			all[1][r].push_back(i);
		}
		else
		{
			int a;  cin >> a >> k[i];
			ask[a].push_back(i);
		}
	}
	for(int i = 1 ; i <= n ; i++)
	{
		for(auto u : all[0][i])
		{
			//cout << "Hi Add" << endl;
			Add(u , k[u]);
			//cout << "Bye Add" << endl;
		}
		for(auto u : ask[i])
		{
			//cout << "Hi solve" << endl;
			ans[u] = solve(u);
			//cout << "Bye solve" << endl;
		}
		for(auto u : all[1][i])
			Add(u , k[u] , 0);
	}
	for(int i = 0 ; i < q ; i++)  if(ans[i] != -1)
		cout << ans[i] << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 43388 KB Output is correct
2 Correct 21 ms 43476 KB Output is correct
3 Correct 21 ms 43476 KB Output is correct
4 Correct 21 ms 43524 KB Output is correct
5 Correct 23 ms 43484 KB Output is correct
6 Correct 21 ms 43440 KB Output is correct
7 Correct 22 ms 43476 KB Output is correct
8 Correct 22 ms 43524 KB Output is correct
9 Correct 22 ms 43452 KB Output is correct
10 Correct 22 ms 43424 KB Output is correct
11 Correct 22 ms 43520 KB Output is correct
12 Correct 22 ms 43448 KB Output is correct
13 Correct 21 ms 43476 KB Output is correct
14 Correct 22 ms 43476 KB Output is correct
15 Correct 23 ms 43348 KB Output is correct
16 Correct 23 ms 43548 KB Output is correct
17 Correct 21 ms 43396 KB Output is correct
18 Correct 21 ms 43392 KB Output is correct
19 Correct 21 ms 43468 KB Output is correct
20 Correct 22 ms 43476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 43388 KB Output is correct
2 Correct 21 ms 43476 KB Output is correct
3 Correct 21 ms 43476 KB Output is correct
4 Correct 21 ms 43524 KB Output is correct
5 Correct 23 ms 43484 KB Output is correct
6 Correct 21 ms 43440 KB Output is correct
7 Correct 22 ms 43476 KB Output is correct
8 Correct 22 ms 43524 KB Output is correct
9 Correct 22 ms 43452 KB Output is correct
10 Correct 22 ms 43424 KB Output is correct
11 Correct 22 ms 43520 KB Output is correct
12 Correct 22 ms 43448 KB Output is correct
13 Correct 21 ms 43476 KB Output is correct
14 Correct 22 ms 43476 KB Output is correct
15 Correct 23 ms 43348 KB Output is correct
16 Correct 23 ms 43548 KB Output is correct
17 Correct 21 ms 43396 KB Output is correct
18 Correct 21 ms 43392 KB Output is correct
19 Correct 21 ms 43468 KB Output is correct
20 Correct 22 ms 43476 KB Output is correct
21 Correct 22 ms 43480 KB Output is correct
22 Correct 22 ms 43484 KB Output is correct
23 Correct 21 ms 43500 KB Output is correct
24 Correct 22 ms 43468 KB Output is correct
25 Correct 21 ms 43436 KB Output is correct
26 Correct 22 ms 43476 KB Output is correct
27 Correct 23 ms 43476 KB Output is correct
28 Correct 22 ms 43468 KB Output is correct
29 Correct 22 ms 43504 KB Output is correct
30 Correct 23 ms 43524 KB Output is correct
31 Correct 22 ms 43456 KB Output is correct
32 Correct 23 ms 43524 KB Output is correct
33 Correct 22 ms 43444 KB Output is correct
34 Correct 24 ms 43480 KB Output is correct
35 Correct 22 ms 43400 KB Output is correct
36 Correct 23 ms 43512 KB Output is correct
37 Correct 20 ms 43432 KB Output is correct
38 Correct 23 ms 43416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 47736 KB Output is correct
2 Correct 81 ms 48332 KB Output is correct
3 Correct 87 ms 48204 KB Output is correct
4 Correct 86 ms 48116 KB Output is correct
5 Correct 81 ms 48204 KB Output is correct
6 Correct 91 ms 48352 KB Output is correct
7 Correct 93 ms 46080 KB Output is correct
8 Correct 96 ms 46404 KB Output is correct
9 Correct 83 ms 48016 KB Output is correct
10 Correct 80 ms 48252 KB Output is correct
11 Correct 81 ms 48168 KB Output is correct
12 Correct 82 ms 48252 KB Output is correct
13 Correct 97 ms 47372 KB Output is correct
14 Correct 108 ms 48096 KB Output is correct
15 Correct 75 ms 48036 KB Output is correct
16 Correct 89 ms 48572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 734 ms 57420 KB Output is correct
2 Correct 583 ms 57688 KB Output is correct
3 Correct 831 ms 62988 KB Output is correct
4 Correct 494 ms 58000 KB Output is correct
5 Correct 498 ms 57892 KB Output is correct
6 Correct 699 ms 62960 KB Output is correct
7 Correct 550 ms 55724 KB Output is correct
8 Correct 588 ms 55688 KB Output is correct
9 Execution timed out 1054 ms 62260 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 43388 KB Output is correct
2 Correct 21 ms 43476 KB Output is correct
3 Correct 21 ms 43476 KB Output is correct
4 Correct 21 ms 43524 KB Output is correct
5 Correct 23 ms 43484 KB Output is correct
6 Correct 21 ms 43440 KB Output is correct
7 Correct 22 ms 43476 KB Output is correct
8 Correct 22 ms 43524 KB Output is correct
9 Correct 22 ms 43452 KB Output is correct
10 Correct 22 ms 43424 KB Output is correct
11 Correct 22 ms 43520 KB Output is correct
12 Correct 22 ms 43448 KB Output is correct
13 Correct 21 ms 43476 KB Output is correct
14 Correct 22 ms 43476 KB Output is correct
15 Correct 23 ms 43348 KB Output is correct
16 Correct 23 ms 43548 KB Output is correct
17 Correct 21 ms 43396 KB Output is correct
18 Correct 21 ms 43392 KB Output is correct
19 Correct 21 ms 43468 KB Output is correct
20 Correct 22 ms 43476 KB Output is correct
21 Correct 96 ms 47736 KB Output is correct
22 Correct 81 ms 48332 KB Output is correct
23 Correct 87 ms 48204 KB Output is correct
24 Correct 86 ms 48116 KB Output is correct
25 Correct 81 ms 48204 KB Output is correct
26 Correct 91 ms 48352 KB Output is correct
27 Correct 93 ms 46080 KB Output is correct
28 Correct 96 ms 46404 KB Output is correct
29 Correct 83 ms 48016 KB Output is correct
30 Correct 80 ms 48252 KB Output is correct
31 Correct 81 ms 48168 KB Output is correct
32 Correct 82 ms 48252 KB Output is correct
33 Correct 97 ms 47372 KB Output is correct
34 Correct 108 ms 48096 KB Output is correct
35 Correct 75 ms 48036 KB Output is correct
36 Correct 89 ms 48572 KB Output is correct
37 Correct 149 ms 47436 KB Output is correct
38 Correct 114 ms 47092 KB Output is correct
39 Correct 95 ms 45616 KB Output is correct
40 Correct 109 ms 46152 KB Output is correct
41 Correct 141 ms 47644 KB Output is correct
42 Correct 141 ms 48076 KB Output is correct
43 Correct 145 ms 47872 KB Output is correct
44 Correct 140 ms 47768 KB Output is correct
45 Correct 140 ms 47924 KB Output is correct
46 Correct 142 ms 47864 KB Output is correct
47 Correct 176 ms 46560 KB Output is correct
48 Correct 152 ms 47180 KB Output is correct
49 Correct 91 ms 46572 KB Output is correct
50 Correct 115 ms 47356 KB Output is correct
51 Correct 134 ms 48000 KB Output is correct
52 Correct 126 ms 47960 KB Output is correct
53 Correct 67 ms 47300 KB Output is correct
54 Correct 77 ms 48268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 206 ms 47308 KB Output is correct
2 Correct 227 ms 48328 KB Output is correct
3 Correct 229 ms 48492 KB Output is correct
4 Correct 162 ms 46928 KB Output is correct
5 Correct 189 ms 47692 KB Output is correct
6 Correct 220 ms 48408 KB Output is correct
7 Correct 199 ms 46304 KB Output is correct
8 Correct 161 ms 46148 KB Output is correct
9 Correct 205 ms 47332 KB Output is correct
10 Correct 150 ms 46380 KB Output is correct
11 Correct 224 ms 47716 KB Output is correct
12 Correct 213 ms 47572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 43388 KB Output is correct
2 Correct 21 ms 43476 KB Output is correct
3 Correct 21 ms 43476 KB Output is correct
4 Correct 21 ms 43524 KB Output is correct
5 Correct 23 ms 43484 KB Output is correct
6 Correct 21 ms 43440 KB Output is correct
7 Correct 22 ms 43476 KB Output is correct
8 Correct 22 ms 43524 KB Output is correct
9 Correct 22 ms 43452 KB Output is correct
10 Correct 22 ms 43424 KB Output is correct
11 Correct 22 ms 43520 KB Output is correct
12 Correct 22 ms 43448 KB Output is correct
13 Correct 21 ms 43476 KB Output is correct
14 Correct 22 ms 43476 KB Output is correct
15 Correct 23 ms 43348 KB Output is correct
16 Correct 23 ms 43548 KB Output is correct
17 Correct 21 ms 43396 KB Output is correct
18 Correct 21 ms 43392 KB Output is correct
19 Correct 21 ms 43468 KB Output is correct
20 Correct 22 ms 43476 KB Output is correct
21 Correct 22 ms 43480 KB Output is correct
22 Correct 22 ms 43484 KB Output is correct
23 Correct 21 ms 43500 KB Output is correct
24 Correct 22 ms 43468 KB Output is correct
25 Correct 21 ms 43436 KB Output is correct
26 Correct 22 ms 43476 KB Output is correct
27 Correct 23 ms 43476 KB Output is correct
28 Correct 22 ms 43468 KB Output is correct
29 Correct 22 ms 43504 KB Output is correct
30 Correct 23 ms 43524 KB Output is correct
31 Correct 22 ms 43456 KB Output is correct
32 Correct 23 ms 43524 KB Output is correct
33 Correct 22 ms 43444 KB Output is correct
34 Correct 24 ms 43480 KB Output is correct
35 Correct 22 ms 43400 KB Output is correct
36 Correct 23 ms 43512 KB Output is correct
37 Correct 20 ms 43432 KB Output is correct
38 Correct 23 ms 43416 KB Output is correct
39 Correct 96 ms 47736 KB Output is correct
40 Correct 81 ms 48332 KB Output is correct
41 Correct 87 ms 48204 KB Output is correct
42 Correct 86 ms 48116 KB Output is correct
43 Correct 81 ms 48204 KB Output is correct
44 Correct 91 ms 48352 KB Output is correct
45 Correct 93 ms 46080 KB Output is correct
46 Correct 96 ms 46404 KB Output is correct
47 Correct 83 ms 48016 KB Output is correct
48 Correct 80 ms 48252 KB Output is correct
49 Correct 81 ms 48168 KB Output is correct
50 Correct 82 ms 48252 KB Output is correct
51 Correct 97 ms 47372 KB Output is correct
52 Correct 108 ms 48096 KB Output is correct
53 Correct 75 ms 48036 KB Output is correct
54 Correct 89 ms 48572 KB Output is correct
55 Correct 149 ms 47436 KB Output is correct
56 Correct 114 ms 47092 KB Output is correct
57 Correct 95 ms 45616 KB Output is correct
58 Correct 109 ms 46152 KB Output is correct
59 Correct 141 ms 47644 KB Output is correct
60 Correct 141 ms 48076 KB Output is correct
61 Correct 145 ms 47872 KB Output is correct
62 Correct 140 ms 47768 KB Output is correct
63 Correct 140 ms 47924 KB Output is correct
64 Correct 142 ms 47864 KB Output is correct
65 Correct 176 ms 46560 KB Output is correct
66 Correct 152 ms 47180 KB Output is correct
67 Correct 91 ms 46572 KB Output is correct
68 Correct 115 ms 47356 KB Output is correct
69 Correct 134 ms 48000 KB Output is correct
70 Correct 126 ms 47960 KB Output is correct
71 Correct 67 ms 47300 KB Output is correct
72 Correct 77 ms 48268 KB Output is correct
73 Correct 206 ms 47308 KB Output is correct
74 Correct 227 ms 48328 KB Output is correct
75 Correct 229 ms 48492 KB Output is correct
76 Correct 162 ms 46928 KB Output is correct
77 Correct 189 ms 47692 KB Output is correct
78 Correct 220 ms 48408 KB Output is correct
79 Correct 199 ms 46304 KB Output is correct
80 Correct 161 ms 46148 KB Output is correct
81 Correct 205 ms 47332 KB Output is correct
82 Correct 150 ms 46380 KB Output is correct
83 Correct 224 ms 47716 KB Output is correct
84 Correct 213 ms 47572 KB Output is correct
85 Correct 150 ms 47948 KB Output is correct
86 Correct 194 ms 48448 KB Output is correct
87 Correct 129 ms 47916 KB Output is correct
88 Correct 147 ms 48552 KB Output is correct
89 Correct 100 ms 46648 KB Output is correct
90 Correct 153 ms 48472 KB Output is correct
91 Correct 117 ms 47436 KB Output is correct
92 Correct 115 ms 47220 KB Output is correct
93 Correct 143 ms 48388 KB Output is correct
94 Correct 160 ms 48348 KB Output is correct
95 Correct 141 ms 48244 KB Output is correct
96 Correct 144 ms 48420 KB Output is correct
97 Correct 138 ms 48380 KB Output is correct
98 Correct 138 ms 47572 KB Output is correct
99 Correct 150 ms 47068 KB Output is correct
100 Correct 131 ms 46820 KB Output is correct
101 Correct 155 ms 47692 KB Output is correct
102 Correct 121 ms 48992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 43388 KB Output is correct
2 Correct 21 ms 43476 KB Output is correct
3 Correct 21 ms 43476 KB Output is correct
4 Correct 21 ms 43524 KB Output is correct
5 Correct 23 ms 43484 KB Output is correct
6 Correct 21 ms 43440 KB Output is correct
7 Correct 22 ms 43476 KB Output is correct
8 Correct 22 ms 43524 KB Output is correct
9 Correct 22 ms 43452 KB Output is correct
10 Correct 22 ms 43424 KB Output is correct
11 Correct 22 ms 43520 KB Output is correct
12 Correct 22 ms 43448 KB Output is correct
13 Correct 21 ms 43476 KB Output is correct
14 Correct 22 ms 43476 KB Output is correct
15 Correct 23 ms 43348 KB Output is correct
16 Correct 23 ms 43548 KB Output is correct
17 Correct 21 ms 43396 KB Output is correct
18 Correct 21 ms 43392 KB Output is correct
19 Correct 21 ms 43468 KB Output is correct
20 Correct 22 ms 43476 KB Output is correct
21 Correct 22 ms 43480 KB Output is correct
22 Correct 22 ms 43484 KB Output is correct
23 Correct 21 ms 43500 KB Output is correct
24 Correct 22 ms 43468 KB Output is correct
25 Correct 21 ms 43436 KB Output is correct
26 Correct 22 ms 43476 KB Output is correct
27 Correct 23 ms 43476 KB Output is correct
28 Correct 22 ms 43468 KB Output is correct
29 Correct 22 ms 43504 KB Output is correct
30 Correct 23 ms 43524 KB Output is correct
31 Correct 22 ms 43456 KB Output is correct
32 Correct 23 ms 43524 KB Output is correct
33 Correct 22 ms 43444 KB Output is correct
34 Correct 24 ms 43480 KB Output is correct
35 Correct 22 ms 43400 KB Output is correct
36 Correct 23 ms 43512 KB Output is correct
37 Correct 20 ms 43432 KB Output is correct
38 Correct 23 ms 43416 KB Output is correct
39 Correct 96 ms 47736 KB Output is correct
40 Correct 81 ms 48332 KB Output is correct
41 Correct 87 ms 48204 KB Output is correct
42 Correct 86 ms 48116 KB Output is correct
43 Correct 81 ms 48204 KB Output is correct
44 Correct 91 ms 48352 KB Output is correct
45 Correct 93 ms 46080 KB Output is correct
46 Correct 96 ms 46404 KB Output is correct
47 Correct 83 ms 48016 KB Output is correct
48 Correct 80 ms 48252 KB Output is correct
49 Correct 81 ms 48168 KB Output is correct
50 Correct 82 ms 48252 KB Output is correct
51 Correct 97 ms 47372 KB Output is correct
52 Correct 108 ms 48096 KB Output is correct
53 Correct 75 ms 48036 KB Output is correct
54 Correct 89 ms 48572 KB Output is correct
55 Correct 734 ms 57420 KB Output is correct
56 Correct 583 ms 57688 KB Output is correct
57 Correct 831 ms 62988 KB Output is correct
58 Correct 494 ms 58000 KB Output is correct
59 Correct 498 ms 57892 KB Output is correct
60 Correct 699 ms 62960 KB Output is correct
61 Correct 550 ms 55724 KB Output is correct
62 Correct 588 ms 55688 KB Output is correct
63 Execution timed out 1054 ms 62260 KB Time limit exceeded
64 Halted 0 ms 0 KB -