Submission #442312

# Submission time Handle Problem Language Result Execution time Memory
442312 2021-07-07T12:33:36 Z keta_tsimakuridze Food Court (JOI21_foodcourt) C++14
68 / 100
234 ms 47516 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int> 
using namespace std;
const int N=2e5+5,mod=1e9+7;
int t,tree[4*N],add[4*N],n,m,q,g[N],cnt[N],ans[N];
pii lazy[4*N];
vector<int> t1;
vector<pair<int,int> > st[N],en[N],x[N];
void update1(int u,int start,int end,int l,int r,int val) {
	if(l>end || r<start) return;
	if(start<=l && r<=end) {
		add[u] += val;
		return;
	}
	if(l==r) return;
	int mid = (l+r)/2;
	update1(2*u,start,end,l,mid,val);
	update1(2*u+1,start,end,mid+1,r,val);
}
int getans1(int u,int ind,int l,int r) {
	if(l>ind || r<ind) return 0;
	if(l==r) return add[u];
	int mid = (l+r)/2;
	return getans1(2*u,ind,l,mid) + getans1(2*u+1,ind,mid+1,r) + add[u];
}
void upd(pii &a,pii b){
	if(a.s >= b.f) {
		a.s = a.s - b.f + b.s;
	}
	else {
		a.f += b.f - a.s;
		a.s = b.s;
	}
}
void update(int u,int start,int end,int l,int r,int val) {
	if(lazy[u].f||lazy[u].s) {
		tree[u] = max(tree[u]-lazy[u].f,0ll) + lazy[u].s;
		if(l!=r){
			upd(lazy[2*u],lazy[u]);
			upd(lazy[2*u+1],lazy[u]);
		}
		lazy[u] = {0,0};
	}
	if(l>end || r<start) return;
	if(start<=l && r<=end) {
		if(val>0) lazy[u].s = val;
		else lazy[u].f = -val; 
		tree[u] = max(tree[u]-lazy[u].f,0ll) + lazy[u].s;
		if(l!=r){
			upd(lazy[2*u],lazy[u]);
			upd(lazy[2*u+1],lazy[u]);
		}
		lazy[u] = {0,0};
		return;		
	}
	int mid = (l+r)/2;
	update(2*u,start,end,l,mid,val);
	update(2*u+1,start,end,mid+1,r,val);
}
int getans(int u,int ind,int l,int r) {
	if(lazy[u].f||lazy[u].s) {
		tree[u] = max(tree[u]-lazy[u].f,0ll) + lazy[u].s;
		if(l!=r){
			upd(lazy[2*u],lazy[u]);
			upd(lazy[2*u+1],lazy[u]);
		}
		lazy[u] = {0,0};
	}
	if(l>ind || r<ind) return 0;
	if(l==r) return tree[u];
	int mid = (l+r)/2;
	return getans(2*u,ind,l,mid) + getans(2*u+1,ind,mid+1,r);
}
 main(){
 	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++){
		int t,l,r,c,k;
		cin>>t;
		
		if(t==1) {
			
			cin>>l>>r>>c>>k;
			g[i] = c;
			st[l].push_back({i,k});
			en[r].push_back({i,k});
			update(1,l,r,1,n,k);
			t1.push_back(i);
		}
		else if(t==2){
			cin>>l>>r>>k;
			update(1,l,r,1,n,-k);
		}
		else  {
			int a,c;
			cin>>a>>c;
			x[a].push_back({c,i});
			cnt[i] = getans(1,a,1,n);  
		}
	} 
	for(int i=1;i<=n;i++) {
		for(int j=0;j<st[i].size();j++) {
			update1(1,st[i][j].f,q,1,q,st[i][j].s); 
		}
		for(int j=0;j<x[i].size();j++) {
			int ind = x[i][j].s; 
			int c = getans1(1,ind,1,q);
			if(cnt[ind] < x[i][j].f) {
				ans[ind] = -1;
				continue;
			}
			else {
				int l = 0, r = (int)t1.size() - 1; 
				while(l<=r) {
					int mid = (l+r)/2; 
					if(c - getans1(1,t1[mid]-1,1,q) >= cnt[ind] - x[i][j].f+1) {
						ans[ind] = g[t1[mid]];  
						l = mid + 1;
					}
					else r = mid - 1;
				}
				
			}
		}
		for(int j=0;j<en[i].size();j++){
			update1(1,en[i][j].f,q,1,q,-en[i][j].s); 
		}
	}
	for(int i=1;i<=q;i++) {
		if(ans[i]) cout<<max(0ll,ans[i])<<" ";
	}
}

Compilation message

foodcourt.cpp:77:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   77 |  main(){
      |  ^~~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:105:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |   for(int j=0;j<st[i].size();j++) {
      |               ~^~~~~~~~~~~~~
foodcourt.cpp:108:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |   for(int j=0;j<x[i].size();j++) {
      |               ~^~~~~~~~~~~~
foodcourt.cpp:128:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |   for(int j=0;j<en[i].size();j++){
      |               ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14668 KB Output is correct
2 Correct 11 ms 14640 KB Output is correct
3 Correct 10 ms 14684 KB Output is correct
4 Correct 12 ms 14680 KB Output is correct
5 Correct 10 ms 14540 KB Output is correct
6 Correct 10 ms 14524 KB Output is correct
7 Correct 12 ms 14680 KB Output is correct
8 Correct 11 ms 14668 KB Output is correct
9 Correct 11 ms 14668 KB Output is correct
10 Correct 11 ms 14668 KB Output is correct
11 Correct 11 ms 14640 KB Output is correct
12 Correct 11 ms 14680 KB Output is correct
13 Correct 11 ms 14676 KB Output is correct
14 Correct 10 ms 14668 KB Output is correct
15 Correct 10 ms 14668 KB Output is correct
16 Correct 11 ms 14664 KB Output is correct
17 Correct 10 ms 14668 KB Output is correct
18 Correct 11 ms 14628 KB Output is correct
19 Correct 10 ms 14668 KB Output is correct
20 Correct 11 ms 14716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14668 KB Output is correct
2 Correct 11 ms 14640 KB Output is correct
3 Correct 10 ms 14684 KB Output is correct
4 Correct 12 ms 14680 KB Output is correct
5 Correct 10 ms 14540 KB Output is correct
6 Correct 10 ms 14524 KB Output is correct
7 Correct 12 ms 14680 KB Output is correct
8 Correct 11 ms 14668 KB Output is correct
9 Correct 11 ms 14668 KB Output is correct
10 Correct 11 ms 14668 KB Output is correct
11 Correct 11 ms 14640 KB Output is correct
12 Correct 11 ms 14680 KB Output is correct
13 Correct 11 ms 14676 KB Output is correct
14 Correct 10 ms 14668 KB Output is correct
15 Correct 10 ms 14668 KB Output is correct
16 Correct 11 ms 14664 KB Output is correct
17 Correct 10 ms 14668 KB Output is correct
18 Correct 11 ms 14628 KB Output is correct
19 Correct 10 ms 14668 KB Output is correct
20 Correct 11 ms 14716 KB Output is correct
21 Correct 14 ms 14676 KB Output is correct
22 Correct 11 ms 14700 KB Output is correct
23 Correct 11 ms 14680 KB Output is correct
24 Correct 11 ms 14668 KB Output is correct
25 Correct 10 ms 14540 KB Output is correct
26 Correct 9 ms 14532 KB Output is correct
27 Correct 12 ms 14668 KB Output is correct
28 Correct 13 ms 14684 KB Output is correct
29 Correct 12 ms 14668 KB Output is correct
30 Correct 12 ms 14796 KB Output is correct
31 Correct 12 ms 14680 KB Output is correct
32 Correct 12 ms 14668 KB Output is correct
33 Correct 10 ms 14716 KB Output is correct
34 Correct 11 ms 14700 KB Output is correct
35 Correct 11 ms 14668 KB Output is correct
36 Correct 12 ms 14644 KB Output is correct
37 Correct 10 ms 14684 KB Output is correct
38 Correct 12 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 23360 KB Output is correct
2 Correct 120 ms 23900 KB Output is correct
3 Correct 126 ms 23276 KB Output is correct
4 Correct 149 ms 23376 KB Output is correct
5 Correct 129 ms 23900 KB Output is correct
6 Correct 118 ms 24016 KB Output is correct
7 Correct 72 ms 18828 KB Output is correct
8 Correct 62 ms 18948 KB Output is correct
9 Correct 116 ms 22856 KB Output is correct
10 Correct 122 ms 23432 KB Output is correct
11 Correct 111 ms 23164 KB Output is correct
12 Correct 122 ms 23424 KB Output is correct
13 Correct 111 ms 23388 KB Output is correct
14 Correct 130 ms 24044 KB Output is correct
15 Correct 125 ms 24760 KB Output is correct
16 Correct 126 ms 24996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 52 ms 47516 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14668 KB Output is correct
2 Correct 11 ms 14640 KB Output is correct
3 Correct 10 ms 14684 KB Output is correct
4 Correct 12 ms 14680 KB Output is correct
5 Correct 10 ms 14540 KB Output is correct
6 Correct 10 ms 14524 KB Output is correct
7 Correct 12 ms 14680 KB Output is correct
8 Correct 11 ms 14668 KB Output is correct
9 Correct 11 ms 14668 KB Output is correct
10 Correct 11 ms 14668 KB Output is correct
11 Correct 11 ms 14640 KB Output is correct
12 Correct 11 ms 14680 KB Output is correct
13 Correct 11 ms 14676 KB Output is correct
14 Correct 10 ms 14668 KB Output is correct
15 Correct 10 ms 14668 KB Output is correct
16 Correct 11 ms 14664 KB Output is correct
17 Correct 10 ms 14668 KB Output is correct
18 Correct 11 ms 14628 KB Output is correct
19 Correct 10 ms 14668 KB Output is correct
20 Correct 11 ms 14716 KB Output is correct
21 Correct 113 ms 23360 KB Output is correct
22 Correct 120 ms 23900 KB Output is correct
23 Correct 126 ms 23276 KB Output is correct
24 Correct 149 ms 23376 KB Output is correct
25 Correct 129 ms 23900 KB Output is correct
26 Correct 118 ms 24016 KB Output is correct
27 Correct 72 ms 18828 KB Output is correct
28 Correct 62 ms 18948 KB Output is correct
29 Correct 116 ms 22856 KB Output is correct
30 Correct 122 ms 23432 KB Output is correct
31 Correct 111 ms 23164 KB Output is correct
32 Correct 122 ms 23424 KB Output is correct
33 Correct 111 ms 23388 KB Output is correct
34 Correct 130 ms 24044 KB Output is correct
35 Correct 125 ms 24760 KB Output is correct
36 Correct 126 ms 24996 KB Output is correct
37 Correct 151 ms 22636 KB Output is correct
38 Correct 134 ms 22624 KB Output is correct
39 Correct 61 ms 18444 KB Output is correct
40 Correct 85 ms 18996 KB Output is correct
41 Correct 167 ms 22516 KB Output is correct
42 Correct 158 ms 23276 KB Output is correct
43 Correct 169 ms 23232 KB Output is correct
44 Correct 161 ms 22836 KB Output is correct
45 Correct 181 ms 23224 KB Output is correct
46 Correct 170 ms 23252 KB Output is correct
47 Correct 123 ms 22536 KB Output is correct
48 Correct 163 ms 23056 KB Output is correct
49 Correct 108 ms 21836 KB Output is correct
50 Correct 129 ms 22496 KB Output is correct
51 Correct 218 ms 23276 KB Output is correct
52 Correct 167 ms 23200 KB Output is correct
53 Correct 116 ms 23616 KB Output is correct
54 Correct 132 ms 25108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 24076 KB Output is correct
2 Correct 207 ms 24656 KB Output is correct
3 Correct 215 ms 24800 KB Output is correct
4 Correct 141 ms 22976 KB Output is correct
5 Correct 188 ms 23900 KB Output is correct
6 Correct 234 ms 24776 KB Output is correct
7 Correct 107 ms 19760 KB Output is correct
8 Correct 129 ms 19640 KB Output is correct
9 Correct 175 ms 23924 KB Output is correct
10 Correct 133 ms 22720 KB Output is correct
11 Correct 195 ms 24440 KB Output is correct
12 Correct 188 ms 24392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14668 KB Output is correct
2 Correct 11 ms 14640 KB Output is correct
3 Correct 10 ms 14684 KB Output is correct
4 Correct 12 ms 14680 KB Output is correct
5 Correct 10 ms 14540 KB Output is correct
6 Correct 10 ms 14524 KB Output is correct
7 Correct 12 ms 14680 KB Output is correct
8 Correct 11 ms 14668 KB Output is correct
9 Correct 11 ms 14668 KB Output is correct
10 Correct 11 ms 14668 KB Output is correct
11 Correct 11 ms 14640 KB Output is correct
12 Correct 11 ms 14680 KB Output is correct
13 Correct 11 ms 14676 KB Output is correct
14 Correct 10 ms 14668 KB Output is correct
15 Correct 10 ms 14668 KB Output is correct
16 Correct 11 ms 14664 KB Output is correct
17 Correct 10 ms 14668 KB Output is correct
18 Correct 11 ms 14628 KB Output is correct
19 Correct 10 ms 14668 KB Output is correct
20 Correct 11 ms 14716 KB Output is correct
21 Correct 14 ms 14676 KB Output is correct
22 Correct 11 ms 14700 KB Output is correct
23 Correct 11 ms 14680 KB Output is correct
24 Correct 11 ms 14668 KB Output is correct
25 Correct 10 ms 14540 KB Output is correct
26 Correct 9 ms 14532 KB Output is correct
27 Correct 12 ms 14668 KB Output is correct
28 Correct 13 ms 14684 KB Output is correct
29 Correct 12 ms 14668 KB Output is correct
30 Correct 12 ms 14796 KB Output is correct
31 Correct 12 ms 14680 KB Output is correct
32 Correct 12 ms 14668 KB Output is correct
33 Correct 10 ms 14716 KB Output is correct
34 Correct 11 ms 14700 KB Output is correct
35 Correct 11 ms 14668 KB Output is correct
36 Correct 12 ms 14644 KB Output is correct
37 Correct 10 ms 14684 KB Output is correct
38 Correct 12 ms 14684 KB Output is correct
39 Correct 113 ms 23360 KB Output is correct
40 Correct 120 ms 23900 KB Output is correct
41 Correct 126 ms 23276 KB Output is correct
42 Correct 149 ms 23376 KB Output is correct
43 Correct 129 ms 23900 KB Output is correct
44 Correct 118 ms 24016 KB Output is correct
45 Correct 72 ms 18828 KB Output is correct
46 Correct 62 ms 18948 KB Output is correct
47 Correct 116 ms 22856 KB Output is correct
48 Correct 122 ms 23432 KB Output is correct
49 Correct 111 ms 23164 KB Output is correct
50 Correct 122 ms 23424 KB Output is correct
51 Correct 111 ms 23388 KB Output is correct
52 Correct 130 ms 24044 KB Output is correct
53 Correct 125 ms 24760 KB Output is correct
54 Correct 126 ms 24996 KB Output is correct
55 Correct 151 ms 22636 KB Output is correct
56 Correct 134 ms 22624 KB Output is correct
57 Correct 61 ms 18444 KB Output is correct
58 Correct 85 ms 18996 KB Output is correct
59 Correct 167 ms 22516 KB Output is correct
60 Correct 158 ms 23276 KB Output is correct
61 Correct 169 ms 23232 KB Output is correct
62 Correct 161 ms 22836 KB Output is correct
63 Correct 181 ms 23224 KB Output is correct
64 Correct 170 ms 23252 KB Output is correct
65 Correct 123 ms 22536 KB Output is correct
66 Correct 163 ms 23056 KB Output is correct
67 Correct 108 ms 21836 KB Output is correct
68 Correct 129 ms 22496 KB Output is correct
69 Correct 218 ms 23276 KB Output is correct
70 Correct 167 ms 23200 KB Output is correct
71 Correct 116 ms 23616 KB Output is correct
72 Correct 132 ms 25108 KB Output is correct
73 Correct 202 ms 24076 KB Output is correct
74 Correct 207 ms 24656 KB Output is correct
75 Correct 215 ms 24800 KB Output is correct
76 Correct 141 ms 22976 KB Output is correct
77 Correct 188 ms 23900 KB Output is correct
78 Correct 234 ms 24776 KB Output is correct
79 Correct 107 ms 19760 KB Output is correct
80 Correct 129 ms 19640 KB Output is correct
81 Correct 175 ms 23924 KB Output is correct
82 Correct 133 ms 22720 KB Output is correct
83 Correct 195 ms 24440 KB Output is correct
84 Correct 188 ms 24392 KB Output is correct
85 Correct 166 ms 23248 KB Output is correct
86 Correct 221 ms 23744 KB Output is correct
87 Correct 161 ms 23524 KB Output is correct
88 Correct 181 ms 24384 KB Output is correct
89 Correct 113 ms 21336 KB Output is correct
90 Correct 169 ms 23784 KB Output is correct
91 Correct 134 ms 22884 KB Output is correct
92 Correct 127 ms 22556 KB Output is correct
93 Correct 188 ms 23752 KB Output is correct
94 Correct 164 ms 23356 KB Output is correct
95 Correct 169 ms 23560 KB Output is correct
96 Correct 170 ms 23756 KB Output is correct
97 Correct 176 ms 23744 KB Output is correct
98 Correct 137 ms 22956 KB Output is correct
99 Correct 118 ms 22992 KB Output is correct
100 Correct 140 ms 22664 KB Output is correct
101 Correct 176 ms 23496 KB Output is correct
102 Correct 134 ms 24336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14668 KB Output is correct
2 Correct 11 ms 14640 KB Output is correct
3 Correct 10 ms 14684 KB Output is correct
4 Correct 12 ms 14680 KB Output is correct
5 Correct 10 ms 14540 KB Output is correct
6 Correct 10 ms 14524 KB Output is correct
7 Correct 12 ms 14680 KB Output is correct
8 Correct 11 ms 14668 KB Output is correct
9 Correct 11 ms 14668 KB Output is correct
10 Correct 11 ms 14668 KB Output is correct
11 Correct 11 ms 14640 KB Output is correct
12 Correct 11 ms 14680 KB Output is correct
13 Correct 11 ms 14676 KB Output is correct
14 Correct 10 ms 14668 KB Output is correct
15 Correct 10 ms 14668 KB Output is correct
16 Correct 11 ms 14664 KB Output is correct
17 Correct 10 ms 14668 KB Output is correct
18 Correct 11 ms 14628 KB Output is correct
19 Correct 10 ms 14668 KB Output is correct
20 Correct 11 ms 14716 KB Output is correct
21 Correct 14 ms 14676 KB Output is correct
22 Correct 11 ms 14700 KB Output is correct
23 Correct 11 ms 14680 KB Output is correct
24 Correct 11 ms 14668 KB Output is correct
25 Correct 10 ms 14540 KB Output is correct
26 Correct 9 ms 14532 KB Output is correct
27 Correct 12 ms 14668 KB Output is correct
28 Correct 13 ms 14684 KB Output is correct
29 Correct 12 ms 14668 KB Output is correct
30 Correct 12 ms 14796 KB Output is correct
31 Correct 12 ms 14680 KB Output is correct
32 Correct 12 ms 14668 KB Output is correct
33 Correct 10 ms 14716 KB Output is correct
34 Correct 11 ms 14700 KB Output is correct
35 Correct 11 ms 14668 KB Output is correct
36 Correct 12 ms 14644 KB Output is correct
37 Correct 10 ms 14684 KB Output is correct
38 Correct 12 ms 14684 KB Output is correct
39 Correct 113 ms 23360 KB Output is correct
40 Correct 120 ms 23900 KB Output is correct
41 Correct 126 ms 23276 KB Output is correct
42 Correct 149 ms 23376 KB Output is correct
43 Correct 129 ms 23900 KB Output is correct
44 Correct 118 ms 24016 KB Output is correct
45 Correct 72 ms 18828 KB Output is correct
46 Correct 62 ms 18948 KB Output is correct
47 Correct 116 ms 22856 KB Output is correct
48 Correct 122 ms 23432 KB Output is correct
49 Correct 111 ms 23164 KB Output is correct
50 Correct 122 ms 23424 KB Output is correct
51 Correct 111 ms 23388 KB Output is correct
52 Correct 130 ms 24044 KB Output is correct
53 Correct 125 ms 24760 KB Output is correct
54 Correct 126 ms 24996 KB Output is correct
55 Runtime error 52 ms 47516 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -