답안 #1089095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089095 2024-09-16T04:48:06 Z coldbr3w 푸드 코트 (JOI21_foodcourt) C++17
14 / 100
1000 ms 87340 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second  
#define all(x) (x).begin(), (x).end()

const ll N = 3e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll blocks = 350;
ll n,m,q;
vector<pll>t[N], ask[N];
ll g[N], res[N], add[N], ok[N];
struct segment_tree_min{
    ll n;
    vector<pll>st;
	vector<ll> lz;
    void init(ll _n){
        n = _n;
        st.clear(); st.resize(4 * n + 10);
        lz.clear(); lz.resize(4 * n + 10, 0);
		build(1,1,n);
    }
	void build(ll id, ll l, ll r){
		if(l == r){
			st[id] = {0, l};
			return;
		}
		ll mid = (l + r) / 2;
		build(2 * id, l, mid); build(2 * id + 1, mid + 1, r);
		st[id] = min(st[2 * id], st[2 * id + 1]);
	}
    void down(ll id, ll l, ll r){
        st[id].F += lz[id];
        if(l != r) lz[2 * id] += lz[id], lz[2 * id + 1] += lz[id];
        lz[id] = 0;
    }
    void update(ll id, ll l, ll r, ll left, ll right, ll val){
        down(id, l, r);
        if(l > right || r < left) return;
        if(left <= l && r <= right){
            lz[id] += val;
            down(id, l, r);
            return;
        }
        ll mid = (l + r) / 2;
        update(2 * id, l, mid, left, right, val);
        update(2 * id + 1, mid + 1, r, left, right, val);
        st[id] = min(st[2 * id], st[2 * id + 1]);
    }
    pll get(ll id, ll l, ll r, ll left, ll right){
        down(id, l, r);
        if(l > right || r < left) return {inf, inf};
        if(left <= l && r <= right) return st[id];
        ll mid = (l + r) / 2;
        return min(get(2 * id, l, mid, left, right), get(2 * id + 1, mid + 1, r, left, right));
    }
    void update(ll l, ll r, ll val){update(1,1,n,l,r,val);}
    pll get(ll l, ll r){return get(1,1,n,l,r);}
} stmin;
struct segment_tree_sum{
	ll n;
    vector<ll>st, lz;
    void init(ll _n){
        n = _n;
        st.clear(); st.resize(4 * n + 10, 0);
        lz.clear(); lz.resize(4 * n + 10, 0);
    }
    void down(ll id, ll l, ll r){
        st[id] += lz[id] * (r - l + 1);
		ll mid = (l + r) / 2;
        if(l != r) lz[2 * id] += lz[id], lz[2 * id + 1] += lz[id];
        lz[id] = 0;
    }
    void update(ll id, ll l, ll r, ll left, ll right, ll val){
        down(id, l, r);
        if(l > right || r < left) return;
        if(left <= l && r <= right){
            lz[id] += val;
            down(id, l, r);
            return;
        }
        ll mid = (l + r) / 2;
        update(2 * id, l, mid, left, right, val);
        update(2 * id + 1, mid + 1, r, left, right, val);
        st[id] = st[2 * id] + st[2 * id + 1];
    }
    ll get(ll id, ll l, ll r, ll left, ll right){
        down(id, l, r);
        if(l > right || r < left) return 0;
        if(left <= l && r <= right) return st[id];
        ll mid = (l + r) / 2;
        return get(2 * id, l, mid, left, right) + get(2 * id + 1, mid + 1, r, left, right);
    }
	ll walk(ll id, ll l, ll r, ll pos, ll val){
		down(id, l, r);
		if(r < pos || st[id] < val) return -1;
		if(l == r) return l;
		ll mid = (l + r) / 2;
		ll res = -1;
		down(2 * id, l, mid); down(2 * id + 1, mid + 1, r);
		if(st[2 * id]) res = walk(2 * id, l, mid, pos, val);
		if(res == -1) res = walk(2 * id + 1, mid + 1, r, pos, val);
		return res;
	}
	ll walk(ll pos, ll val){return walk(1,1,n,pos,val);}
    void update(ll l, ll r, ll val){update(1,1,n,l,r,val);}
    ll get(ll l, ll r){return get(1,1,n,l,r);}
} st1, st2;
void to_thic_cau(){
	cin >> n >> m >> q;
	st1.init(q); st2.init(q); stmin.init(q);
	for(int i = 1; i <= q;i++){
		ll typ; cin >> typ;
		if(typ == 1){
			ll l,r,c,k; cin >> l >> r >> c >> k;
			g[i] = c; add[i] = 1;
			t[l].pb({i, k}); t[r + 1].pb({i, -k});
		}
		else if(typ == 2){
			ll l,r,k; cin >> l >> r >> k;
			t[l].pb({i, -k}); t[r+1].pb({i, k});
		}
		else{
			ok[i] = 1;
			ll a,b; cin >> a >> b;
			ask[a].pb({b, i});
		}
	}	
	for(int i = 1; i <= n;i++){
		for(auto x : t[i]){
			ll j = x.F, k = x.S;
			stmin.update(j, q, k);
			if(add[j]) st1.update(j, q, k); 
			else st2.update(j, q, -k);
		}
		for(auto x : ask[i]){
			ll v = x.F, j = x.S;
			pll cur = min(make_pair(0ll,0ll), stmin.get(1, j));
			if(stmin.get(j, j).F < cur.F + v) continue;
			v += st2.get(j, j) + cur.F;
			res[j] = g[st1.walk(cur.S + 1, v)];	
		}
	}
	for(int i = 1; i <= q;i++) if(ok[i]) cout << res[i] << " ";
	cout << '\n';
}

signed main()   
{ 
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll tc = 1;
	//cin >> tc;
	while(tc--) to_thic_cau();
}

Compilation message

foodcourt.cpp: In member function 'void segment_tree_sum::down(long long int, long long int, long long int)':
foodcourt.cpp:75:6: warning: unused variable 'mid' [-Wunused-variable]
   75 |   ll mid = (l + r) / 2;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14936 KB Output is correct
2 Correct 10 ms 15196 KB Output is correct
3 Correct 9 ms 14940 KB Output is correct
4 Correct 9 ms 15084 KB Output is correct
5 Correct 9 ms 14940 KB Output is correct
6 Correct 8 ms 14940 KB Output is correct
7 Correct 9 ms 15196 KB Output is correct
8 Correct 11 ms 15156 KB Output is correct
9 Correct 9 ms 15196 KB Output is correct
10 Correct 10 ms 15196 KB Output is correct
11 Correct 10 ms 15196 KB Output is correct
12 Correct 10 ms 15196 KB Output is correct
13 Correct 8 ms 14940 KB Output is correct
14 Correct 10 ms 15236 KB Output is correct
15 Correct 8 ms 14940 KB Output is correct
16 Correct 10 ms 15140 KB Output is correct
17 Correct 8 ms 14940 KB Output is correct
18 Correct 9 ms 15196 KB Output is correct
19 Correct 9 ms 15088 KB Output is correct
20 Correct 8 ms 15196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14936 KB Output is correct
2 Correct 10 ms 15196 KB Output is correct
3 Correct 9 ms 14940 KB Output is correct
4 Correct 9 ms 15084 KB Output is correct
5 Correct 9 ms 14940 KB Output is correct
6 Correct 8 ms 14940 KB Output is correct
7 Correct 9 ms 15196 KB Output is correct
8 Correct 11 ms 15156 KB Output is correct
9 Correct 9 ms 15196 KB Output is correct
10 Correct 10 ms 15196 KB Output is correct
11 Correct 10 ms 15196 KB Output is correct
12 Correct 10 ms 15196 KB Output is correct
13 Correct 8 ms 14940 KB Output is correct
14 Correct 10 ms 15236 KB Output is correct
15 Correct 8 ms 14940 KB Output is correct
16 Correct 10 ms 15140 KB Output is correct
17 Correct 8 ms 14940 KB Output is correct
18 Correct 9 ms 15196 KB Output is correct
19 Correct 9 ms 15088 KB Output is correct
20 Correct 8 ms 15196 KB Output is correct
21 Correct 9 ms 15196 KB Output is correct
22 Correct 10 ms 15196 KB Output is correct
23 Correct 9 ms 15196 KB Output is correct
24 Correct 9 ms 15100 KB Output is correct
25 Correct 8 ms 14936 KB Output is correct
26 Correct 9 ms 14940 KB Output is correct
27 Correct 9 ms 15128 KB Output is correct
28 Correct 10 ms 15192 KB Output is correct
29 Correct 10 ms 15196 KB Output is correct
30 Correct 9 ms 15164 KB Output is correct
31 Correct 10 ms 15088 KB Output is correct
32 Correct 9 ms 15192 KB Output is correct
33 Correct 8 ms 15192 KB Output is correct
34 Correct 10 ms 15196 KB Output is correct
35 Correct 9 ms 14940 KB Output is correct
36 Correct 8 ms 15196 KB Output is correct
37 Correct 8 ms 14940 KB Output is correct
38 Correct 9 ms 15192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 34616 KB Output is correct
2 Correct 103 ms 34644 KB Output is correct
3 Correct 95 ms 34784 KB Output is correct
4 Correct 90 ms 34384 KB Output is correct
5 Correct 97 ms 34644 KB Output is correct
6 Correct 95 ms 34600 KB Output is correct
7 Correct 52 ms 32280 KB Output is correct
8 Correct 56 ms 32700 KB Output is correct
9 Correct 95 ms 34368 KB Output is correct
10 Correct 93 ms 34640 KB Output is correct
11 Correct 105 ms 34384 KB Output is correct
12 Correct 100 ms 34684 KB Output is correct
13 Correct 81 ms 32596 KB Output is correct
14 Correct 88 ms 34900 KB Output is correct
15 Correct 102 ms 34888 KB Output is correct
16 Correct 117 ms 35012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 87340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14936 KB Output is correct
2 Correct 10 ms 15196 KB Output is correct
3 Correct 9 ms 14940 KB Output is correct
4 Correct 9 ms 15084 KB Output is correct
5 Correct 9 ms 14940 KB Output is correct
6 Correct 8 ms 14940 KB Output is correct
7 Correct 9 ms 15196 KB Output is correct
8 Correct 11 ms 15156 KB Output is correct
9 Correct 9 ms 15196 KB Output is correct
10 Correct 10 ms 15196 KB Output is correct
11 Correct 10 ms 15196 KB Output is correct
12 Correct 10 ms 15196 KB Output is correct
13 Correct 8 ms 14940 KB Output is correct
14 Correct 10 ms 15236 KB Output is correct
15 Correct 8 ms 14940 KB Output is correct
16 Correct 10 ms 15140 KB Output is correct
17 Correct 8 ms 14940 KB Output is correct
18 Correct 9 ms 15196 KB Output is correct
19 Correct 9 ms 15088 KB Output is correct
20 Correct 8 ms 15196 KB Output is correct
21 Correct 101 ms 34616 KB Output is correct
22 Correct 103 ms 34644 KB Output is correct
23 Correct 95 ms 34784 KB Output is correct
24 Correct 90 ms 34384 KB Output is correct
25 Correct 97 ms 34644 KB Output is correct
26 Correct 95 ms 34600 KB Output is correct
27 Correct 52 ms 32280 KB Output is correct
28 Correct 56 ms 32700 KB Output is correct
29 Correct 95 ms 34368 KB Output is correct
30 Correct 93 ms 34640 KB Output is correct
31 Correct 105 ms 34384 KB Output is correct
32 Correct 100 ms 34684 KB Output is correct
33 Correct 81 ms 32596 KB Output is correct
34 Correct 88 ms 34900 KB Output is correct
35 Correct 102 ms 34888 KB Output is correct
36 Correct 117 ms 35012 KB Output is correct
37 Execution timed out 1036 ms 32528 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1056 ms 32744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14936 KB Output is correct
2 Correct 10 ms 15196 KB Output is correct
3 Correct 9 ms 14940 KB Output is correct
4 Correct 9 ms 15084 KB Output is correct
5 Correct 9 ms 14940 KB Output is correct
6 Correct 8 ms 14940 KB Output is correct
7 Correct 9 ms 15196 KB Output is correct
8 Correct 11 ms 15156 KB Output is correct
9 Correct 9 ms 15196 KB Output is correct
10 Correct 10 ms 15196 KB Output is correct
11 Correct 10 ms 15196 KB Output is correct
12 Correct 10 ms 15196 KB Output is correct
13 Correct 8 ms 14940 KB Output is correct
14 Correct 10 ms 15236 KB Output is correct
15 Correct 8 ms 14940 KB Output is correct
16 Correct 10 ms 15140 KB Output is correct
17 Correct 8 ms 14940 KB Output is correct
18 Correct 9 ms 15196 KB Output is correct
19 Correct 9 ms 15088 KB Output is correct
20 Correct 8 ms 15196 KB Output is correct
21 Correct 9 ms 15196 KB Output is correct
22 Correct 10 ms 15196 KB Output is correct
23 Correct 9 ms 15196 KB Output is correct
24 Correct 9 ms 15100 KB Output is correct
25 Correct 8 ms 14936 KB Output is correct
26 Correct 9 ms 14940 KB Output is correct
27 Correct 9 ms 15128 KB Output is correct
28 Correct 10 ms 15192 KB Output is correct
29 Correct 10 ms 15196 KB Output is correct
30 Correct 9 ms 15164 KB Output is correct
31 Correct 10 ms 15088 KB Output is correct
32 Correct 9 ms 15192 KB Output is correct
33 Correct 8 ms 15192 KB Output is correct
34 Correct 10 ms 15196 KB Output is correct
35 Correct 9 ms 14940 KB Output is correct
36 Correct 8 ms 15196 KB Output is correct
37 Correct 8 ms 14940 KB Output is correct
38 Correct 9 ms 15192 KB Output is correct
39 Correct 101 ms 34616 KB Output is correct
40 Correct 103 ms 34644 KB Output is correct
41 Correct 95 ms 34784 KB Output is correct
42 Correct 90 ms 34384 KB Output is correct
43 Correct 97 ms 34644 KB Output is correct
44 Correct 95 ms 34600 KB Output is correct
45 Correct 52 ms 32280 KB Output is correct
46 Correct 56 ms 32700 KB Output is correct
47 Correct 95 ms 34368 KB Output is correct
48 Correct 93 ms 34640 KB Output is correct
49 Correct 105 ms 34384 KB Output is correct
50 Correct 100 ms 34684 KB Output is correct
51 Correct 81 ms 32596 KB Output is correct
52 Correct 88 ms 34900 KB Output is correct
53 Correct 102 ms 34888 KB Output is correct
54 Correct 117 ms 35012 KB Output is correct
55 Execution timed out 1036 ms 32528 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14936 KB Output is correct
2 Correct 10 ms 15196 KB Output is correct
3 Correct 9 ms 14940 KB Output is correct
4 Correct 9 ms 15084 KB Output is correct
5 Correct 9 ms 14940 KB Output is correct
6 Correct 8 ms 14940 KB Output is correct
7 Correct 9 ms 15196 KB Output is correct
8 Correct 11 ms 15156 KB Output is correct
9 Correct 9 ms 15196 KB Output is correct
10 Correct 10 ms 15196 KB Output is correct
11 Correct 10 ms 15196 KB Output is correct
12 Correct 10 ms 15196 KB Output is correct
13 Correct 8 ms 14940 KB Output is correct
14 Correct 10 ms 15236 KB Output is correct
15 Correct 8 ms 14940 KB Output is correct
16 Correct 10 ms 15140 KB Output is correct
17 Correct 8 ms 14940 KB Output is correct
18 Correct 9 ms 15196 KB Output is correct
19 Correct 9 ms 15088 KB Output is correct
20 Correct 8 ms 15196 KB Output is correct
21 Correct 9 ms 15196 KB Output is correct
22 Correct 10 ms 15196 KB Output is correct
23 Correct 9 ms 15196 KB Output is correct
24 Correct 9 ms 15100 KB Output is correct
25 Correct 8 ms 14936 KB Output is correct
26 Correct 9 ms 14940 KB Output is correct
27 Correct 9 ms 15128 KB Output is correct
28 Correct 10 ms 15192 KB Output is correct
29 Correct 10 ms 15196 KB Output is correct
30 Correct 9 ms 15164 KB Output is correct
31 Correct 10 ms 15088 KB Output is correct
32 Correct 9 ms 15192 KB Output is correct
33 Correct 8 ms 15192 KB Output is correct
34 Correct 10 ms 15196 KB Output is correct
35 Correct 9 ms 14940 KB Output is correct
36 Correct 8 ms 15196 KB Output is correct
37 Correct 8 ms 14940 KB Output is correct
38 Correct 9 ms 15192 KB Output is correct
39 Correct 101 ms 34616 KB Output is correct
40 Correct 103 ms 34644 KB Output is correct
41 Correct 95 ms 34784 KB Output is correct
42 Correct 90 ms 34384 KB Output is correct
43 Correct 97 ms 34644 KB Output is correct
44 Correct 95 ms 34600 KB Output is correct
45 Correct 52 ms 32280 KB Output is correct
46 Correct 56 ms 32700 KB Output is correct
47 Correct 95 ms 34368 KB Output is correct
48 Correct 93 ms 34640 KB Output is correct
49 Correct 105 ms 34384 KB Output is correct
50 Correct 100 ms 34684 KB Output is correct
51 Correct 81 ms 32596 KB Output is correct
52 Correct 88 ms 34900 KB Output is correct
53 Correct 102 ms 34888 KB Output is correct
54 Correct 117 ms 35012 KB Output is correct
55 Execution timed out 1081 ms 87340 KB Time limit exceeded
56 Halted 0 ms 0 KB -