답안 #439017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439017 2021-06-29T04:47:35 Z kig9981 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 70016 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,int>> U[250001];
vector<tuple<int,int,long long>> L[2*SZ], qry;
long long C[2*SZ];
int V[250000];

void add(int s, int e, int c)
{
	for(s+=SZ,e+=SZ;s<=e;s>>=1,e>>=1) {
		if(s&1) C[s++]+=c;
		if(~e&1) C[e--]+=c;
	}
}

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]);
}

void update(int n, int c, int k)
{
	V[n]=c;
	for(C[n+=SZ]+=k;n>>=1;) C[n]=C[2*n]+C[2*n+1];
}

int query(long long k)
{
	int bit=1, s=0, e=SZ-1;
	while(s<e) {
		int m=(s+e)>>1;
		if(C[2*bit]<k) {
			k-=C[2*bit];
			s=m+1;
			bit=2*bit+1;
		}
		else {
			e=m;
			bit=2*bit;
		}
	}
	return V[s];
}

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, j=0;
	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;
			add_tree(a,--b,d);
			add(a,b,d);
			U[a].emplace_back(i,c,d);
			U[b+1].emplace_back(i,c,-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) {
				qry.emplace_back(i,a,-1);
				continue;
			}
			for(tot=C[n=SZ+a];n>>=1;) tot+=C[n];
			qry.emplace_back(i,a,b+=tot-tree[SZ+a].m);
		}
	}
	sort(qry.begin(),qry.end(),[](const auto &a, const auto &b) {return get<1>(a)<get<1>(b);});
	memset(C,0,sizeof(C));
	for(auto &[t,p,v]: qry) {
		for(;j<=p;j++) for(auto[i,c,k]: U[j]) update(i,c,k);
		if(v==-1) {
			v=0;
			continue;
		}
		v=query(v);
	}
	sort(qry.begin(),qry.end());
	for(auto &[t,p,v]: qry) cout<<v<<'\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 55364 KB Output is correct
2 Correct 52 ms 55364 KB Output is correct
3 Correct 53 ms 55424 KB Output is correct
4 Correct 50 ms 55412 KB Output is correct
5 Correct 62 ms 55480 KB Output is correct
6 Correct 68 ms 55468 KB Output is correct
7 Correct 56 ms 55360 KB Output is correct
8 Correct 52 ms 55376 KB Output is correct
9 Correct 55 ms 55496 KB Output is correct
10 Correct 51 ms 55484 KB Output is correct
11 Correct 52 ms 55476 KB Output is correct
12 Correct 55 ms 55452 KB Output is correct
13 Correct 57 ms 55424 KB Output is correct
14 Correct 57 ms 55492 KB Output is correct
15 Correct 50 ms 55432 KB Output is correct
16 Correct 51 ms 55396 KB Output is correct
17 Correct 64 ms 55364 KB Output is correct
18 Correct 64 ms 55380 KB Output is correct
19 Correct 53 ms 55504 KB Output is correct
20 Correct 55 ms 55480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 55364 KB Output is correct
2 Correct 52 ms 55364 KB Output is correct
3 Correct 53 ms 55424 KB Output is correct
4 Correct 50 ms 55412 KB Output is correct
5 Correct 62 ms 55480 KB Output is correct
6 Correct 68 ms 55468 KB Output is correct
7 Correct 56 ms 55360 KB Output is correct
8 Correct 52 ms 55376 KB Output is correct
9 Correct 55 ms 55496 KB Output is correct
10 Correct 51 ms 55484 KB Output is correct
11 Correct 52 ms 55476 KB Output is correct
12 Correct 55 ms 55452 KB Output is correct
13 Correct 57 ms 55424 KB Output is correct
14 Correct 57 ms 55492 KB Output is correct
15 Correct 50 ms 55432 KB Output is correct
16 Correct 51 ms 55396 KB Output is correct
17 Correct 64 ms 55364 KB Output is correct
18 Correct 64 ms 55380 KB Output is correct
19 Correct 53 ms 55504 KB Output is correct
20 Correct 55 ms 55480 KB Output is correct
21 Correct 53 ms 55416 KB Output is correct
22 Correct 56 ms 55364 KB Output is correct
23 Correct 67 ms 55468 KB Output is correct
24 Correct 66 ms 55452 KB Output is correct
25 Correct 59 ms 55400 KB Output is correct
26 Correct 59 ms 55456 KB Output is correct
27 Correct 52 ms 55488 KB Output is correct
28 Correct 54 ms 55616 KB Output is correct
29 Correct 53 ms 55484 KB Output is correct
30 Correct 61 ms 55364 KB Output is correct
31 Correct 56 ms 55352 KB Output is correct
32 Correct 57 ms 55364 KB Output is correct
33 Correct 60 ms 55492 KB Output is correct
34 Correct 56 ms 55496 KB Output is correct
35 Correct 52 ms 55364 KB Output is correct
36 Correct 53 ms 55400 KB Output is correct
37 Correct 52 ms 55480 KB Output is correct
38 Correct 55 ms 55492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 57000 KB Output is correct
2 Correct 233 ms 57412 KB Output is correct
3 Correct 237 ms 57036 KB Output is correct
4 Correct 226 ms 57016 KB Output is correct
5 Correct 214 ms 57320 KB Output is correct
6 Correct 230 ms 57340 KB Output is correct
7 Correct 133 ms 56800 KB Output is correct
8 Correct 138 ms 56696 KB Output is correct
9 Correct 209 ms 56972 KB Output is correct
10 Correct 230 ms 57088 KB Output is correct
11 Correct 279 ms 57084 KB Output is correct
12 Correct 226 ms 57160 KB Output is correct
13 Correct 182 ms 57312 KB Output is correct
14 Correct 204 ms 57476 KB Output is correct
15 Correct 214 ms 58088 KB Output is correct
16 Correct 273 ms 58052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 864 ms 61848 KB Output is correct
2 Correct 694 ms 64404 KB Output is correct
3 Correct 848 ms 67764 KB Output is correct
4 Correct 635 ms 65640 KB Output is correct
5 Correct 661 ms 65544 KB Output is correct
6 Correct 947 ms 69256 KB Output is correct
7 Correct 289 ms 64104 KB Output is correct
8 Correct 294 ms 63980 KB Output is correct
9 Correct 798 ms 70008 KB Output is correct
10 Correct 839 ms 70016 KB Output is correct
11 Correct 898 ms 67628 KB Output is correct
12 Correct 910 ms 67988 KB Output is correct
13 Correct 834 ms 67404 KB Output is correct
14 Correct 947 ms 67968 KB Output is correct
15 Execution timed out 1008 ms 67948 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 55364 KB Output is correct
2 Correct 52 ms 55364 KB Output is correct
3 Correct 53 ms 55424 KB Output is correct
4 Correct 50 ms 55412 KB Output is correct
5 Correct 62 ms 55480 KB Output is correct
6 Correct 68 ms 55468 KB Output is correct
7 Correct 56 ms 55360 KB Output is correct
8 Correct 52 ms 55376 KB Output is correct
9 Correct 55 ms 55496 KB Output is correct
10 Correct 51 ms 55484 KB Output is correct
11 Correct 52 ms 55476 KB Output is correct
12 Correct 55 ms 55452 KB Output is correct
13 Correct 57 ms 55424 KB Output is correct
14 Correct 57 ms 55492 KB Output is correct
15 Correct 50 ms 55432 KB Output is correct
16 Correct 51 ms 55396 KB Output is correct
17 Correct 64 ms 55364 KB Output is correct
18 Correct 64 ms 55380 KB Output is correct
19 Correct 53 ms 55504 KB Output is correct
20 Correct 55 ms 55480 KB Output is correct
21 Correct 219 ms 57000 KB Output is correct
22 Correct 233 ms 57412 KB Output is correct
23 Correct 237 ms 57036 KB Output is correct
24 Correct 226 ms 57016 KB Output is correct
25 Correct 214 ms 57320 KB Output is correct
26 Correct 230 ms 57340 KB Output is correct
27 Correct 133 ms 56800 KB Output is correct
28 Correct 138 ms 56696 KB Output is correct
29 Correct 209 ms 56972 KB Output is correct
30 Correct 230 ms 57088 KB Output is correct
31 Correct 279 ms 57084 KB Output is correct
32 Correct 226 ms 57160 KB Output is correct
33 Correct 182 ms 57312 KB Output is correct
34 Correct 204 ms 57476 KB Output is correct
35 Correct 214 ms 58088 KB Output is correct
36 Correct 273 ms 58052 KB Output is correct
37 Correct 193 ms 56988 KB Output is correct
38 Correct 178 ms 57048 KB Output is correct
39 Correct 105 ms 56440 KB Output is correct
40 Correct 113 ms 56600 KB Output is correct
41 Correct 248 ms 56992 KB Output is correct
42 Correct 204 ms 57152 KB Output is correct
43 Correct 228 ms 57164 KB Output is correct
44 Correct 229 ms 57104 KB Output is correct
45 Correct 204 ms 57088 KB Output is correct
46 Correct 218 ms 57152 KB Output is correct
47 Correct 161 ms 56756 KB Output is correct
48 Correct 173 ms 57024 KB Output is correct
49 Correct 178 ms 56660 KB Output is correct
50 Correct 261 ms 56924 KB Output is correct
51 Correct 274 ms 57200 KB Output is correct
52 Correct 301 ms 57208 KB Output is correct
53 Correct 195 ms 57532 KB Output is correct
54 Correct 213 ms 58056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 57460 KB Output is correct
2 Correct 215 ms 57660 KB Output is correct
3 Correct 209 ms 57800 KB Output is correct
4 Correct 190 ms 57128 KB Output is correct
5 Correct 162 ms 57404 KB Output is correct
6 Correct 205 ms 57764 KB Output is correct
7 Correct 107 ms 57204 KB Output is correct
8 Correct 116 ms 57220 KB Output is correct
9 Correct 129 ms 57208 KB Output is correct
10 Correct 132 ms 56944 KB Output is correct
11 Correct 168 ms 57400 KB Output is correct
12 Correct 183 ms 57496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 55364 KB Output is correct
2 Correct 52 ms 55364 KB Output is correct
3 Correct 53 ms 55424 KB Output is correct
4 Correct 50 ms 55412 KB Output is correct
5 Correct 62 ms 55480 KB Output is correct
6 Correct 68 ms 55468 KB Output is correct
7 Correct 56 ms 55360 KB Output is correct
8 Correct 52 ms 55376 KB Output is correct
9 Correct 55 ms 55496 KB Output is correct
10 Correct 51 ms 55484 KB Output is correct
11 Correct 52 ms 55476 KB Output is correct
12 Correct 55 ms 55452 KB Output is correct
13 Correct 57 ms 55424 KB Output is correct
14 Correct 57 ms 55492 KB Output is correct
15 Correct 50 ms 55432 KB Output is correct
16 Correct 51 ms 55396 KB Output is correct
17 Correct 64 ms 55364 KB Output is correct
18 Correct 64 ms 55380 KB Output is correct
19 Correct 53 ms 55504 KB Output is correct
20 Correct 55 ms 55480 KB Output is correct
21 Correct 53 ms 55416 KB Output is correct
22 Correct 56 ms 55364 KB Output is correct
23 Correct 67 ms 55468 KB Output is correct
24 Correct 66 ms 55452 KB Output is correct
25 Correct 59 ms 55400 KB Output is correct
26 Correct 59 ms 55456 KB Output is correct
27 Correct 52 ms 55488 KB Output is correct
28 Correct 54 ms 55616 KB Output is correct
29 Correct 53 ms 55484 KB Output is correct
30 Correct 61 ms 55364 KB Output is correct
31 Correct 56 ms 55352 KB Output is correct
32 Correct 57 ms 55364 KB Output is correct
33 Correct 60 ms 55492 KB Output is correct
34 Correct 56 ms 55496 KB Output is correct
35 Correct 52 ms 55364 KB Output is correct
36 Correct 53 ms 55400 KB Output is correct
37 Correct 52 ms 55480 KB Output is correct
38 Correct 55 ms 55492 KB Output is correct
39 Correct 219 ms 57000 KB Output is correct
40 Correct 233 ms 57412 KB Output is correct
41 Correct 237 ms 57036 KB Output is correct
42 Correct 226 ms 57016 KB Output is correct
43 Correct 214 ms 57320 KB Output is correct
44 Correct 230 ms 57340 KB Output is correct
45 Correct 133 ms 56800 KB Output is correct
46 Correct 138 ms 56696 KB Output is correct
47 Correct 209 ms 56972 KB Output is correct
48 Correct 230 ms 57088 KB Output is correct
49 Correct 279 ms 57084 KB Output is correct
50 Correct 226 ms 57160 KB Output is correct
51 Correct 182 ms 57312 KB Output is correct
52 Correct 204 ms 57476 KB Output is correct
53 Correct 214 ms 58088 KB Output is correct
54 Correct 273 ms 58052 KB Output is correct
55 Correct 193 ms 56988 KB Output is correct
56 Correct 178 ms 57048 KB Output is correct
57 Correct 105 ms 56440 KB Output is correct
58 Correct 113 ms 56600 KB Output is correct
59 Correct 248 ms 56992 KB Output is correct
60 Correct 204 ms 57152 KB Output is correct
61 Correct 228 ms 57164 KB Output is correct
62 Correct 229 ms 57104 KB Output is correct
63 Correct 204 ms 57088 KB Output is correct
64 Correct 218 ms 57152 KB Output is correct
65 Correct 161 ms 56756 KB Output is correct
66 Correct 173 ms 57024 KB Output is correct
67 Correct 178 ms 56660 KB Output is correct
68 Correct 261 ms 56924 KB Output is correct
69 Correct 274 ms 57200 KB Output is correct
70 Correct 301 ms 57208 KB Output is correct
71 Correct 195 ms 57532 KB Output is correct
72 Correct 213 ms 58056 KB Output is correct
73 Correct 217 ms 57460 KB Output is correct
74 Correct 215 ms 57660 KB Output is correct
75 Correct 209 ms 57800 KB Output is correct
76 Correct 190 ms 57128 KB Output is correct
77 Correct 162 ms 57404 KB Output is correct
78 Correct 205 ms 57764 KB Output is correct
79 Correct 107 ms 57204 KB Output is correct
80 Correct 116 ms 57220 KB Output is correct
81 Correct 129 ms 57208 KB Output is correct
82 Correct 132 ms 56944 KB Output is correct
83 Correct 168 ms 57400 KB Output is correct
84 Correct 183 ms 57496 KB Output is correct
85 Correct 209 ms 57108 KB Output is correct
86 Correct 211 ms 57132 KB Output is correct
87 Correct 218 ms 57192 KB Output is correct
88 Correct 214 ms 57476 KB Output is correct
89 Correct 154 ms 56484 KB Output is correct
90 Correct 222 ms 57116 KB Output is correct
91 Correct 187 ms 56820 KB Output is correct
92 Correct 188 ms 56720 KB Output is correct
93 Correct 280 ms 57084 KB Output is correct
94 Correct 228 ms 57100 KB Output is correct
95 Correct 221 ms 56996 KB Output is correct
96 Correct 216 ms 57116 KB Output is correct
97 Correct 240 ms 57140 KB Output is correct
98 Correct 233 ms 56824 KB Output is correct
99 Correct 120 ms 56784 KB Output is correct
100 Correct 166 ms 56684 KB Output is correct
101 Correct 191 ms 57016 KB Output is correct
102 Correct 213 ms 57428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 55364 KB Output is correct
2 Correct 52 ms 55364 KB Output is correct
3 Correct 53 ms 55424 KB Output is correct
4 Correct 50 ms 55412 KB Output is correct
5 Correct 62 ms 55480 KB Output is correct
6 Correct 68 ms 55468 KB Output is correct
7 Correct 56 ms 55360 KB Output is correct
8 Correct 52 ms 55376 KB Output is correct
9 Correct 55 ms 55496 KB Output is correct
10 Correct 51 ms 55484 KB Output is correct
11 Correct 52 ms 55476 KB Output is correct
12 Correct 55 ms 55452 KB Output is correct
13 Correct 57 ms 55424 KB Output is correct
14 Correct 57 ms 55492 KB Output is correct
15 Correct 50 ms 55432 KB Output is correct
16 Correct 51 ms 55396 KB Output is correct
17 Correct 64 ms 55364 KB Output is correct
18 Correct 64 ms 55380 KB Output is correct
19 Correct 53 ms 55504 KB Output is correct
20 Correct 55 ms 55480 KB Output is correct
21 Correct 53 ms 55416 KB Output is correct
22 Correct 56 ms 55364 KB Output is correct
23 Correct 67 ms 55468 KB Output is correct
24 Correct 66 ms 55452 KB Output is correct
25 Correct 59 ms 55400 KB Output is correct
26 Correct 59 ms 55456 KB Output is correct
27 Correct 52 ms 55488 KB Output is correct
28 Correct 54 ms 55616 KB Output is correct
29 Correct 53 ms 55484 KB Output is correct
30 Correct 61 ms 55364 KB Output is correct
31 Correct 56 ms 55352 KB Output is correct
32 Correct 57 ms 55364 KB Output is correct
33 Correct 60 ms 55492 KB Output is correct
34 Correct 56 ms 55496 KB Output is correct
35 Correct 52 ms 55364 KB Output is correct
36 Correct 53 ms 55400 KB Output is correct
37 Correct 52 ms 55480 KB Output is correct
38 Correct 55 ms 55492 KB Output is correct
39 Correct 219 ms 57000 KB Output is correct
40 Correct 233 ms 57412 KB Output is correct
41 Correct 237 ms 57036 KB Output is correct
42 Correct 226 ms 57016 KB Output is correct
43 Correct 214 ms 57320 KB Output is correct
44 Correct 230 ms 57340 KB Output is correct
45 Correct 133 ms 56800 KB Output is correct
46 Correct 138 ms 56696 KB Output is correct
47 Correct 209 ms 56972 KB Output is correct
48 Correct 230 ms 57088 KB Output is correct
49 Correct 279 ms 57084 KB Output is correct
50 Correct 226 ms 57160 KB Output is correct
51 Correct 182 ms 57312 KB Output is correct
52 Correct 204 ms 57476 KB Output is correct
53 Correct 214 ms 58088 KB Output is correct
54 Correct 273 ms 58052 KB Output is correct
55 Correct 864 ms 61848 KB Output is correct
56 Correct 694 ms 64404 KB Output is correct
57 Correct 848 ms 67764 KB Output is correct
58 Correct 635 ms 65640 KB Output is correct
59 Correct 661 ms 65544 KB Output is correct
60 Correct 947 ms 69256 KB Output is correct
61 Correct 289 ms 64104 KB Output is correct
62 Correct 294 ms 63980 KB Output is correct
63 Correct 798 ms 70008 KB Output is correct
64 Correct 839 ms 70016 KB Output is correct
65 Correct 898 ms 67628 KB Output is correct
66 Correct 910 ms 67988 KB Output is correct
67 Correct 834 ms 67404 KB Output is correct
68 Correct 947 ms 67968 KB Output is correct
69 Execution timed out 1008 ms 67948 KB Time limit exceeded
70 Halted 0 ms 0 KB -