답안 #442316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442316 2021-07-07T12:37:15 Z keta_tsimakuridze 푸드 코트 (JOI21_foodcourt) C++14
24 / 100
638 ms 45068 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);
}
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  {
			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; 
			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(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 15 ms 18124 KB Output is correct
2 Correct 18 ms 18200 KB Output is correct
3 Correct 15 ms 18124 KB Output is correct
4 Correct 14 ms 18200 KB Output is correct
5 Correct 13 ms 17996 KB Output is correct
6 Correct 14 ms 18020 KB Output is correct
7 Correct 13 ms 18108 KB Output is correct
8 Correct 13 ms 18136 KB Output is correct
9 Correct 17 ms 18124 KB Output is correct
10 Correct 18 ms 18084 KB Output is correct
11 Correct 16 ms 18124 KB Output is correct
12 Correct 14 ms 18120 KB Output is correct
13 Correct 14 ms 18184 KB Output is correct
14 Correct 13 ms 18152 KB Output is correct
15 Correct 14 ms 18164 KB Output is correct
16 Correct 15 ms 18108 KB Output is correct
17 Correct 14 ms 18124 KB Output is correct
18 Correct 14 ms 18124 KB Output is correct
19 Correct 15 ms 18124 KB Output is correct
20 Correct 16 ms 18200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 18124 KB Output is correct
2 Correct 18 ms 18200 KB Output is correct
3 Correct 15 ms 18124 KB Output is correct
4 Correct 14 ms 18200 KB Output is correct
5 Correct 13 ms 17996 KB Output is correct
6 Correct 14 ms 18020 KB Output is correct
7 Correct 13 ms 18108 KB Output is correct
8 Correct 13 ms 18136 KB Output is correct
9 Correct 17 ms 18124 KB Output is correct
10 Correct 18 ms 18084 KB Output is correct
11 Correct 16 ms 18124 KB Output is correct
12 Correct 14 ms 18120 KB Output is correct
13 Correct 14 ms 18184 KB Output is correct
14 Correct 13 ms 18152 KB Output is correct
15 Correct 14 ms 18164 KB Output is correct
16 Correct 15 ms 18108 KB Output is correct
17 Correct 14 ms 18124 KB Output is correct
18 Correct 14 ms 18124 KB Output is correct
19 Correct 15 ms 18124 KB Output is correct
20 Correct 16 ms 18200 KB Output is correct
21 Incorrect 13 ms 18108 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 25036 KB Output is correct
2 Correct 139 ms 25544 KB Output is correct
3 Correct 117 ms 24984 KB Output is correct
4 Correct 105 ms 25028 KB Output is correct
5 Correct 129 ms 25540 KB Output is correct
6 Correct 131 ms 25612 KB Output is correct
7 Correct 62 ms 21216 KB Output is correct
8 Correct 63 ms 21084 KB Output is correct
9 Correct 109 ms 24624 KB Output is correct
10 Correct 108 ms 25028 KB Output is correct
11 Correct 115 ms 24900 KB Output is correct
12 Correct 146 ms 25088 KB Output is correct
13 Correct 109 ms 25384 KB Output is correct
14 Correct 127 ms 25776 KB Output is correct
15 Correct 116 ms 26304 KB Output is correct
16 Correct 134 ms 26532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 638 ms 45068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 18124 KB Output is correct
2 Correct 18 ms 18200 KB Output is correct
3 Correct 15 ms 18124 KB Output is correct
4 Correct 14 ms 18200 KB Output is correct
5 Correct 13 ms 17996 KB Output is correct
6 Correct 14 ms 18020 KB Output is correct
7 Correct 13 ms 18108 KB Output is correct
8 Correct 13 ms 18136 KB Output is correct
9 Correct 17 ms 18124 KB Output is correct
10 Correct 18 ms 18084 KB Output is correct
11 Correct 16 ms 18124 KB Output is correct
12 Correct 14 ms 18120 KB Output is correct
13 Correct 14 ms 18184 KB Output is correct
14 Correct 13 ms 18152 KB Output is correct
15 Correct 14 ms 18164 KB Output is correct
16 Correct 15 ms 18108 KB Output is correct
17 Correct 14 ms 18124 KB Output is correct
18 Correct 14 ms 18124 KB Output is correct
19 Correct 15 ms 18124 KB Output is correct
20 Correct 16 ms 18200 KB Output is correct
21 Correct 123 ms 25036 KB Output is correct
22 Correct 139 ms 25544 KB Output is correct
23 Correct 117 ms 24984 KB Output is correct
24 Correct 105 ms 25028 KB Output is correct
25 Correct 129 ms 25540 KB Output is correct
26 Correct 131 ms 25612 KB Output is correct
27 Correct 62 ms 21216 KB Output is correct
28 Correct 63 ms 21084 KB Output is correct
29 Correct 109 ms 24624 KB Output is correct
30 Correct 108 ms 25028 KB Output is correct
31 Correct 115 ms 24900 KB Output is correct
32 Correct 146 ms 25088 KB Output is correct
33 Correct 109 ms 25384 KB Output is correct
34 Correct 127 ms 25776 KB Output is correct
35 Correct 116 ms 26304 KB Output is correct
36 Correct 134 ms 26532 KB Output is correct
37 Correct 158 ms 24728 KB Output is correct
38 Correct 140 ms 24836 KB Output is correct
39 Correct 74 ms 21044 KB Output is correct
40 Correct 72 ms 21228 KB Output is correct
41 Correct 159 ms 24436 KB Output is correct
42 Correct 175 ms 25028 KB Output is correct
43 Correct 158 ms 25032 KB Output is correct
44 Correct 167 ms 24772 KB Output is correct
45 Correct 159 ms 25076 KB Output is correct
46 Correct 174 ms 25028 KB Output is correct
47 Correct 113 ms 24596 KB Output is correct
48 Correct 149 ms 24936 KB Output is correct
49 Correct 106 ms 24108 KB Output is correct
50 Correct 140 ms 24604 KB Output is correct
51 Correct 157 ms 25044 KB Output is correct
52 Correct 150 ms 25028 KB Output is correct
53 Correct 98 ms 25564 KB Output is correct
54 Correct 118 ms 26480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 124 ms 25540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 18124 KB Output is correct
2 Correct 18 ms 18200 KB Output is correct
3 Correct 15 ms 18124 KB Output is correct
4 Correct 14 ms 18200 KB Output is correct
5 Correct 13 ms 17996 KB Output is correct
6 Correct 14 ms 18020 KB Output is correct
7 Correct 13 ms 18108 KB Output is correct
8 Correct 13 ms 18136 KB Output is correct
9 Correct 17 ms 18124 KB Output is correct
10 Correct 18 ms 18084 KB Output is correct
11 Correct 16 ms 18124 KB Output is correct
12 Correct 14 ms 18120 KB Output is correct
13 Correct 14 ms 18184 KB Output is correct
14 Correct 13 ms 18152 KB Output is correct
15 Correct 14 ms 18164 KB Output is correct
16 Correct 15 ms 18108 KB Output is correct
17 Correct 14 ms 18124 KB Output is correct
18 Correct 14 ms 18124 KB Output is correct
19 Correct 15 ms 18124 KB Output is correct
20 Correct 16 ms 18200 KB Output is correct
21 Incorrect 13 ms 18108 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 18124 KB Output is correct
2 Correct 18 ms 18200 KB Output is correct
3 Correct 15 ms 18124 KB Output is correct
4 Correct 14 ms 18200 KB Output is correct
5 Correct 13 ms 17996 KB Output is correct
6 Correct 14 ms 18020 KB Output is correct
7 Correct 13 ms 18108 KB Output is correct
8 Correct 13 ms 18136 KB Output is correct
9 Correct 17 ms 18124 KB Output is correct
10 Correct 18 ms 18084 KB Output is correct
11 Correct 16 ms 18124 KB Output is correct
12 Correct 14 ms 18120 KB Output is correct
13 Correct 14 ms 18184 KB Output is correct
14 Correct 13 ms 18152 KB Output is correct
15 Correct 14 ms 18164 KB Output is correct
16 Correct 15 ms 18108 KB Output is correct
17 Correct 14 ms 18124 KB Output is correct
18 Correct 14 ms 18124 KB Output is correct
19 Correct 15 ms 18124 KB Output is correct
20 Correct 16 ms 18200 KB Output is correct
21 Incorrect 13 ms 18108 KB Output isn't correct
22 Halted 0 ms 0 KB -