답안 #540490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540490 2022-03-20T13:44:28 Z alvingogo 푸드 코트 (JOI21_foodcourt) C++14
68 / 100
1000 ms 123912 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define cd complex<double>
#define p_q priority_queue
#define int long long
using namespace std;
 
typedef pair<int,int> pii;
struct BIT{
	int n;
	vector<int> bt;
	void init(int nn){
		n=nn;
		bt.resize(n);
	}
	void update(int x,int y){
		x++;
		for(;x<=n;x+=(x&-x)){
			bt[x]+=y;
		}
	}
	int query(int x){
		x++;
		int ans=0;
		for(;x>0;x-=(x&-x)){
			ans+=bt[x];
		}
		return ans;
	}
};
struct qu{
	int t;
	int l,r,c,k;
	int ans=-1;
};
vector<qu> vq;
struct DS{
	struct no{
		vector<int> tag;
		int cnt=0;
	};
	vector<no> st;
	vector<int> kk;
	void init(int n){
		st.resize(4*n);
		kk.resize(n);
	}
	void upd(int v,int x){
		while(st[v].tag.size()){
			int y=st[v].tag.back();
			if(y<0 && x>0){
				break;
			}
			if(y>0 && x<0){
				st[v].cnt+=min(abs(y),abs(x));
				x+=y;
			}
			else{
				x+=y;
			}
			st[v].tag.pop_back();
		}
		if(x!=0){
			st[v].tag.push_back(x);
		}
	}
	void pudo(int v){
		st[2*v+1].cnt+=st[v].cnt;
		st[2*v+2].cnt+=st[v].cnt;
		for(auto y:st[v].tag){
			upd(2*v+1,y);
			upd(2*v+2,y);
		}
		st[v].cnt=0;
		st[v].tag.clear();
	}
	void update(int v,int L,int R,int l,int r,int k){
		if(l==L && r==R){
			upd(v,k);
			return;
		}
		pudo(v);
		int m=(L+R)/2;
		if(r<=m){
			update(2*v+1,L,m,l,r,k);
		}
		else if(l>m){
			update(2*v+2,m+1,R,l,r,k);
		}
		else{
			update(2*v+1,L,m,l,m,k);
			update(2*v+2,m+1,R,m+1,r,k);
		}
	}
	int query(int v,int L,int R,int pos){
		if(L==R){
			for(auto h:st[v].tag){
				if(h<0 && kk[L]>0){
					st[v].cnt+=min(abs(h),abs(kk[L]));
				}
				kk[L]+=h;
				kk[L]=max(kk[L],0ll);
			}
			st[v].tag.clear();
			return st[v].cnt;
		}
		pudo(v);
		int m=(L+R)/2;
		if(pos<=m){
			return query(2*v+1,L,m,pos);
		}
		else{
			return query(2*v+2,m+1,R,pos);
		}
	}
	void pre(int n){
		for(auto &h:vq){
			if(h.t==1){
				update(0,0,n-1,h.l,h.r,h.k);
			}
			else if(h.t==2){
				update(0,0,n-1,h.l,h.r,-h.k);
			}
			else{
				h.k+=query(0,0,n-1,h.c);
			}
		}
	}
};
struct Q13{
	struct upd{
		int t,u,k;
	};
	vector<vector<int> > qq;
	BIT bt;
	vector<vector<upd> > st;
	map<int,int> s;
	void init(int n,int q){
		bt.init(q+10);
		st.resize(4*n);
		qq.resize(n);
	}
	void update(int v,int L,int R,int l,int r,upd a){
		if(l==L && r==R){
			st[v].push_back(a);
			return;
		}
		int m=(L+R)/2;
		if(r<=m){
			update(2*v+1,L,m,l,r,a);
		}
		else if(l>m){
			update(2*v+2,m+1,R,l,r,a);
		}
		else{
			update(2*v+1,L,m,l,m,a);
			update(2*v+2,m+1,R,m+1,r,a);
		}
	}
	void trav(int v,int L,int R){
		for(auto h:st[v]){
			bt.update(h.t,h.k);
			s[h.t]=h.u;
		}
		if(L==R){
			for(auto h:qq[L]){
				int l=0,r=vq[h].l-1;
				while(r>l){
					int m=(l+r+1)/2;
					if(bt.query(m)<vq[h].k){
						l=m;
					}
					else{
						r=m-1;
					}
				}
				if(bt.query(l+1)<vq[h].k){
					vq[h].ans=0;
				}
				else{
					vq[h].ans=(*s.upper_bound(l)).sc;
				}
			}
		}
		else{
			int m=(L+R)/2;
			trav(2*v+1,L,m);
			trav(2*v+2,m+1,R);
		}
		for(auto h:st[v]){
			bt.update(h.t,-h.k);
			s.erase(h.t);
		}
	}
	void solve(int n,int q){
		for(int i=0;i<q;i++){
			if(vq[i].t==1){
				update(0,0,n-1,vq[i].l,vq[i].r,{i+1,vq[i].c,vq[i].k});
			}
			else if(vq[i].t==3){
				qq[vq[i].c].push_back(i);
			}
		}
		trav(0,0,n-1);
		for(int i=0;i<q;i++){
			if(vq[i].t==3){
				cout << vq[i].ans << "\n";
			}
		}
	}
};
signed main(){
	AquA;
	int n,m,q;
	cin >> n >> m >> q;
	vq.resize(q);
	for(int i=0;i<q;i++){
		cin >> vq[i].t;
		if(vq[i].t==1){
			cin >> vq[i].l >> vq[i].r >> vq[i].c >> vq[i].k;
			vq[i].l--;
			vq[i].r--;
		}
		else if(vq[i].t==2){
			cin >> vq[i].l >> vq[i].r >> vq[i].k;
			vq[i].l--;
			vq[i].r--;
		}
		else{
			cin >> vq[i].c >> vq[i].k;
			vq[i].c--;
			vq[i].l=i;
		}
	}
	DS ds;
	ds.init(n);
	ds.pre(n);
	Q13 ss;
	ss.init(n,q);
	ss.solve(n,q);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 980 KB Output is correct
2 Correct 6 ms 1212 KB Output is correct
3 Correct 6 ms 1228 KB Output is correct
4 Correct 7 ms 1484 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 5 ms 1364 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 6 ms 1352 KB Output is correct
10 Correct 6 ms 1360 KB Output is correct
11 Correct 8 ms 1400 KB Output is correct
12 Correct 6 ms 1364 KB Output is correct
13 Correct 3 ms 972 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 5 ms 1236 KB Output is correct
16 Correct 6 ms 1352 KB Output is correct
17 Correct 7 ms 1096 KB Output is correct
18 Correct 7 ms 1384 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 5 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 980 KB Output is correct
2 Correct 6 ms 1212 KB Output is correct
3 Correct 6 ms 1228 KB Output is correct
4 Correct 7 ms 1484 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 5 ms 1364 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 6 ms 1352 KB Output is correct
10 Correct 6 ms 1360 KB Output is correct
11 Correct 8 ms 1400 KB Output is correct
12 Correct 6 ms 1364 KB Output is correct
13 Correct 3 ms 972 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 5 ms 1236 KB Output is correct
16 Correct 6 ms 1352 KB Output is correct
17 Correct 7 ms 1096 KB Output is correct
18 Correct 7 ms 1384 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 5 ms 1236 KB Output is correct
21 Correct 6 ms 1184 KB Output is correct
22 Correct 6 ms 1228 KB Output is correct
23 Correct 6 ms 1236 KB Output is correct
24 Correct 10 ms 1492 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 11 ms 1364 KB Output is correct
28 Correct 7 ms 1360 KB Output is correct
29 Correct 6 ms 1360 KB Output is correct
30 Correct 6 ms 1420 KB Output is correct
31 Correct 6 ms 1356 KB Output is correct
32 Correct 7 ms 1364 KB Output is correct
33 Correct 2 ms 980 KB Output is correct
34 Correct 3 ms 1096 KB Output is correct
35 Correct 6 ms 1232 KB Output is correct
36 Correct 6 ms 1352 KB Output is correct
37 Correct 4 ms 980 KB Output is correct
38 Correct 4 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 26280 KB Output is correct
2 Correct 134 ms 27096 KB Output is correct
3 Correct 142 ms 26960 KB Output is correct
4 Correct 139 ms 26936 KB Output is correct
5 Correct 154 ms 29316 KB Output is correct
6 Correct 161 ms 29400 KB Output is correct
7 Correct 35 ms 6324 KB Output is correct
8 Correct 35 ms 6328 KB Output is correct
9 Correct 130 ms 27624 KB Output is correct
10 Correct 133 ms 27560 KB Output is correct
11 Correct 134 ms 27664 KB Output is correct
12 Correct 131 ms 27724 KB Output is correct
13 Correct 126 ms 21676 KB Output is correct
14 Correct 136 ms 28832 KB Output is correct
15 Correct 151 ms 24068 KB Output is correct
16 Correct 138 ms 30108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 123912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 980 KB Output is correct
2 Correct 6 ms 1212 KB Output is correct
3 Correct 6 ms 1228 KB Output is correct
4 Correct 7 ms 1484 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 5 ms 1364 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 6 ms 1352 KB Output is correct
10 Correct 6 ms 1360 KB Output is correct
11 Correct 8 ms 1400 KB Output is correct
12 Correct 6 ms 1364 KB Output is correct
13 Correct 3 ms 972 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 5 ms 1236 KB Output is correct
16 Correct 6 ms 1352 KB Output is correct
17 Correct 7 ms 1096 KB Output is correct
18 Correct 7 ms 1384 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 5 ms 1236 KB Output is correct
21 Correct 124 ms 26280 KB Output is correct
22 Correct 134 ms 27096 KB Output is correct
23 Correct 142 ms 26960 KB Output is correct
24 Correct 139 ms 26936 KB Output is correct
25 Correct 154 ms 29316 KB Output is correct
26 Correct 161 ms 29400 KB Output is correct
27 Correct 35 ms 6324 KB Output is correct
28 Correct 35 ms 6328 KB Output is correct
29 Correct 130 ms 27624 KB Output is correct
30 Correct 133 ms 27560 KB Output is correct
31 Correct 134 ms 27664 KB Output is correct
32 Correct 131 ms 27724 KB Output is correct
33 Correct 126 ms 21676 KB Output is correct
34 Correct 136 ms 28832 KB Output is correct
35 Correct 151 ms 24068 KB Output is correct
36 Correct 138 ms 30108 KB Output is correct
37 Correct 263 ms 32252 KB Output is correct
38 Correct 267 ms 35644 KB Output is correct
39 Correct 27 ms 5548 KB Output is correct
40 Correct 41 ms 6024 KB Output is correct
41 Correct 275 ms 37764 KB Output is correct
42 Correct 301 ms 37948 KB Output is correct
43 Correct 332 ms 37720 KB Output is correct
44 Correct 332 ms 37752 KB Output is correct
45 Correct 313 ms 37844 KB Output is correct
46 Correct 311 ms 37780 KB Output is correct
47 Correct 81 ms 26324 KB Output is correct
48 Correct 244 ms 38548 KB Output is correct
49 Correct 193 ms 26592 KB Output is correct
50 Correct 250 ms 34908 KB Output is correct
51 Correct 296 ms 37980 KB Output is correct
52 Correct 298 ms 37968 KB Output is correct
53 Correct 118 ms 25484 KB Output is correct
54 Correct 150 ms 30156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 302 ms 37184 KB Output is correct
2 Correct 327 ms 36252 KB Output is correct
3 Correct 322 ms 39904 KB Output is correct
4 Correct 257 ms 33812 KB Output is correct
5 Correct 283 ms 37648 KB Output is correct
6 Correct 337 ms 41248 KB Output is correct
7 Correct 43 ms 6308 KB Output is correct
8 Correct 36 ms 5460 KB Output is correct
9 Correct 90 ms 27036 KB Output is correct
10 Correct 189 ms 33808 KB Output is correct
11 Correct 282 ms 43920 KB Output is correct
12 Correct 275 ms 43844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 980 KB Output is correct
2 Correct 6 ms 1212 KB Output is correct
3 Correct 6 ms 1228 KB Output is correct
4 Correct 7 ms 1484 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 5 ms 1364 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 6 ms 1352 KB Output is correct
10 Correct 6 ms 1360 KB Output is correct
11 Correct 8 ms 1400 KB Output is correct
12 Correct 6 ms 1364 KB Output is correct
13 Correct 3 ms 972 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 5 ms 1236 KB Output is correct
16 Correct 6 ms 1352 KB Output is correct
17 Correct 7 ms 1096 KB Output is correct
18 Correct 7 ms 1384 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 5 ms 1236 KB Output is correct
21 Correct 6 ms 1184 KB Output is correct
22 Correct 6 ms 1228 KB Output is correct
23 Correct 6 ms 1236 KB Output is correct
24 Correct 10 ms 1492 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 11 ms 1364 KB Output is correct
28 Correct 7 ms 1360 KB Output is correct
29 Correct 6 ms 1360 KB Output is correct
30 Correct 6 ms 1420 KB Output is correct
31 Correct 6 ms 1356 KB Output is correct
32 Correct 7 ms 1364 KB Output is correct
33 Correct 2 ms 980 KB Output is correct
34 Correct 3 ms 1096 KB Output is correct
35 Correct 6 ms 1232 KB Output is correct
36 Correct 6 ms 1352 KB Output is correct
37 Correct 4 ms 980 KB Output is correct
38 Correct 4 ms 1228 KB Output is correct
39 Correct 124 ms 26280 KB Output is correct
40 Correct 134 ms 27096 KB Output is correct
41 Correct 142 ms 26960 KB Output is correct
42 Correct 139 ms 26936 KB Output is correct
43 Correct 154 ms 29316 KB Output is correct
44 Correct 161 ms 29400 KB Output is correct
45 Correct 35 ms 6324 KB Output is correct
46 Correct 35 ms 6328 KB Output is correct
47 Correct 130 ms 27624 KB Output is correct
48 Correct 133 ms 27560 KB Output is correct
49 Correct 134 ms 27664 KB Output is correct
50 Correct 131 ms 27724 KB Output is correct
51 Correct 126 ms 21676 KB Output is correct
52 Correct 136 ms 28832 KB Output is correct
53 Correct 151 ms 24068 KB Output is correct
54 Correct 138 ms 30108 KB Output is correct
55 Correct 263 ms 32252 KB Output is correct
56 Correct 267 ms 35644 KB Output is correct
57 Correct 27 ms 5548 KB Output is correct
58 Correct 41 ms 6024 KB Output is correct
59 Correct 275 ms 37764 KB Output is correct
60 Correct 301 ms 37948 KB Output is correct
61 Correct 332 ms 37720 KB Output is correct
62 Correct 332 ms 37752 KB Output is correct
63 Correct 313 ms 37844 KB Output is correct
64 Correct 311 ms 37780 KB Output is correct
65 Correct 81 ms 26324 KB Output is correct
66 Correct 244 ms 38548 KB Output is correct
67 Correct 193 ms 26592 KB Output is correct
68 Correct 250 ms 34908 KB Output is correct
69 Correct 296 ms 37980 KB Output is correct
70 Correct 298 ms 37968 KB Output is correct
71 Correct 118 ms 25484 KB Output is correct
72 Correct 150 ms 30156 KB Output is correct
73 Correct 302 ms 37184 KB Output is correct
74 Correct 327 ms 36252 KB Output is correct
75 Correct 322 ms 39904 KB Output is correct
76 Correct 257 ms 33812 KB Output is correct
77 Correct 283 ms 37648 KB Output is correct
78 Correct 337 ms 41248 KB Output is correct
79 Correct 43 ms 6308 KB Output is correct
80 Correct 36 ms 5460 KB Output is correct
81 Correct 90 ms 27036 KB Output is correct
82 Correct 189 ms 33808 KB Output is correct
83 Correct 282 ms 43920 KB Output is correct
84 Correct 275 ms 43844 KB Output is correct
85 Correct 254 ms 30488 KB Output is correct
86 Correct 259 ms 36512 KB Output is correct
87 Correct 306 ms 38320 KB Output is correct
88 Correct 337 ms 42456 KB Output is correct
89 Correct 164 ms 28084 KB Output is correct
90 Correct 268 ms 38424 KB Output is correct
91 Correct 214 ms 28432 KB Output is correct
92 Correct 199 ms 27820 KB Output is correct
93 Correct 281 ms 38292 KB Output is correct
94 Correct 264 ms 38392 KB Output is correct
95 Correct 261 ms 36092 KB Output is correct
96 Correct 275 ms 38420 KB Output is correct
97 Correct 272 ms 38424 KB Output is correct
98 Correct 231 ms 29932 KB Output is correct
99 Correct 83 ms 26844 KB Output is correct
100 Correct 191 ms 32456 KB Output is correct
101 Correct 233 ms 38972 KB Output is correct
102 Correct 166 ms 32780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 980 KB Output is correct
2 Correct 6 ms 1212 KB Output is correct
3 Correct 6 ms 1228 KB Output is correct
4 Correct 7 ms 1484 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 5 ms 1364 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 6 ms 1352 KB Output is correct
10 Correct 6 ms 1360 KB Output is correct
11 Correct 8 ms 1400 KB Output is correct
12 Correct 6 ms 1364 KB Output is correct
13 Correct 3 ms 972 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 5 ms 1236 KB Output is correct
16 Correct 6 ms 1352 KB Output is correct
17 Correct 7 ms 1096 KB Output is correct
18 Correct 7 ms 1384 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 5 ms 1236 KB Output is correct
21 Correct 6 ms 1184 KB Output is correct
22 Correct 6 ms 1228 KB Output is correct
23 Correct 6 ms 1236 KB Output is correct
24 Correct 10 ms 1492 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 11 ms 1364 KB Output is correct
28 Correct 7 ms 1360 KB Output is correct
29 Correct 6 ms 1360 KB Output is correct
30 Correct 6 ms 1420 KB Output is correct
31 Correct 6 ms 1356 KB Output is correct
32 Correct 7 ms 1364 KB Output is correct
33 Correct 2 ms 980 KB Output is correct
34 Correct 3 ms 1096 KB Output is correct
35 Correct 6 ms 1232 KB Output is correct
36 Correct 6 ms 1352 KB Output is correct
37 Correct 4 ms 980 KB Output is correct
38 Correct 4 ms 1228 KB Output is correct
39 Correct 124 ms 26280 KB Output is correct
40 Correct 134 ms 27096 KB Output is correct
41 Correct 142 ms 26960 KB Output is correct
42 Correct 139 ms 26936 KB Output is correct
43 Correct 154 ms 29316 KB Output is correct
44 Correct 161 ms 29400 KB Output is correct
45 Correct 35 ms 6324 KB Output is correct
46 Correct 35 ms 6328 KB Output is correct
47 Correct 130 ms 27624 KB Output is correct
48 Correct 133 ms 27560 KB Output is correct
49 Correct 134 ms 27664 KB Output is correct
50 Correct 131 ms 27724 KB Output is correct
51 Correct 126 ms 21676 KB Output is correct
52 Correct 136 ms 28832 KB Output is correct
53 Correct 151 ms 24068 KB Output is correct
54 Correct 138 ms 30108 KB Output is correct
55 Execution timed out 1090 ms 123912 KB Time limit exceeded
56 Halted 0 ms 0 KB -