답안 #439010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439010 2021-06-29T04:14:53 Z kig9981 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 65076 KB
#include <bits/stdc++.h>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

struct Seg
{
	long long m, sm, lz, slz;
	Seg() : m(0), sm(0x7fffffffffffffffLL), lz(0), slz(-0x7fffffffffffffffLL) {}
	Seg &operator =(const Seg &a) {
		m=a.m;
		sm=a.sm;
		return *this;
	}
};

const int SZ=1<<18;
const long long MAX=0x7fffffffffffffffLL;
Seg tree[2*SZ];
vector<tuple<int,int,long long>> L[2*SZ];

void update(int s, int e, int q, int c, int k)
{
	for(s+=SZ,e+=SZ;s<=e;s>>=1,e>>=1) {
		if(s&1) {
			L[s].emplace_back(q,c,get<2>(L[s].back())+k);
			s++;
		}
		if(~e&1) {
			L[e].emplace_back(q,c,get<2>(L[e].back())+k);
			e--;
		}
	}
}

Seg combine(const Seg &a, const Seg &b)
{
	Seg c;
	c.m=min(a.m,b.m);
	if(c.m<max(a.m,b.m)) c.sm=max(a.m,b.m);
	if(c.m<a.sm) c.sm=min(c.sm,a.sm);
	if(c.m<b.sm) c.sm=min(c.sm,b.sm);
	return c;
}

void lazy_propagation(int bit, int s, int e)
{
	if(tree[bit].slz!=-MAX) {
		if(s<e) {
			if(max(tree[2*bit].slz,tree[2*bit].m)+tree[2*bit].lz==tree[bit].m) tree[2*bit].slz=tree[bit].slz-tree[2*bit].lz;
			if(max(tree[2*bit+1].slz,tree[2*bit+1].m)+tree[2*bit+1].lz==tree[bit].m) tree[2*bit+1].slz=tree[bit].slz-tree[2*bit+1].lz;
		}
		tree[bit].m=tree[bit].slz;
		tree[bit].slz=-MAX;
	}
	tree[bit].m+=tree[bit].lz;
	if(tree[bit].sm<MAX) tree[bit].sm+=tree[bit].lz;
	if(s<e) {
		tree[2*bit].lz+=tree[bit].lz;
		tree[2*bit+1].lz+=tree[bit].lz;
	}
	tree[bit].lz=0;
}

void add_tree(int n1, int n2, int v, int bit=1, int s=0, int e=SZ-1)
{
	int m=(s+e)>>1;
	lazy_propagation(bit,s,e);
	if(n2<n1 || n2<s || e<n1) return;
	if(n1<=s && e<=n2) {
		tree[bit].lz=v;
		lazy_propagation(bit,s,e);
		return;
	}
	add_tree(n1,n2,v,2*bit,s,m);
	add_tree(n1,n2,v,2*bit+1,m+1,e);
	tree[bit]=combine(tree[2*bit],tree[2*bit+1]);
}

void set_tree(int n1, int n2, int bit=1, int s=0, int e=SZ-1)
{
	int m=(s+e)>>1;
	lazy_propagation(bit,s,e);
	if(n2<n1 || n2<s || e<n1 || tree[bit].m>=0) return;
	if(n1<=s && e<=n2 && tree[bit].sm>0) {
		tree[bit].slz=0;
		lazy_propagation(bit,s,e);
		return;
	}
	set_tree(n1,n2,2*bit,s,m);
	set_tree(n1,n2,2*bit+1,m+1,e);
	tree[bit]=combine(tree[2*bit],tree[2*bit+1]);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N, M, Q;
	cin>>N>>M>>Q;
	for(int i=2*SZ;--i;) L[i].emplace_back(0,0,0);
	for(int i=1;i<=Q;i++) {
		int t, a, c, d;
		long long b;
		cin>>t>>a>>b; --a;
		if(t==1) {
			cin>>c>>d;
			update(a,--b,i,c,d);
			add_tree(a,b,d);
		}
		else if(t==2) {
			cin>>c;
			add_tree(a,--b,-c);
			set_tree(a,b);
		}
		else {
			long long tot;
			int n=1, s=0, e=SZ-1;
			while(s<e) {
				int m=(s+e)>>1;
				lazy_propagation(n,s,e);
				if(a<=m) tie(n,e)=make_pair(2*n,m);
				else tie(n,s)=make_pair(2*n+1,m+1);
			}
			lazy_propagation(n,s,e);
			if(tree[n].m<b) {
				cout<<"0\n";
				continue;
			}
			for(tot=get<2>(L[n=SZ+a].back());n>>=1;) tot+=get<2>(L[n].back());
			b+=tot-tree[SZ+a].m;
			s=1; e=i-1;
			while(s<=e) {
				int m=(s+e)>>1; tot=0; n=SZ+a;
				for(;;) {
					tot+=get<2>(*--upper_bound(L[n].begin(),L[n].end(),make_tuple(m,0,0)));
					if(!(n>>=1)) break;
				}
				if(tot<b) s=m+1;
				else e=m-1;
			}
			n=SZ+a; e=tot=0;
			for(;;) {
				auto v=*--upper_bound(L[n].begin(),L[n].end(),make_tuple(s,0,0));
				if(get<0>(v)>tot) {
					tot=get<0>(v);
					e=get<1>(v);
				}
				if(!(n>>=1)) break;
			}
			cout<<e<<'\n';
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 45468 KB Output is correct
2 Correct 55 ms 45628 KB Output is correct
3 Correct 60 ms 45572 KB Output is correct
4 Correct 51 ms 45648 KB Output is correct
5 Correct 50 ms 45424 KB Output is correct
6 Correct 52 ms 45444 KB Output is correct
7 Correct 58 ms 45560 KB Output is correct
8 Correct 53 ms 45604 KB Output is correct
9 Correct 55 ms 45568 KB Output is correct
10 Correct 62 ms 45576 KB Output is correct
11 Correct 53 ms 45568 KB Output is correct
12 Correct 54 ms 45636 KB Output is correct
13 Correct 58 ms 45488 KB Output is correct
14 Correct 63 ms 45540 KB Output is correct
15 Correct 59 ms 45584 KB Output is correct
16 Correct 75 ms 45628 KB Output is correct
17 Correct 61 ms 45568 KB Output is correct
18 Correct 68 ms 45676 KB Output is correct
19 Correct 64 ms 45520 KB Output is correct
20 Correct 55 ms 45508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 45468 KB Output is correct
2 Correct 55 ms 45628 KB Output is correct
3 Correct 60 ms 45572 KB Output is correct
4 Correct 51 ms 45648 KB Output is correct
5 Correct 50 ms 45424 KB Output is correct
6 Correct 52 ms 45444 KB Output is correct
7 Correct 58 ms 45560 KB Output is correct
8 Correct 53 ms 45604 KB Output is correct
9 Correct 55 ms 45568 KB Output is correct
10 Correct 62 ms 45576 KB Output is correct
11 Correct 53 ms 45568 KB Output is correct
12 Correct 54 ms 45636 KB Output is correct
13 Correct 58 ms 45488 KB Output is correct
14 Correct 63 ms 45540 KB Output is correct
15 Correct 59 ms 45584 KB Output is correct
16 Correct 75 ms 45628 KB Output is correct
17 Correct 61 ms 45568 KB Output is correct
18 Correct 68 ms 45676 KB Output is correct
19 Correct 64 ms 45520 KB Output is correct
20 Correct 55 ms 45508 KB Output is correct
21 Correct 53 ms 45608 KB Output is correct
22 Correct 54 ms 45536 KB Output is correct
23 Correct 56 ms 45636 KB Output is correct
24 Correct 57 ms 45636 KB Output is correct
25 Correct 55 ms 45432 KB Output is correct
26 Correct 56 ms 45380 KB Output is correct
27 Correct 54 ms 45604 KB Output is correct
28 Correct 65 ms 45684 KB Output is correct
29 Correct 52 ms 45636 KB Output is correct
30 Correct 50 ms 45600 KB Output is correct
31 Correct 50 ms 45672 KB Output is correct
32 Correct 52 ms 45588 KB Output is correct
33 Correct 60 ms 45636 KB Output is correct
34 Correct 61 ms 45512 KB Output is correct
35 Correct 58 ms 45684 KB Output is correct
36 Correct 58 ms 45636 KB Output is correct
37 Correct 49 ms 45456 KB Output is correct
38 Correct 50 ms 45496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 254 ms 47172 KB Output is correct
2 Correct 271 ms 49064 KB Output is correct
3 Correct 234 ms 48836 KB Output is correct
4 Correct 256 ms 48856 KB Output is correct
5 Correct 308 ms 49912 KB Output is correct
6 Correct 280 ms 49848 KB Output is correct
7 Correct 150 ms 46792 KB Output is correct
8 Correct 135 ms 46912 KB Output is correct
9 Correct 247 ms 48616 KB Output is correct
10 Correct 239 ms 48656 KB Output is correct
11 Correct 248 ms 48732 KB Output is correct
12 Correct 254 ms 48656 KB Output is correct
13 Correct 207 ms 48840 KB Output is correct
14 Correct 242 ms 49536 KB Output is correct
15 Correct 228 ms 50468 KB Output is correct
16 Correct 297 ms 50680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1083 ms 65076 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 45468 KB Output is correct
2 Correct 55 ms 45628 KB Output is correct
3 Correct 60 ms 45572 KB Output is correct
4 Correct 51 ms 45648 KB Output is correct
5 Correct 50 ms 45424 KB Output is correct
6 Correct 52 ms 45444 KB Output is correct
7 Correct 58 ms 45560 KB Output is correct
8 Correct 53 ms 45604 KB Output is correct
9 Correct 55 ms 45568 KB Output is correct
10 Correct 62 ms 45576 KB Output is correct
11 Correct 53 ms 45568 KB Output is correct
12 Correct 54 ms 45636 KB Output is correct
13 Correct 58 ms 45488 KB Output is correct
14 Correct 63 ms 45540 KB Output is correct
15 Correct 59 ms 45584 KB Output is correct
16 Correct 75 ms 45628 KB Output is correct
17 Correct 61 ms 45568 KB Output is correct
18 Correct 68 ms 45676 KB Output is correct
19 Correct 64 ms 45520 KB Output is correct
20 Correct 55 ms 45508 KB Output is correct
21 Correct 254 ms 47172 KB Output is correct
22 Correct 271 ms 49064 KB Output is correct
23 Correct 234 ms 48836 KB Output is correct
24 Correct 256 ms 48856 KB Output is correct
25 Correct 308 ms 49912 KB Output is correct
26 Correct 280 ms 49848 KB Output is correct
27 Correct 150 ms 46792 KB Output is correct
28 Correct 135 ms 46912 KB Output is correct
29 Correct 247 ms 48616 KB Output is correct
30 Correct 239 ms 48656 KB Output is correct
31 Correct 248 ms 48732 KB Output is correct
32 Correct 254 ms 48656 KB Output is correct
33 Correct 207 ms 48840 KB Output is correct
34 Correct 242 ms 49536 KB Output is correct
35 Correct 228 ms 50468 KB Output is correct
36 Correct 297 ms 50680 KB Output is correct
37 Correct 376 ms 52832 KB Output is correct
38 Correct 305 ms 55204 KB Output is correct
39 Correct 116 ms 46644 KB Output is correct
40 Correct 143 ms 46796 KB Output is correct
41 Correct 389 ms 55264 KB Output is correct
42 Correct 385 ms 55196 KB Output is correct
43 Correct 358 ms 55224 KB Output is correct
44 Correct 403 ms 55004 KB Output is correct
45 Correct 377 ms 55024 KB Output is correct
46 Correct 385 ms 55104 KB Output is correct
47 Correct 160 ms 50580 KB Output is correct
48 Correct 232 ms 54960 KB Output is correct
49 Correct 292 ms 52220 KB Output is correct
50 Correct 334 ms 53876 KB Output is correct
51 Correct 400 ms 55276 KB Output is correct
52 Correct 402 ms 55296 KB Output is correct
53 Correct 230 ms 49636 KB Output is correct
54 Correct 264 ms 50712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 416 ms 54760 KB Output is correct
2 Correct 490 ms 55676 KB Output is correct
3 Correct 460 ms 56000 KB Output is correct
4 Correct 346 ms 53476 KB Output is correct
5 Correct 420 ms 55196 KB Output is correct
6 Correct 465 ms 56660 KB Output is correct
7 Correct 165 ms 46136 KB Output is correct
8 Correct 163 ms 46168 KB Output is correct
9 Correct 196 ms 51580 KB Output is correct
10 Correct 225 ms 54408 KB Output is correct
11 Correct 302 ms 57088 KB Output is correct
12 Correct 272 ms 57044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 45468 KB Output is correct
2 Correct 55 ms 45628 KB Output is correct
3 Correct 60 ms 45572 KB Output is correct
4 Correct 51 ms 45648 KB Output is correct
5 Correct 50 ms 45424 KB Output is correct
6 Correct 52 ms 45444 KB Output is correct
7 Correct 58 ms 45560 KB Output is correct
8 Correct 53 ms 45604 KB Output is correct
9 Correct 55 ms 45568 KB Output is correct
10 Correct 62 ms 45576 KB Output is correct
11 Correct 53 ms 45568 KB Output is correct
12 Correct 54 ms 45636 KB Output is correct
13 Correct 58 ms 45488 KB Output is correct
14 Correct 63 ms 45540 KB Output is correct
15 Correct 59 ms 45584 KB Output is correct
16 Correct 75 ms 45628 KB Output is correct
17 Correct 61 ms 45568 KB Output is correct
18 Correct 68 ms 45676 KB Output is correct
19 Correct 64 ms 45520 KB Output is correct
20 Correct 55 ms 45508 KB Output is correct
21 Correct 53 ms 45608 KB Output is correct
22 Correct 54 ms 45536 KB Output is correct
23 Correct 56 ms 45636 KB Output is correct
24 Correct 57 ms 45636 KB Output is correct
25 Correct 55 ms 45432 KB Output is correct
26 Correct 56 ms 45380 KB Output is correct
27 Correct 54 ms 45604 KB Output is correct
28 Correct 65 ms 45684 KB Output is correct
29 Correct 52 ms 45636 KB Output is correct
30 Correct 50 ms 45600 KB Output is correct
31 Correct 50 ms 45672 KB Output is correct
32 Correct 52 ms 45588 KB Output is correct
33 Correct 60 ms 45636 KB Output is correct
34 Correct 61 ms 45512 KB Output is correct
35 Correct 58 ms 45684 KB Output is correct
36 Correct 58 ms 45636 KB Output is correct
37 Correct 49 ms 45456 KB Output is correct
38 Correct 50 ms 45496 KB Output is correct
39 Correct 254 ms 47172 KB Output is correct
40 Correct 271 ms 49064 KB Output is correct
41 Correct 234 ms 48836 KB Output is correct
42 Correct 256 ms 48856 KB Output is correct
43 Correct 308 ms 49912 KB Output is correct
44 Correct 280 ms 49848 KB Output is correct
45 Correct 150 ms 46792 KB Output is correct
46 Correct 135 ms 46912 KB Output is correct
47 Correct 247 ms 48616 KB Output is correct
48 Correct 239 ms 48656 KB Output is correct
49 Correct 248 ms 48732 KB Output is correct
50 Correct 254 ms 48656 KB Output is correct
51 Correct 207 ms 48840 KB Output is correct
52 Correct 242 ms 49536 KB Output is correct
53 Correct 228 ms 50468 KB Output is correct
54 Correct 297 ms 50680 KB Output is correct
55 Correct 376 ms 52832 KB Output is correct
56 Correct 305 ms 55204 KB Output is correct
57 Correct 116 ms 46644 KB Output is correct
58 Correct 143 ms 46796 KB Output is correct
59 Correct 389 ms 55264 KB Output is correct
60 Correct 385 ms 55196 KB Output is correct
61 Correct 358 ms 55224 KB Output is correct
62 Correct 403 ms 55004 KB Output is correct
63 Correct 377 ms 55024 KB Output is correct
64 Correct 385 ms 55104 KB Output is correct
65 Correct 160 ms 50580 KB Output is correct
66 Correct 232 ms 54960 KB Output is correct
67 Correct 292 ms 52220 KB Output is correct
68 Correct 334 ms 53876 KB Output is correct
69 Correct 400 ms 55276 KB Output is correct
70 Correct 402 ms 55296 KB Output is correct
71 Correct 230 ms 49636 KB Output is correct
72 Correct 264 ms 50712 KB Output is correct
73 Correct 416 ms 54760 KB Output is correct
74 Correct 490 ms 55676 KB Output is correct
75 Correct 460 ms 56000 KB Output is correct
76 Correct 346 ms 53476 KB Output is correct
77 Correct 420 ms 55196 KB Output is correct
78 Correct 465 ms 56660 KB Output is correct
79 Correct 165 ms 46136 KB Output is correct
80 Correct 163 ms 46168 KB Output is correct
81 Correct 196 ms 51580 KB Output is correct
82 Correct 225 ms 54408 KB Output is correct
83 Correct 302 ms 57088 KB Output is correct
84 Correct 272 ms 57044 KB Output is correct
85 Correct 350 ms 53392 KB Output is correct
86 Correct 383 ms 54460 KB Output is correct
87 Correct 363 ms 56504 KB Output is correct
88 Correct 401 ms 58356 KB Output is correct
89 Correct 242 ms 52192 KB Output is correct
90 Correct 399 ms 55776 KB Output is correct
91 Correct 309 ms 53388 KB Output is correct
92 Correct 293 ms 53104 KB Output is correct
93 Correct 409 ms 55696 KB Output is correct
94 Correct 400 ms 55652 KB Output is correct
95 Correct 370 ms 55396 KB Output is correct
96 Correct 349 ms 55680 KB Output is correct
97 Correct 385 ms 55604 KB Output is correct
98 Correct 321 ms 53716 KB Output is correct
99 Correct 168 ms 51076 KB Output is correct
100 Correct 204 ms 52980 KB Output is correct
101 Correct 292 ms 55556 KB Output is correct
102 Correct 271 ms 52508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 45468 KB Output is correct
2 Correct 55 ms 45628 KB Output is correct
3 Correct 60 ms 45572 KB Output is correct
4 Correct 51 ms 45648 KB Output is correct
5 Correct 50 ms 45424 KB Output is correct
6 Correct 52 ms 45444 KB Output is correct
7 Correct 58 ms 45560 KB Output is correct
8 Correct 53 ms 45604 KB Output is correct
9 Correct 55 ms 45568 KB Output is correct
10 Correct 62 ms 45576 KB Output is correct
11 Correct 53 ms 45568 KB Output is correct
12 Correct 54 ms 45636 KB Output is correct
13 Correct 58 ms 45488 KB Output is correct
14 Correct 63 ms 45540 KB Output is correct
15 Correct 59 ms 45584 KB Output is correct
16 Correct 75 ms 45628 KB Output is correct
17 Correct 61 ms 45568 KB Output is correct
18 Correct 68 ms 45676 KB Output is correct
19 Correct 64 ms 45520 KB Output is correct
20 Correct 55 ms 45508 KB Output is correct
21 Correct 53 ms 45608 KB Output is correct
22 Correct 54 ms 45536 KB Output is correct
23 Correct 56 ms 45636 KB Output is correct
24 Correct 57 ms 45636 KB Output is correct
25 Correct 55 ms 45432 KB Output is correct
26 Correct 56 ms 45380 KB Output is correct
27 Correct 54 ms 45604 KB Output is correct
28 Correct 65 ms 45684 KB Output is correct
29 Correct 52 ms 45636 KB Output is correct
30 Correct 50 ms 45600 KB Output is correct
31 Correct 50 ms 45672 KB Output is correct
32 Correct 52 ms 45588 KB Output is correct
33 Correct 60 ms 45636 KB Output is correct
34 Correct 61 ms 45512 KB Output is correct
35 Correct 58 ms 45684 KB Output is correct
36 Correct 58 ms 45636 KB Output is correct
37 Correct 49 ms 45456 KB Output is correct
38 Correct 50 ms 45496 KB Output is correct
39 Correct 254 ms 47172 KB Output is correct
40 Correct 271 ms 49064 KB Output is correct
41 Correct 234 ms 48836 KB Output is correct
42 Correct 256 ms 48856 KB Output is correct
43 Correct 308 ms 49912 KB Output is correct
44 Correct 280 ms 49848 KB Output is correct
45 Correct 150 ms 46792 KB Output is correct
46 Correct 135 ms 46912 KB Output is correct
47 Correct 247 ms 48616 KB Output is correct
48 Correct 239 ms 48656 KB Output is correct
49 Correct 248 ms 48732 KB Output is correct
50 Correct 254 ms 48656 KB Output is correct
51 Correct 207 ms 48840 KB Output is correct
52 Correct 242 ms 49536 KB Output is correct
53 Correct 228 ms 50468 KB Output is correct
54 Correct 297 ms 50680 KB Output is correct
55 Execution timed out 1083 ms 65076 KB Time limit exceeded
56 Halted 0 ms 0 KB -