Submission #960303

# Submission time Handle Problem Language Result Execution time Memory
960303 2024-04-10T08:08:23 Z aaron_dcoder Food Court (JOI21_foodcourt) C++17
68 / 100
1000 ms 60784 KB
#define NDEBUG

#ifdef NDEBUG

#define dbg(TXT) (void)0;
#define dbgv(VAR) (void)0;
#define dbgfor if constexpr (false) for

#else

#define _GLIBCXX_DEBUG
#define dbg(TXT) cerr << TXT << "\n";
#define dbgv(VAR) cerr << #VAR << " = " << VAR <<", line "<< __LINE__ << '\n';
#define dbgfor for

#endif

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair<ll,ll>;
#define e0 first
#define e1 second

constexpr ll INFTY = 2e18;

struct segtree
{
	vector<ll> toadd;
	vector<ll> currfloor;

	segtree(ll n)
	{
		toadd.assign(4*n,0);
		currfloor.assign(4*n,0);
	}

	void add(ll val, ll base, ll baseforced, ll lseg, ll rseg, ll l, ll r, ll node)
	{
		currfloor[node] = max(currfloor[node],baseforced);
		if (rseg<l || r<lseg) return;

		if (lseg<=l && r<=rseg)
		{
			toadd[node]+=val;
			currfloor[node] = max(currfloor[node],base);
			currfloor[node]+=val;
			return;
		}


		ll mid = (l+r)/2;
		add(val, base-toadd[node], currfloor[node]-toadd[node], lseg, rseg, l,mid,node*2);
		add(val, base-toadd[node], currfloor[node]-toadd[node], lseg, rseg, mid+1,r,node*2+1);
		currfloor[node]=-INFTY;
	}

	ll get(ll x, ll l, ll r, ll node)
	{
		if (x<l || r<x) return 0;

		if (l==r)
		{
			return currfloor[node];
		}

		ll mid = (l+r)/2;
		return max(toadd[node]+(get(x, l,mid,node*2)+get(x, mid+1,r,node*2+1)),currfloor[node]);
	}
};

int main()
{
	ll N,M,Q;
	cin >> N >> M >> Q;


	segtree stree(N);
	segtree totsize(N);

	vector<vector<pll>> tofind(N+1,vector<pll>{});
	vector<vector<pll>> tostart(N+1,vector<pll>{});
	vector<vector<ll>> toend(N+1,vector<ll>{});
	vector<ll> q_group(Q,-1);

	vector<ll> ans(Q,-1);


	for (ll qno = 0; qno < Q; ++qno)
	{
		ll t;
		cin >> t;

		if (t==1)
		{
			ll l,r,k;
			cin >> l >> r >> q_group[qno] >> k;

			tostart[l].push_back({k,qno});
			toend[r].push_back(qno);

			totsize.add(k,0,-INFTY,l,r, 1,N,1);
			stree.add(k,0,-INFTY,l,r, 1,N,1);
		}
		else if (t==2)
		{
			ll l,r,k;
			cin >> l >> r >> k;
			stree.add(-k,k,-INFTY,l,r, 1,N,1);
		}
		else
		{
			assert(t==3);
			ll a,b;
			cin >> a >> b;
			if (b>stree.get(a, 1,N,1))
			{
				ans[qno]=0;
			}
			else
			{
				tofind[a].push_back({totsize.get(a, 1,N,1)-(stree.get(a, 1,N,1)-b),qno});
			}
		}
	}

	vector<ll> currpeeps(Q,0);
	for (ll i = 1; i <= N; ++i)
	{
		for (auto [k ,qno] :tostart[i])
		{
			assert(currpeeps[qno]==0);
			currpeeps[qno]=k;
		}

		for (auto [numpeeps, qno]:tofind[i])
		{
			ll cs=0;
			ll qidx=0;
			while (cs<numpeeps)
			{
				cs+=currpeeps[qidx];
				qidx++;
			}
			qidx--;
			ans[qno]=q_group[qidx];
		}
		

		for (ll qno :toend[i])
		{
			assert(currpeeps[qno]!=0);
			currpeeps[qno]=0;
		}
	}

	for (ll i : ans)
	{
		if (i!=-1) cout << i << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 756 KB Output is correct
2 Correct 3 ms 856 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 3 ms 960 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 756 KB Output is correct
2 Correct 3 ms 856 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 3 ms 960 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 4 ms 932 KB Output is correct
23 Correct 4 ms 604 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 3 ms 952 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 3 ms 860 KB Output is correct
35 Correct 3 ms 860 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 2 ms 700 KB Output is correct
38 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 16868 KB Output is correct
2 Correct 83 ms 17476 KB Output is correct
3 Correct 95 ms 16980 KB Output is correct
4 Correct 98 ms 16864 KB Output is correct
5 Correct 86 ms 17588 KB Output is correct
6 Correct 92 ms 17572 KB Output is correct
7 Correct 122 ms 3444 KB Output is correct
8 Correct 137 ms 3156 KB Output is correct
9 Correct 92 ms 17108 KB Output is correct
10 Correct 87 ms 17232 KB Output is correct
11 Correct 93 ms 17236 KB Output is correct
12 Correct 85 ms 17168 KB Output is correct
13 Correct 126 ms 13092 KB Output is correct
14 Correct 156 ms 17744 KB Output is correct
15 Correct 110 ms 14484 KB Output is correct
16 Correct 137 ms 18628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1039 ms 60784 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 756 KB Output is correct
2 Correct 3 ms 856 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 3 ms 960 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 80 ms 16868 KB Output is correct
22 Correct 83 ms 17476 KB Output is correct
23 Correct 95 ms 16980 KB Output is correct
24 Correct 98 ms 16864 KB Output is correct
25 Correct 86 ms 17588 KB Output is correct
26 Correct 92 ms 17572 KB Output is correct
27 Correct 122 ms 3444 KB Output is correct
28 Correct 137 ms 3156 KB Output is correct
29 Correct 92 ms 17108 KB Output is correct
30 Correct 87 ms 17232 KB Output is correct
31 Correct 93 ms 17236 KB Output is correct
32 Correct 85 ms 17168 KB Output is correct
33 Correct 126 ms 13092 KB Output is correct
34 Correct 156 ms 17744 KB Output is correct
35 Correct 110 ms 14484 KB Output is correct
36 Correct 137 ms 18628 KB Output is correct
37 Correct 247 ms 15692 KB Output is correct
38 Correct 159 ms 15628 KB Output is correct
39 Correct 137 ms 3224 KB Output is correct
40 Correct 187 ms 3528 KB Output is correct
41 Correct 182 ms 17232 KB Output is correct
42 Correct 211 ms 17232 KB Output is correct
43 Correct 244 ms 17236 KB Output is correct
44 Correct 233 ms 17344 KB Output is correct
45 Correct 237 ms 17344 KB Output is correct
46 Correct 267 ms 17236 KB Output is correct
47 Correct 275 ms 16532 KB Output is correct
48 Correct 300 ms 16872 KB Output is correct
49 Correct 131 ms 12244 KB Output is correct
50 Correct 183 ms 16752 KB Output is correct
51 Correct 243 ms 17232 KB Output is correct
52 Correct 231 ms 17360 KB Output is correct
53 Correct 76 ms 15696 KB Output is correct
54 Correct 102 ms 18532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 254 ms 17744 KB Output is correct
2 Correct 295 ms 16720 KB Output is correct
3 Correct 350 ms 18636 KB Output is correct
4 Correct 181 ms 16344 KB Output is correct
5 Correct 244 ms 17392 KB Output is correct
6 Correct 321 ms 18564 KB Output is correct
7 Correct 232 ms 4168 KB Output is correct
8 Correct 175 ms 4248 KB Output is correct
9 Correct 283 ms 17872 KB Output is correct
10 Correct 164 ms 15100 KB Output is correct
11 Correct 322 ms 17960 KB Output is correct
12 Correct 310 ms 17992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 756 KB Output is correct
2 Correct 3 ms 856 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 3 ms 960 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 4 ms 932 KB Output is correct
23 Correct 4 ms 604 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 3 ms 952 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 3 ms 860 KB Output is correct
35 Correct 3 ms 860 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 2 ms 700 KB Output is correct
38 Correct 3 ms 860 KB Output is correct
39 Correct 80 ms 16868 KB Output is correct
40 Correct 83 ms 17476 KB Output is correct
41 Correct 95 ms 16980 KB Output is correct
42 Correct 98 ms 16864 KB Output is correct
43 Correct 86 ms 17588 KB Output is correct
44 Correct 92 ms 17572 KB Output is correct
45 Correct 122 ms 3444 KB Output is correct
46 Correct 137 ms 3156 KB Output is correct
47 Correct 92 ms 17108 KB Output is correct
48 Correct 87 ms 17232 KB Output is correct
49 Correct 93 ms 17236 KB Output is correct
50 Correct 85 ms 17168 KB Output is correct
51 Correct 126 ms 13092 KB Output is correct
52 Correct 156 ms 17744 KB Output is correct
53 Correct 110 ms 14484 KB Output is correct
54 Correct 137 ms 18628 KB Output is correct
55 Correct 247 ms 15692 KB Output is correct
56 Correct 159 ms 15628 KB Output is correct
57 Correct 137 ms 3224 KB Output is correct
58 Correct 187 ms 3528 KB Output is correct
59 Correct 182 ms 17232 KB Output is correct
60 Correct 211 ms 17232 KB Output is correct
61 Correct 244 ms 17236 KB Output is correct
62 Correct 233 ms 17344 KB Output is correct
63 Correct 237 ms 17344 KB Output is correct
64 Correct 267 ms 17236 KB Output is correct
65 Correct 275 ms 16532 KB Output is correct
66 Correct 300 ms 16872 KB Output is correct
67 Correct 131 ms 12244 KB Output is correct
68 Correct 183 ms 16752 KB Output is correct
69 Correct 243 ms 17232 KB Output is correct
70 Correct 231 ms 17360 KB Output is correct
71 Correct 76 ms 15696 KB Output is correct
72 Correct 102 ms 18532 KB Output is correct
73 Correct 254 ms 17744 KB Output is correct
74 Correct 295 ms 16720 KB Output is correct
75 Correct 350 ms 18636 KB Output is correct
76 Correct 181 ms 16344 KB Output is correct
77 Correct 244 ms 17392 KB Output is correct
78 Correct 321 ms 18564 KB Output is correct
79 Correct 232 ms 4168 KB Output is correct
80 Correct 175 ms 4248 KB Output is correct
81 Correct 283 ms 17872 KB Output is correct
82 Correct 164 ms 15100 KB Output is correct
83 Correct 322 ms 17960 KB Output is correct
84 Correct 310 ms 17992 KB Output is correct
85 Correct 260 ms 14672 KB Output is correct
86 Correct 336 ms 17748 KB Output is correct
87 Correct 185 ms 16724 KB Output is correct
88 Correct 241 ms 18260 KB Output is correct
89 Correct 106 ms 13544 KB Output is correct
90 Correct 223 ms 17880 KB Output is correct
91 Correct 215 ms 12668 KB Output is correct
92 Correct 173 ms 12700 KB Output is correct
93 Correct 301 ms 17844 KB Output is correct
94 Correct 255 ms 18016 KB Output is correct
95 Correct 234 ms 16588 KB Output is correct
96 Correct 261 ms 17856 KB Output is correct
97 Correct 276 ms 17748 KB Output is correct
98 Correct 201 ms 13392 KB Output is correct
99 Correct 287 ms 17096 KB Output is correct
100 Correct 226 ms 14896 KB Output is correct
101 Correct 307 ms 17492 KB Output is correct
102 Correct 203 ms 18972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 756 KB Output is correct
2 Correct 3 ms 856 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 3 ms 960 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 4 ms 932 KB Output is correct
23 Correct 4 ms 604 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 3 ms 952 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 3 ms 860 KB Output is correct
35 Correct 3 ms 860 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 2 ms 700 KB Output is correct
38 Correct 3 ms 860 KB Output is correct
39 Correct 80 ms 16868 KB Output is correct
40 Correct 83 ms 17476 KB Output is correct
41 Correct 95 ms 16980 KB Output is correct
42 Correct 98 ms 16864 KB Output is correct
43 Correct 86 ms 17588 KB Output is correct
44 Correct 92 ms 17572 KB Output is correct
45 Correct 122 ms 3444 KB Output is correct
46 Correct 137 ms 3156 KB Output is correct
47 Correct 92 ms 17108 KB Output is correct
48 Correct 87 ms 17232 KB Output is correct
49 Correct 93 ms 17236 KB Output is correct
50 Correct 85 ms 17168 KB Output is correct
51 Correct 126 ms 13092 KB Output is correct
52 Correct 156 ms 17744 KB Output is correct
53 Correct 110 ms 14484 KB Output is correct
54 Correct 137 ms 18628 KB Output is correct
55 Execution timed out 1039 ms 60784 KB Time limit exceeded
56 Halted 0 ms 0 KB -