답안 #442317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442317 2021-07-07T12:38:11 Z keta_tsimakuridze 푸드 코트 (JOI21_foodcourt) C++14
68 / 100
1000 ms 49040 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define pii pair<ll,ll> 
using namespace std;
const int N=250005,mod=1e9+7;
int t,n,m,q,g[N],ans[N];
ll tree[4*N],add[4*N],cnt[N];
pii lazy[4*N];
vector<int> t1;
vector<pair<ll,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);
}
ll 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);
}
ll 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  {
			ll 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; 
			ll 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(0,ans[i])<<" ";
	}
}

Compilation message

foodcourt.cpp:78:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   78 |  main(){
      |  ^~~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:106:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |   for(int j=0;j<st[i].size();j++) {
      |               ~^~~~~~~~~~~~~
foodcourt.cpp:109:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |   for(int j=0;j<x[i].size();j++) {
      |               ~^~~~~~~~~~~~
foodcourt.cpp:129:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |   for(int j=0;j<en[i].size();j++){
      |               ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 18124 KB Output is correct
2 Correct 13 ms 18124 KB Output is correct
3 Correct 12 ms 18124 KB Output is correct
4 Correct 13 ms 18156 KB Output is correct
5 Correct 11 ms 18004 KB Output is correct
6 Correct 11 ms 18072 KB Output is correct
7 Correct 13 ms 18124 KB Output is correct
8 Correct 13 ms 18124 KB Output is correct
9 Correct 13 ms 18124 KB Output is correct
10 Correct 12 ms 18124 KB Output is correct
11 Correct 12 ms 18124 KB Output is correct
12 Correct 13 ms 18140 KB Output is correct
13 Correct 12 ms 18060 KB Output is correct
14 Correct 13 ms 18124 KB Output is correct
15 Correct 12 ms 18084 KB Output is correct
16 Correct 12 ms 18108 KB Output is correct
17 Correct 12 ms 18128 KB Output is correct
18 Correct 13 ms 18124 KB Output is correct
19 Correct 12 ms 18216 KB Output is correct
20 Correct 12 ms 18124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 18124 KB Output is correct
2 Correct 13 ms 18124 KB Output is correct
3 Correct 12 ms 18124 KB Output is correct
4 Correct 13 ms 18156 KB Output is correct
5 Correct 11 ms 18004 KB Output is correct
6 Correct 11 ms 18072 KB Output is correct
7 Correct 13 ms 18124 KB Output is correct
8 Correct 13 ms 18124 KB Output is correct
9 Correct 13 ms 18124 KB Output is correct
10 Correct 12 ms 18124 KB Output is correct
11 Correct 12 ms 18124 KB Output is correct
12 Correct 13 ms 18140 KB Output is correct
13 Correct 12 ms 18060 KB Output is correct
14 Correct 13 ms 18124 KB Output is correct
15 Correct 12 ms 18084 KB Output is correct
16 Correct 12 ms 18108 KB Output is correct
17 Correct 12 ms 18128 KB Output is correct
18 Correct 13 ms 18124 KB Output is correct
19 Correct 12 ms 18216 KB Output is correct
20 Correct 12 ms 18124 KB Output is correct
21 Correct 13 ms 18188 KB Output is correct
22 Correct 13 ms 18076 KB Output is correct
23 Correct 13 ms 18100 KB Output is correct
24 Correct 13 ms 18124 KB Output is correct
25 Correct 11 ms 17996 KB Output is correct
26 Correct 12 ms 17996 KB Output is correct
27 Correct 13 ms 18104 KB Output is correct
28 Correct 13 ms 18116 KB Output is correct
29 Correct 13 ms 18124 KB Output is correct
30 Correct 13 ms 18076 KB Output is correct
31 Correct 13 ms 18096 KB Output is correct
32 Correct 13 ms 18192 KB Output is correct
33 Correct 12 ms 18188 KB Output is correct
34 Correct 12 ms 18124 KB Output is correct
35 Correct 13 ms 18124 KB Output is correct
36 Correct 12 ms 18188 KB Output is correct
37 Correct 12 ms 18164 KB Output is correct
38 Correct 13 ms 18212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 25100 KB Output is correct
2 Correct 113 ms 25560 KB Output is correct
3 Correct 122 ms 25048 KB Output is correct
4 Correct 108 ms 25072 KB Output is correct
5 Correct 109 ms 25544 KB Output is correct
6 Correct 110 ms 25512 KB Output is correct
7 Correct 60 ms 21312 KB Output is correct
8 Correct 63 ms 21188 KB Output is correct
9 Correct 106 ms 24660 KB Output is correct
10 Correct 107 ms 25016 KB Output is correct
11 Correct 113 ms 24916 KB Output is correct
12 Correct 118 ms 25080 KB Output is correct
13 Correct 105 ms 25372 KB Output is correct
14 Correct 123 ms 25792 KB Output is correct
15 Correct 116 ms 26272 KB Output is correct
16 Correct 121 ms 26460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 783 ms 44992 KB Output is correct
2 Correct 607 ms 42828 KB Output is correct
3 Correct 925 ms 46160 KB Output is correct
4 Correct 665 ms 43968 KB Output is correct
5 Correct 626 ms 44060 KB Output is correct
6 Correct 935 ms 47416 KB Output is correct
7 Correct 354 ms 30868 KB Output is correct
8 Correct 365 ms 31232 KB Output is correct
9 Execution timed out 1053 ms 49040 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 18124 KB Output is correct
2 Correct 13 ms 18124 KB Output is correct
3 Correct 12 ms 18124 KB Output is correct
4 Correct 13 ms 18156 KB Output is correct
5 Correct 11 ms 18004 KB Output is correct
6 Correct 11 ms 18072 KB Output is correct
7 Correct 13 ms 18124 KB Output is correct
8 Correct 13 ms 18124 KB Output is correct
9 Correct 13 ms 18124 KB Output is correct
10 Correct 12 ms 18124 KB Output is correct
11 Correct 12 ms 18124 KB Output is correct
12 Correct 13 ms 18140 KB Output is correct
13 Correct 12 ms 18060 KB Output is correct
14 Correct 13 ms 18124 KB Output is correct
15 Correct 12 ms 18084 KB Output is correct
16 Correct 12 ms 18108 KB Output is correct
17 Correct 12 ms 18128 KB Output is correct
18 Correct 13 ms 18124 KB Output is correct
19 Correct 12 ms 18216 KB Output is correct
20 Correct 12 ms 18124 KB Output is correct
21 Correct 109 ms 25100 KB Output is correct
22 Correct 113 ms 25560 KB Output is correct
23 Correct 122 ms 25048 KB Output is correct
24 Correct 108 ms 25072 KB Output is correct
25 Correct 109 ms 25544 KB Output is correct
26 Correct 110 ms 25512 KB Output is correct
27 Correct 60 ms 21312 KB Output is correct
28 Correct 63 ms 21188 KB Output is correct
29 Correct 106 ms 24660 KB Output is correct
30 Correct 107 ms 25016 KB Output is correct
31 Correct 113 ms 24916 KB Output is correct
32 Correct 118 ms 25080 KB Output is correct
33 Correct 105 ms 25372 KB Output is correct
34 Correct 123 ms 25792 KB Output is correct
35 Correct 116 ms 26272 KB Output is correct
36 Correct 121 ms 26460 KB Output is correct
37 Correct 148 ms 24736 KB Output is correct
38 Correct 128 ms 24780 KB Output is correct
39 Correct 63 ms 21112 KB Output is correct
40 Correct 71 ms 21260 KB Output is correct
41 Correct 200 ms 24384 KB Output is correct
42 Correct 158 ms 25084 KB Output is correct
43 Correct 166 ms 25076 KB Output is correct
44 Correct 166 ms 24716 KB Output is correct
45 Correct 165 ms 25068 KB Output is correct
46 Correct 175 ms 25032 KB Output is correct
47 Correct 121 ms 24500 KB Output is correct
48 Correct 154 ms 24992 KB Output is correct
49 Correct 108 ms 24188 KB Output is correct
50 Correct 125 ms 24532 KB Output is correct
51 Correct 153 ms 25156 KB Output is correct
52 Correct 151 ms 25028 KB Output is correct
53 Correct 94 ms 25556 KB Output is correct
54 Correct 118 ms 26504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 185 ms 25696 KB Output is correct
2 Correct 222 ms 25920 KB Output is correct
3 Correct 206 ms 26052 KB Output is correct
4 Correct 149 ms 24884 KB Output is correct
5 Correct 197 ms 25492 KB Output is correct
6 Correct 215 ms 25968 KB Output is correct
7 Correct 110 ms 21564 KB Output is correct
8 Correct 125 ms 21560 KB Output is correct
9 Correct 155 ms 25300 KB Output is correct
10 Correct 128 ms 24712 KB Output is correct
11 Correct 196 ms 25656 KB Output is correct
12 Correct 217 ms 25656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 18124 KB Output is correct
2 Correct 13 ms 18124 KB Output is correct
3 Correct 12 ms 18124 KB Output is correct
4 Correct 13 ms 18156 KB Output is correct
5 Correct 11 ms 18004 KB Output is correct
6 Correct 11 ms 18072 KB Output is correct
7 Correct 13 ms 18124 KB Output is correct
8 Correct 13 ms 18124 KB Output is correct
9 Correct 13 ms 18124 KB Output is correct
10 Correct 12 ms 18124 KB Output is correct
11 Correct 12 ms 18124 KB Output is correct
12 Correct 13 ms 18140 KB Output is correct
13 Correct 12 ms 18060 KB Output is correct
14 Correct 13 ms 18124 KB Output is correct
15 Correct 12 ms 18084 KB Output is correct
16 Correct 12 ms 18108 KB Output is correct
17 Correct 12 ms 18128 KB Output is correct
18 Correct 13 ms 18124 KB Output is correct
19 Correct 12 ms 18216 KB Output is correct
20 Correct 12 ms 18124 KB Output is correct
21 Correct 13 ms 18188 KB Output is correct
22 Correct 13 ms 18076 KB Output is correct
23 Correct 13 ms 18100 KB Output is correct
24 Correct 13 ms 18124 KB Output is correct
25 Correct 11 ms 17996 KB Output is correct
26 Correct 12 ms 17996 KB Output is correct
27 Correct 13 ms 18104 KB Output is correct
28 Correct 13 ms 18116 KB Output is correct
29 Correct 13 ms 18124 KB Output is correct
30 Correct 13 ms 18076 KB Output is correct
31 Correct 13 ms 18096 KB Output is correct
32 Correct 13 ms 18192 KB Output is correct
33 Correct 12 ms 18188 KB Output is correct
34 Correct 12 ms 18124 KB Output is correct
35 Correct 13 ms 18124 KB Output is correct
36 Correct 12 ms 18188 KB Output is correct
37 Correct 12 ms 18164 KB Output is correct
38 Correct 13 ms 18212 KB Output is correct
39 Correct 109 ms 25100 KB Output is correct
40 Correct 113 ms 25560 KB Output is correct
41 Correct 122 ms 25048 KB Output is correct
42 Correct 108 ms 25072 KB Output is correct
43 Correct 109 ms 25544 KB Output is correct
44 Correct 110 ms 25512 KB Output is correct
45 Correct 60 ms 21312 KB Output is correct
46 Correct 63 ms 21188 KB Output is correct
47 Correct 106 ms 24660 KB Output is correct
48 Correct 107 ms 25016 KB Output is correct
49 Correct 113 ms 24916 KB Output is correct
50 Correct 118 ms 25080 KB Output is correct
51 Correct 105 ms 25372 KB Output is correct
52 Correct 123 ms 25792 KB Output is correct
53 Correct 116 ms 26272 KB Output is correct
54 Correct 121 ms 26460 KB Output is correct
55 Correct 148 ms 24736 KB Output is correct
56 Correct 128 ms 24780 KB Output is correct
57 Correct 63 ms 21112 KB Output is correct
58 Correct 71 ms 21260 KB Output is correct
59 Correct 200 ms 24384 KB Output is correct
60 Correct 158 ms 25084 KB Output is correct
61 Correct 166 ms 25076 KB Output is correct
62 Correct 166 ms 24716 KB Output is correct
63 Correct 165 ms 25068 KB Output is correct
64 Correct 175 ms 25032 KB Output is correct
65 Correct 121 ms 24500 KB Output is correct
66 Correct 154 ms 24992 KB Output is correct
67 Correct 108 ms 24188 KB Output is correct
68 Correct 125 ms 24532 KB Output is correct
69 Correct 153 ms 25156 KB Output is correct
70 Correct 151 ms 25028 KB Output is correct
71 Correct 94 ms 25556 KB Output is correct
72 Correct 118 ms 26504 KB Output is correct
73 Correct 185 ms 25696 KB Output is correct
74 Correct 222 ms 25920 KB Output is correct
75 Correct 206 ms 26052 KB Output is correct
76 Correct 149 ms 24884 KB Output is correct
77 Correct 197 ms 25492 KB Output is correct
78 Correct 215 ms 25968 KB Output is correct
79 Correct 110 ms 21564 KB Output is correct
80 Correct 125 ms 21560 KB Output is correct
81 Correct 155 ms 25300 KB Output is correct
82 Correct 128 ms 24712 KB Output is correct
83 Correct 196 ms 25656 KB Output is correct
84 Correct 217 ms 25656 KB Output is correct
85 Correct 162 ms 24760 KB Output is correct
86 Correct 181 ms 25088 KB Output is correct
87 Correct 152 ms 25144 KB Output is correct
88 Correct 185 ms 25460 KB Output is correct
89 Correct 115 ms 23444 KB Output is correct
90 Correct 165 ms 25020 KB Output is correct
91 Correct 142 ms 24560 KB Output is correct
92 Correct 126 ms 24336 KB Output is correct
93 Correct 176 ms 25024 KB Output is correct
94 Correct 193 ms 24768 KB Output is correct
95 Correct 193 ms 24960 KB Output is correct
96 Correct 163 ms 25020 KB Output is correct
97 Correct 196 ms 24984 KB Output is correct
98 Correct 144 ms 24680 KB Output is correct
99 Correct 135 ms 24532 KB Output is correct
100 Correct 130 ms 24388 KB Output is correct
101 Correct 158 ms 24940 KB Output is correct
102 Correct 125 ms 25708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 18124 KB Output is correct
2 Correct 13 ms 18124 KB Output is correct
3 Correct 12 ms 18124 KB Output is correct
4 Correct 13 ms 18156 KB Output is correct
5 Correct 11 ms 18004 KB Output is correct
6 Correct 11 ms 18072 KB Output is correct
7 Correct 13 ms 18124 KB Output is correct
8 Correct 13 ms 18124 KB Output is correct
9 Correct 13 ms 18124 KB Output is correct
10 Correct 12 ms 18124 KB Output is correct
11 Correct 12 ms 18124 KB Output is correct
12 Correct 13 ms 18140 KB Output is correct
13 Correct 12 ms 18060 KB Output is correct
14 Correct 13 ms 18124 KB Output is correct
15 Correct 12 ms 18084 KB Output is correct
16 Correct 12 ms 18108 KB Output is correct
17 Correct 12 ms 18128 KB Output is correct
18 Correct 13 ms 18124 KB Output is correct
19 Correct 12 ms 18216 KB Output is correct
20 Correct 12 ms 18124 KB Output is correct
21 Correct 13 ms 18188 KB Output is correct
22 Correct 13 ms 18076 KB Output is correct
23 Correct 13 ms 18100 KB Output is correct
24 Correct 13 ms 18124 KB Output is correct
25 Correct 11 ms 17996 KB Output is correct
26 Correct 12 ms 17996 KB Output is correct
27 Correct 13 ms 18104 KB Output is correct
28 Correct 13 ms 18116 KB Output is correct
29 Correct 13 ms 18124 KB Output is correct
30 Correct 13 ms 18076 KB Output is correct
31 Correct 13 ms 18096 KB Output is correct
32 Correct 13 ms 18192 KB Output is correct
33 Correct 12 ms 18188 KB Output is correct
34 Correct 12 ms 18124 KB Output is correct
35 Correct 13 ms 18124 KB Output is correct
36 Correct 12 ms 18188 KB Output is correct
37 Correct 12 ms 18164 KB Output is correct
38 Correct 13 ms 18212 KB Output is correct
39 Correct 109 ms 25100 KB Output is correct
40 Correct 113 ms 25560 KB Output is correct
41 Correct 122 ms 25048 KB Output is correct
42 Correct 108 ms 25072 KB Output is correct
43 Correct 109 ms 25544 KB Output is correct
44 Correct 110 ms 25512 KB Output is correct
45 Correct 60 ms 21312 KB Output is correct
46 Correct 63 ms 21188 KB Output is correct
47 Correct 106 ms 24660 KB Output is correct
48 Correct 107 ms 25016 KB Output is correct
49 Correct 113 ms 24916 KB Output is correct
50 Correct 118 ms 25080 KB Output is correct
51 Correct 105 ms 25372 KB Output is correct
52 Correct 123 ms 25792 KB Output is correct
53 Correct 116 ms 26272 KB Output is correct
54 Correct 121 ms 26460 KB Output is correct
55 Correct 783 ms 44992 KB Output is correct
56 Correct 607 ms 42828 KB Output is correct
57 Correct 925 ms 46160 KB Output is correct
58 Correct 665 ms 43968 KB Output is correct
59 Correct 626 ms 44060 KB Output is correct
60 Correct 935 ms 47416 KB Output is correct
61 Correct 354 ms 30868 KB Output is correct
62 Correct 365 ms 31232 KB Output is correct
63 Execution timed out 1053 ms 49040 KB Time limit exceeded
64 Halted 0 ms 0 KB -