Submission #442313

# Submission time Handle Problem Language Result Execution time Memory
442313 2021-07-07T12:34:38 Z keta_tsimakuridze Food Court (JOI21_foodcourt) C++14
68 / 100
1000 ms 57632 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=250005,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 14 ms 18124 KB Output is correct
2 Correct 13 ms 18148 KB Output is correct
3 Correct 12 ms 18152 KB Output is correct
4 Correct 14 ms 18124 KB Output is correct
5 Correct 12 ms 18016 KB Output is correct
6 Correct 12 ms 17996 KB Output is correct
7 Correct 13 ms 18128 KB Output is correct
8 Correct 13 ms 18124 KB Output is correct
9 Correct 13 ms 18124 KB Output is correct
10 Correct 14 ms 18192 KB Output is correct
11 Correct 13 ms 18156 KB Output is correct
12 Correct 13 ms 18136 KB Output is correct
13 Correct 12 ms 18172 KB Output is correct
14 Correct 13 ms 18188 KB Output is correct
15 Correct 12 ms 18124 KB Output is correct
16 Correct 13 ms 18172 KB Output is correct
17 Correct 14 ms 18200 KB Output is correct
18 Correct 13 ms 18152 KB Output is correct
19 Correct 13 ms 18168 KB Output is correct
20 Correct 12 ms 18160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 18124 KB Output is correct
2 Correct 13 ms 18148 KB Output is correct
3 Correct 12 ms 18152 KB Output is correct
4 Correct 14 ms 18124 KB Output is correct
5 Correct 12 ms 18016 KB Output is correct
6 Correct 12 ms 17996 KB Output is correct
7 Correct 13 ms 18128 KB Output is correct
8 Correct 13 ms 18124 KB Output is correct
9 Correct 13 ms 18124 KB Output is correct
10 Correct 14 ms 18192 KB Output is correct
11 Correct 13 ms 18156 KB Output is correct
12 Correct 13 ms 18136 KB Output is correct
13 Correct 12 ms 18172 KB Output is correct
14 Correct 13 ms 18188 KB Output is correct
15 Correct 12 ms 18124 KB Output is correct
16 Correct 13 ms 18172 KB Output is correct
17 Correct 14 ms 18200 KB Output is correct
18 Correct 13 ms 18152 KB Output is correct
19 Correct 13 ms 18168 KB Output is correct
20 Correct 12 ms 18160 KB Output is correct
21 Correct 13 ms 18208 KB Output is correct
22 Correct 13 ms 18124 KB Output is correct
23 Correct 13 ms 18108 KB Output is correct
24 Correct 13 ms 18232 KB Output is correct
25 Correct 12 ms 18096 KB Output is correct
26 Correct 12 ms 17996 KB Output is correct
27 Correct 13 ms 18200 KB Output is correct
28 Correct 13 ms 18116 KB Output is correct
29 Correct 13 ms 18208 KB Output is correct
30 Correct 14 ms 18192 KB Output is correct
31 Correct 13 ms 18156 KB Output is correct
32 Correct 13 ms 18116 KB Output is correct
33 Correct 12 ms 18212 KB Output is correct
34 Correct 12 ms 18124 KB Output is correct
35 Correct 12 ms 18204 KB Output is correct
36 Correct 13 ms 18216 KB Output is correct
37 Correct 12 ms 18104 KB Output is correct
38 Correct 13 ms 18148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 25596 KB Output is correct
2 Correct 113 ms 26176 KB Output is correct
3 Correct 113 ms 25696 KB Output is correct
4 Correct 114 ms 25668 KB Output is correct
5 Correct 118 ms 26176 KB Output is correct
6 Correct 117 ms 26196 KB Output is correct
7 Correct 65 ms 21700 KB Output is correct
8 Correct 63 ms 21700 KB Output is correct
9 Correct 107 ms 25072 KB Output is correct
10 Correct 114 ms 25688 KB Output is correct
11 Correct 120 ms 25484 KB Output is correct
12 Correct 111 ms 25620 KB Output is correct
13 Correct 116 ms 25976 KB Output is correct
14 Correct 133 ms 26492 KB Output is correct
15 Correct 121 ms 27068 KB Output is correct
16 Correct 122 ms 27224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 828 ms 52380 KB Output is correct
2 Correct 611 ms 48856 KB Output is correct
3 Correct 881 ms 54280 KB Output is correct
4 Correct 603 ms 50104 KB Output is correct
5 Correct 608 ms 50344 KB Output is correct
6 Correct 841 ms 56128 KB Output is correct
7 Correct 359 ms 37676 KB Output is correct
8 Correct 358 ms 37244 KB Output is correct
9 Execution timed out 1026 ms 57632 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 18124 KB Output is correct
2 Correct 13 ms 18148 KB Output is correct
3 Correct 12 ms 18152 KB Output is correct
4 Correct 14 ms 18124 KB Output is correct
5 Correct 12 ms 18016 KB Output is correct
6 Correct 12 ms 17996 KB Output is correct
7 Correct 13 ms 18128 KB Output is correct
8 Correct 13 ms 18124 KB Output is correct
9 Correct 13 ms 18124 KB Output is correct
10 Correct 14 ms 18192 KB Output is correct
11 Correct 13 ms 18156 KB Output is correct
12 Correct 13 ms 18136 KB Output is correct
13 Correct 12 ms 18172 KB Output is correct
14 Correct 13 ms 18188 KB Output is correct
15 Correct 12 ms 18124 KB Output is correct
16 Correct 13 ms 18172 KB Output is correct
17 Correct 14 ms 18200 KB Output is correct
18 Correct 13 ms 18152 KB Output is correct
19 Correct 13 ms 18168 KB Output is correct
20 Correct 12 ms 18160 KB Output is correct
21 Correct 102 ms 25596 KB Output is correct
22 Correct 113 ms 26176 KB Output is correct
23 Correct 113 ms 25696 KB Output is correct
24 Correct 114 ms 25668 KB Output is correct
25 Correct 118 ms 26176 KB Output is correct
26 Correct 117 ms 26196 KB Output is correct
27 Correct 65 ms 21700 KB Output is correct
28 Correct 63 ms 21700 KB Output is correct
29 Correct 107 ms 25072 KB Output is correct
30 Correct 114 ms 25688 KB Output is correct
31 Correct 120 ms 25484 KB Output is correct
32 Correct 111 ms 25620 KB Output is correct
33 Correct 116 ms 25976 KB Output is correct
34 Correct 133 ms 26492 KB Output is correct
35 Correct 121 ms 27068 KB Output is correct
36 Correct 122 ms 27224 KB Output is correct
37 Correct 159 ms 25288 KB Output is correct
38 Correct 132 ms 25320 KB Output is correct
39 Correct 61 ms 21332 KB Output is correct
40 Correct 71 ms 21816 KB Output is correct
41 Correct 147 ms 24904 KB Output is correct
42 Correct 152 ms 25804 KB Output is correct
43 Correct 158 ms 25624 KB Output is correct
44 Correct 161 ms 25284 KB Output is correct
45 Correct 177 ms 25720 KB Output is correct
46 Correct 163 ms 25708 KB Output is correct
47 Correct 116 ms 25084 KB Output is correct
48 Correct 149 ms 25536 KB Output is correct
49 Correct 108 ms 24584 KB Output is correct
50 Correct 136 ms 25060 KB Output is correct
51 Correct 150 ms 25660 KB Output is correct
52 Correct 156 ms 25688 KB Output is correct
53 Correct 99 ms 26192 KB Output is correct
54 Correct 127 ms 27236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 26216 KB Output is correct
2 Correct 211 ms 26660 KB Output is correct
3 Correct 206 ms 26640 KB Output is correct
4 Correct 187 ms 25280 KB Output is correct
5 Correct 177 ms 26116 KB Output is correct
6 Correct 204 ms 26688 KB Output is correct
7 Correct 111 ms 22216 KB Output is correct
8 Correct 102 ms 22192 KB Output is correct
9 Correct 155 ms 25908 KB Output is correct
10 Correct 137 ms 25152 KB Output is correct
11 Correct 206 ms 26304 KB Output is correct
12 Correct 192 ms 26300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 18124 KB Output is correct
2 Correct 13 ms 18148 KB Output is correct
3 Correct 12 ms 18152 KB Output is correct
4 Correct 14 ms 18124 KB Output is correct
5 Correct 12 ms 18016 KB Output is correct
6 Correct 12 ms 17996 KB Output is correct
7 Correct 13 ms 18128 KB Output is correct
8 Correct 13 ms 18124 KB Output is correct
9 Correct 13 ms 18124 KB Output is correct
10 Correct 14 ms 18192 KB Output is correct
11 Correct 13 ms 18156 KB Output is correct
12 Correct 13 ms 18136 KB Output is correct
13 Correct 12 ms 18172 KB Output is correct
14 Correct 13 ms 18188 KB Output is correct
15 Correct 12 ms 18124 KB Output is correct
16 Correct 13 ms 18172 KB Output is correct
17 Correct 14 ms 18200 KB Output is correct
18 Correct 13 ms 18152 KB Output is correct
19 Correct 13 ms 18168 KB Output is correct
20 Correct 12 ms 18160 KB Output is correct
21 Correct 13 ms 18208 KB Output is correct
22 Correct 13 ms 18124 KB Output is correct
23 Correct 13 ms 18108 KB Output is correct
24 Correct 13 ms 18232 KB Output is correct
25 Correct 12 ms 18096 KB Output is correct
26 Correct 12 ms 17996 KB Output is correct
27 Correct 13 ms 18200 KB Output is correct
28 Correct 13 ms 18116 KB Output is correct
29 Correct 13 ms 18208 KB Output is correct
30 Correct 14 ms 18192 KB Output is correct
31 Correct 13 ms 18156 KB Output is correct
32 Correct 13 ms 18116 KB Output is correct
33 Correct 12 ms 18212 KB Output is correct
34 Correct 12 ms 18124 KB Output is correct
35 Correct 12 ms 18204 KB Output is correct
36 Correct 13 ms 18216 KB Output is correct
37 Correct 12 ms 18104 KB Output is correct
38 Correct 13 ms 18148 KB Output is correct
39 Correct 102 ms 25596 KB Output is correct
40 Correct 113 ms 26176 KB Output is correct
41 Correct 113 ms 25696 KB Output is correct
42 Correct 114 ms 25668 KB Output is correct
43 Correct 118 ms 26176 KB Output is correct
44 Correct 117 ms 26196 KB Output is correct
45 Correct 65 ms 21700 KB Output is correct
46 Correct 63 ms 21700 KB Output is correct
47 Correct 107 ms 25072 KB Output is correct
48 Correct 114 ms 25688 KB Output is correct
49 Correct 120 ms 25484 KB Output is correct
50 Correct 111 ms 25620 KB Output is correct
51 Correct 116 ms 25976 KB Output is correct
52 Correct 133 ms 26492 KB Output is correct
53 Correct 121 ms 27068 KB Output is correct
54 Correct 122 ms 27224 KB Output is correct
55 Correct 159 ms 25288 KB Output is correct
56 Correct 132 ms 25320 KB Output is correct
57 Correct 61 ms 21332 KB Output is correct
58 Correct 71 ms 21816 KB Output is correct
59 Correct 147 ms 24904 KB Output is correct
60 Correct 152 ms 25804 KB Output is correct
61 Correct 158 ms 25624 KB Output is correct
62 Correct 161 ms 25284 KB Output is correct
63 Correct 177 ms 25720 KB Output is correct
64 Correct 163 ms 25708 KB Output is correct
65 Correct 116 ms 25084 KB Output is correct
66 Correct 149 ms 25536 KB Output is correct
67 Correct 108 ms 24584 KB Output is correct
68 Correct 136 ms 25060 KB Output is correct
69 Correct 150 ms 25660 KB Output is correct
70 Correct 156 ms 25688 KB Output is correct
71 Correct 99 ms 26192 KB Output is correct
72 Correct 127 ms 27236 KB Output is correct
73 Correct 194 ms 26216 KB Output is correct
74 Correct 211 ms 26660 KB Output is correct
75 Correct 206 ms 26640 KB Output is correct
76 Correct 187 ms 25280 KB Output is correct
77 Correct 177 ms 26116 KB Output is correct
78 Correct 204 ms 26688 KB Output is correct
79 Correct 111 ms 22216 KB Output is correct
80 Correct 102 ms 22192 KB Output is correct
81 Correct 155 ms 25908 KB Output is correct
82 Correct 137 ms 25152 KB Output is correct
83 Correct 206 ms 26304 KB Output is correct
84 Correct 192 ms 26300 KB Output is correct
85 Correct 162 ms 25328 KB Output is correct
86 Correct 180 ms 25636 KB Output is correct
87 Correct 158 ms 25668 KB Output is correct
88 Correct 172 ms 26104 KB Output is correct
89 Correct 107 ms 23788 KB Output is correct
90 Correct 155 ms 25640 KB Output is correct
91 Correct 134 ms 25004 KB Output is correct
92 Correct 137 ms 24888 KB Output is correct
93 Correct 171 ms 25664 KB Output is correct
94 Correct 172 ms 25336 KB Output is correct
95 Correct 162 ms 25544 KB Output is correct
96 Correct 178 ms 25664 KB Output is correct
97 Correct 164 ms 25584 KB Output is correct
98 Correct 136 ms 25080 KB Output is correct
99 Correct 126 ms 25100 KB Output is correct
100 Correct 134 ms 25016 KB Output is correct
101 Correct 172 ms 25556 KB Output is correct
102 Correct 124 ms 26236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 18124 KB Output is correct
2 Correct 13 ms 18148 KB Output is correct
3 Correct 12 ms 18152 KB Output is correct
4 Correct 14 ms 18124 KB Output is correct
5 Correct 12 ms 18016 KB Output is correct
6 Correct 12 ms 17996 KB Output is correct
7 Correct 13 ms 18128 KB Output is correct
8 Correct 13 ms 18124 KB Output is correct
9 Correct 13 ms 18124 KB Output is correct
10 Correct 14 ms 18192 KB Output is correct
11 Correct 13 ms 18156 KB Output is correct
12 Correct 13 ms 18136 KB Output is correct
13 Correct 12 ms 18172 KB Output is correct
14 Correct 13 ms 18188 KB Output is correct
15 Correct 12 ms 18124 KB Output is correct
16 Correct 13 ms 18172 KB Output is correct
17 Correct 14 ms 18200 KB Output is correct
18 Correct 13 ms 18152 KB Output is correct
19 Correct 13 ms 18168 KB Output is correct
20 Correct 12 ms 18160 KB Output is correct
21 Correct 13 ms 18208 KB Output is correct
22 Correct 13 ms 18124 KB Output is correct
23 Correct 13 ms 18108 KB Output is correct
24 Correct 13 ms 18232 KB Output is correct
25 Correct 12 ms 18096 KB Output is correct
26 Correct 12 ms 17996 KB Output is correct
27 Correct 13 ms 18200 KB Output is correct
28 Correct 13 ms 18116 KB Output is correct
29 Correct 13 ms 18208 KB Output is correct
30 Correct 14 ms 18192 KB Output is correct
31 Correct 13 ms 18156 KB Output is correct
32 Correct 13 ms 18116 KB Output is correct
33 Correct 12 ms 18212 KB Output is correct
34 Correct 12 ms 18124 KB Output is correct
35 Correct 12 ms 18204 KB Output is correct
36 Correct 13 ms 18216 KB Output is correct
37 Correct 12 ms 18104 KB Output is correct
38 Correct 13 ms 18148 KB Output is correct
39 Correct 102 ms 25596 KB Output is correct
40 Correct 113 ms 26176 KB Output is correct
41 Correct 113 ms 25696 KB Output is correct
42 Correct 114 ms 25668 KB Output is correct
43 Correct 118 ms 26176 KB Output is correct
44 Correct 117 ms 26196 KB Output is correct
45 Correct 65 ms 21700 KB Output is correct
46 Correct 63 ms 21700 KB Output is correct
47 Correct 107 ms 25072 KB Output is correct
48 Correct 114 ms 25688 KB Output is correct
49 Correct 120 ms 25484 KB Output is correct
50 Correct 111 ms 25620 KB Output is correct
51 Correct 116 ms 25976 KB Output is correct
52 Correct 133 ms 26492 KB Output is correct
53 Correct 121 ms 27068 KB Output is correct
54 Correct 122 ms 27224 KB Output is correct
55 Correct 828 ms 52380 KB Output is correct
56 Correct 611 ms 48856 KB Output is correct
57 Correct 881 ms 54280 KB Output is correct
58 Correct 603 ms 50104 KB Output is correct
59 Correct 608 ms 50344 KB Output is correct
60 Correct 841 ms 56128 KB Output is correct
61 Correct 359 ms 37676 KB Output is correct
62 Correct 358 ms 37244 KB Output is correct
63 Execution timed out 1026 ms 57632 KB Time limit exceeded
64 Halted 0 ms 0 KB -