Submission #1089124

# Submission time Handle Problem Language Result Execution time Memory
1089124 2024-09-16T05:28:38 Z coldbr3w Food Court (JOI21_foodcourt) C++17
35 / 100
1000 ms 89608 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,popcnt,lzcnt")
#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;
int n,m,q;
vector<pll>t[N], ask[N];
int g[N], res[N];
bool add[N], ok[N];
struct segment_tree_min{
    ll n;
    vector<pair<ll,ll>>st;
	vector<ll> lz;
    void init(int _n){
        n = _n;
        st.clear(); st.resize(4 * n + 10);
        lz.clear(); lz.resize(4 * n + 10, 0);
		build(1,1,n);
    }
	void build(int id, int l, int r){
		if(l == r){
			st[id] = {0, l};
			return;
		}
		int 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(int id, int l, int 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(int id, int l, int r, int left, int 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;
        }
        int 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]);
    }
    pair<ll,ll> get(int id, int l, int r, int left, int right){
        down(id, l, r);
        if(l > right || r < left) return {inf, 0};
        if(left <= l && r <= right) return st[id];
        int 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(int _n){
        n = _n;
        st.clear(); st.resize(4 * n + 10, 0);
        lz.clear(); lz.resize(4 * n + 10, 0);
    }
    void down(int id, ll l, ll r){
        st[id] += lz[id] * (r - l + 1);
        if(l != r) lz[2 * id] += lz[id], lz[2 * id + 1] += lz[id];
        lz[id] = 0;
    }
    void update(int id, int l, int r, int left, int 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;
        }
        int 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(int id, int l, int r, int left, int right){
        down(id, l, r);
        if(l > right || r < left) return 0;
        if(left <= l && r <= right) return st[id];
        int mid = (l + r) / 2;
        return get(2 * id, l, mid, left, right) + get(2 * id + 1, mid + 1, r, left, right);
    }
	int walk(int id, int l, int r, int pos, ll val){
		down(id, l, r);
		if(r < pos || st[id] < val) return -1;
		if(l == r) return l;
		int mid = (l + r) / 2;
		int res = walk(2 * id, l, mid, pos, val);
		if(res == -1) res = walk(2 * id + 1, mid + 1, r, pos, val);
		return res;
	}
	int walk(int pos, ll val){return walk(1,1,n,pos,val);}
    void update(int l, int r, ll val){update(1,1,n,l,r,val);}
    ll get(int l, int 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++){
		int typ; cin >> typ;
		if(typ == 1){
			int l,r,c; ll 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){
			int l,r; ll 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]){
			int j = x.F; ll 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;
			pair<ll,int> cur = min(make_pair(0ll,0ll), stmin.get(1, j));
			if(stmin.get(j, j).F < cur.F + v) continue;
			if(m == 1){
				res[j] = 1;
				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();
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14940 KB Output is correct
2 Correct 10 ms 15124 KB Output is correct
3 Correct 8 ms 14860 KB Output is correct
4 Correct 9 ms 14948 KB Output is correct
5 Correct 8 ms 14940 KB Output is correct
6 Correct 8 ms 14936 KB Output is correct
7 Correct 9 ms 15112 KB Output is correct
8 Correct 12 ms 15016 KB Output is correct
9 Correct 10 ms 15112 KB Output is correct
10 Correct 9 ms 14996 KB Output is correct
11 Correct 9 ms 15124 KB Output is correct
12 Correct 9 ms 14936 KB Output is correct
13 Correct 8 ms 14940 KB Output is correct
14 Correct 10 ms 15156 KB Output is correct
15 Correct 8 ms 14940 KB Output is correct
16 Correct 12 ms 15140 KB Output is correct
17 Correct 9 ms 15028 KB Output is correct
18 Correct 11 ms 14988 KB Output is correct
19 Correct 12 ms 15048 KB Output is correct
20 Correct 11 ms 15132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14940 KB Output is correct
2 Correct 10 ms 15124 KB Output is correct
3 Correct 8 ms 14860 KB Output is correct
4 Correct 9 ms 14948 KB Output is correct
5 Correct 8 ms 14940 KB Output is correct
6 Correct 8 ms 14936 KB Output is correct
7 Correct 9 ms 15112 KB Output is correct
8 Correct 12 ms 15016 KB Output is correct
9 Correct 10 ms 15112 KB Output is correct
10 Correct 9 ms 14996 KB Output is correct
11 Correct 9 ms 15124 KB Output is correct
12 Correct 9 ms 14936 KB Output is correct
13 Correct 8 ms 14940 KB Output is correct
14 Correct 10 ms 15156 KB Output is correct
15 Correct 8 ms 14940 KB Output is correct
16 Correct 12 ms 15140 KB Output is correct
17 Correct 9 ms 15028 KB Output is correct
18 Correct 11 ms 14988 KB Output is correct
19 Correct 12 ms 15048 KB Output is correct
20 Correct 11 ms 15132 KB Output is correct
21 Correct 10 ms 14940 KB Output is correct
22 Correct 15 ms 14940 KB Output is correct
23 Correct 13 ms 14940 KB Output is correct
24 Correct 11 ms 14940 KB Output is correct
25 Correct 9 ms 14928 KB Output is correct
26 Correct 9 ms 14940 KB Output is correct
27 Correct 10 ms 14940 KB Output is correct
28 Correct 14 ms 14936 KB Output is correct
29 Correct 10 ms 14940 KB Output is correct
30 Correct 11 ms 14940 KB Output is correct
31 Correct 10 ms 15040 KB Output is correct
32 Correct 9 ms 14940 KB Output is correct
33 Correct 9 ms 14936 KB Output is correct
34 Correct 10 ms 14940 KB Output is correct
35 Correct 10 ms 14936 KB Output is correct
36 Correct 10 ms 15196 KB Output is correct
37 Correct 8 ms 14940 KB Output is correct
38 Correct 9 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 32100 KB Output is correct
2 Correct 87 ms 32080 KB Output is correct
3 Correct 88 ms 32120 KB Output is correct
4 Correct 82 ms 32084 KB Output is correct
5 Correct 91 ms 32216 KB Output is correct
6 Correct 100 ms 32220 KB Output is correct
7 Correct 48 ms 30160 KB Output is correct
8 Correct 50 ms 30660 KB Output is correct
9 Correct 93 ms 32084 KB Output is correct
10 Correct 88 ms 32084 KB Output is correct
11 Correct 89 ms 32336 KB Output is correct
12 Correct 91 ms 32176 KB Output is correct
13 Correct 81 ms 30484 KB Output is correct
14 Correct 89 ms 32340 KB Output is correct
15 Correct 92 ms 32092 KB Output is correct
16 Correct 92 ms 32344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 426 ms 77140 KB Output is correct
2 Correct 343 ms 69112 KB Output is correct
3 Correct 440 ms 88856 KB Output is correct
4 Correct 328 ms 68688 KB Output is correct
5 Correct 327 ms 69848 KB Output is correct
6 Correct 472 ms 89424 KB Output is correct
7 Correct 192 ms 84556 KB Output is correct
8 Correct 223 ms 83620 KB Output is correct
9 Correct 401 ms 88316 KB Output is correct
10 Correct 402 ms 88180 KB Output is correct
11 Correct 438 ms 88656 KB Output is correct
12 Correct 494 ms 89608 KB Output is correct
13 Correct 432 ms 88792 KB Output is correct
14 Correct 447 ms 89332 KB Output is correct
15 Correct 552 ms 89356 KB Output is correct
16 Correct 479 ms 89244 KB Output is correct
17 Correct 500 ms 89280 KB Output is correct
18 Correct 486 ms 88916 KB Output is correct
19 Correct 463 ms 89304 KB Output is correct
20 Correct 462 ms 89176 KB Output is correct
21 Correct 461 ms 89172 KB Output is correct
22 Correct 452 ms 89168 KB Output is correct
23 Correct 489 ms 89172 KB Output is correct
24 Correct 473 ms 89168 KB Output is correct
25 Correct 397 ms 87724 KB Output is correct
26 Correct 425 ms 89172 KB Output is correct
27 Correct 386 ms 89168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14940 KB Output is correct
2 Correct 10 ms 15124 KB Output is correct
3 Correct 8 ms 14860 KB Output is correct
4 Correct 9 ms 14948 KB Output is correct
5 Correct 8 ms 14940 KB Output is correct
6 Correct 8 ms 14936 KB Output is correct
7 Correct 9 ms 15112 KB Output is correct
8 Correct 12 ms 15016 KB Output is correct
9 Correct 10 ms 15112 KB Output is correct
10 Correct 9 ms 14996 KB Output is correct
11 Correct 9 ms 15124 KB Output is correct
12 Correct 9 ms 14936 KB Output is correct
13 Correct 8 ms 14940 KB Output is correct
14 Correct 10 ms 15156 KB Output is correct
15 Correct 8 ms 14940 KB Output is correct
16 Correct 12 ms 15140 KB Output is correct
17 Correct 9 ms 15028 KB Output is correct
18 Correct 11 ms 14988 KB Output is correct
19 Correct 12 ms 15048 KB Output is correct
20 Correct 11 ms 15132 KB Output is correct
21 Correct 88 ms 32100 KB Output is correct
22 Correct 87 ms 32080 KB Output is correct
23 Correct 88 ms 32120 KB Output is correct
24 Correct 82 ms 32084 KB Output is correct
25 Correct 91 ms 32216 KB Output is correct
26 Correct 100 ms 32220 KB Output is correct
27 Correct 48 ms 30160 KB Output is correct
28 Correct 50 ms 30660 KB Output is correct
29 Correct 93 ms 32084 KB Output is correct
30 Correct 88 ms 32084 KB Output is correct
31 Correct 89 ms 32336 KB Output is correct
32 Correct 91 ms 32176 KB Output is correct
33 Correct 81 ms 30484 KB Output is correct
34 Correct 89 ms 32340 KB Output is correct
35 Correct 92 ms 32092 KB Output is correct
36 Correct 92 ms 32344 KB Output is correct
37 Correct 970 ms 30548 KB Output is correct
38 Correct 700 ms 28752 KB Output is correct
39 Correct 553 ms 28428 KB Output is correct
40 Correct 763 ms 30280 KB Output is correct
41 Correct 830 ms 32516 KB Output is correct
42 Execution timed out 1028 ms 32320 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 30036 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14940 KB Output is correct
2 Correct 10 ms 15124 KB Output is correct
3 Correct 8 ms 14860 KB Output is correct
4 Correct 9 ms 14948 KB Output is correct
5 Correct 8 ms 14940 KB Output is correct
6 Correct 8 ms 14936 KB Output is correct
7 Correct 9 ms 15112 KB Output is correct
8 Correct 12 ms 15016 KB Output is correct
9 Correct 10 ms 15112 KB Output is correct
10 Correct 9 ms 14996 KB Output is correct
11 Correct 9 ms 15124 KB Output is correct
12 Correct 9 ms 14936 KB Output is correct
13 Correct 8 ms 14940 KB Output is correct
14 Correct 10 ms 15156 KB Output is correct
15 Correct 8 ms 14940 KB Output is correct
16 Correct 12 ms 15140 KB Output is correct
17 Correct 9 ms 15028 KB Output is correct
18 Correct 11 ms 14988 KB Output is correct
19 Correct 12 ms 15048 KB Output is correct
20 Correct 11 ms 15132 KB Output is correct
21 Correct 10 ms 14940 KB Output is correct
22 Correct 15 ms 14940 KB Output is correct
23 Correct 13 ms 14940 KB Output is correct
24 Correct 11 ms 14940 KB Output is correct
25 Correct 9 ms 14928 KB Output is correct
26 Correct 9 ms 14940 KB Output is correct
27 Correct 10 ms 14940 KB Output is correct
28 Correct 14 ms 14936 KB Output is correct
29 Correct 10 ms 14940 KB Output is correct
30 Correct 11 ms 14940 KB Output is correct
31 Correct 10 ms 15040 KB Output is correct
32 Correct 9 ms 14940 KB Output is correct
33 Correct 9 ms 14936 KB Output is correct
34 Correct 10 ms 14940 KB Output is correct
35 Correct 10 ms 14936 KB Output is correct
36 Correct 10 ms 15196 KB Output is correct
37 Correct 8 ms 14940 KB Output is correct
38 Correct 9 ms 14940 KB Output is correct
39 Correct 88 ms 32100 KB Output is correct
40 Correct 87 ms 32080 KB Output is correct
41 Correct 88 ms 32120 KB Output is correct
42 Correct 82 ms 32084 KB Output is correct
43 Correct 91 ms 32216 KB Output is correct
44 Correct 100 ms 32220 KB Output is correct
45 Correct 48 ms 30160 KB Output is correct
46 Correct 50 ms 30660 KB Output is correct
47 Correct 93 ms 32084 KB Output is correct
48 Correct 88 ms 32084 KB Output is correct
49 Correct 89 ms 32336 KB Output is correct
50 Correct 91 ms 32176 KB Output is correct
51 Correct 81 ms 30484 KB Output is correct
52 Correct 89 ms 32340 KB Output is correct
53 Correct 92 ms 32092 KB Output is correct
54 Correct 92 ms 32344 KB Output is correct
55 Correct 970 ms 30548 KB Output is correct
56 Correct 700 ms 28752 KB Output is correct
57 Correct 553 ms 28428 KB Output is correct
58 Correct 763 ms 30280 KB Output is correct
59 Correct 830 ms 32516 KB Output is correct
60 Execution timed out 1028 ms 32320 KB Time limit exceeded
61 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14940 KB Output is correct
2 Correct 10 ms 15124 KB Output is correct
3 Correct 8 ms 14860 KB Output is correct
4 Correct 9 ms 14948 KB Output is correct
5 Correct 8 ms 14940 KB Output is correct
6 Correct 8 ms 14936 KB Output is correct
7 Correct 9 ms 15112 KB Output is correct
8 Correct 12 ms 15016 KB Output is correct
9 Correct 10 ms 15112 KB Output is correct
10 Correct 9 ms 14996 KB Output is correct
11 Correct 9 ms 15124 KB Output is correct
12 Correct 9 ms 14936 KB Output is correct
13 Correct 8 ms 14940 KB Output is correct
14 Correct 10 ms 15156 KB Output is correct
15 Correct 8 ms 14940 KB Output is correct
16 Correct 12 ms 15140 KB Output is correct
17 Correct 9 ms 15028 KB Output is correct
18 Correct 11 ms 14988 KB Output is correct
19 Correct 12 ms 15048 KB Output is correct
20 Correct 11 ms 15132 KB Output is correct
21 Correct 10 ms 14940 KB Output is correct
22 Correct 15 ms 14940 KB Output is correct
23 Correct 13 ms 14940 KB Output is correct
24 Correct 11 ms 14940 KB Output is correct
25 Correct 9 ms 14928 KB Output is correct
26 Correct 9 ms 14940 KB Output is correct
27 Correct 10 ms 14940 KB Output is correct
28 Correct 14 ms 14936 KB Output is correct
29 Correct 10 ms 14940 KB Output is correct
30 Correct 11 ms 14940 KB Output is correct
31 Correct 10 ms 15040 KB Output is correct
32 Correct 9 ms 14940 KB Output is correct
33 Correct 9 ms 14936 KB Output is correct
34 Correct 10 ms 14940 KB Output is correct
35 Correct 10 ms 14936 KB Output is correct
36 Correct 10 ms 15196 KB Output is correct
37 Correct 8 ms 14940 KB Output is correct
38 Correct 9 ms 14940 KB Output is correct
39 Correct 88 ms 32100 KB Output is correct
40 Correct 87 ms 32080 KB Output is correct
41 Correct 88 ms 32120 KB Output is correct
42 Correct 82 ms 32084 KB Output is correct
43 Correct 91 ms 32216 KB Output is correct
44 Correct 100 ms 32220 KB Output is correct
45 Correct 48 ms 30160 KB Output is correct
46 Correct 50 ms 30660 KB Output is correct
47 Correct 93 ms 32084 KB Output is correct
48 Correct 88 ms 32084 KB Output is correct
49 Correct 89 ms 32336 KB Output is correct
50 Correct 91 ms 32176 KB Output is correct
51 Correct 81 ms 30484 KB Output is correct
52 Correct 89 ms 32340 KB Output is correct
53 Correct 92 ms 32092 KB Output is correct
54 Correct 92 ms 32344 KB Output is correct
55 Correct 426 ms 77140 KB Output is correct
56 Correct 343 ms 69112 KB Output is correct
57 Correct 440 ms 88856 KB Output is correct
58 Correct 328 ms 68688 KB Output is correct
59 Correct 327 ms 69848 KB Output is correct
60 Correct 472 ms 89424 KB Output is correct
61 Correct 192 ms 84556 KB Output is correct
62 Correct 223 ms 83620 KB Output is correct
63 Correct 401 ms 88316 KB Output is correct
64 Correct 402 ms 88180 KB Output is correct
65 Correct 438 ms 88656 KB Output is correct
66 Correct 494 ms 89608 KB Output is correct
67 Correct 432 ms 88792 KB Output is correct
68 Correct 447 ms 89332 KB Output is correct
69 Correct 552 ms 89356 KB Output is correct
70 Correct 479 ms 89244 KB Output is correct
71 Correct 500 ms 89280 KB Output is correct
72 Correct 486 ms 88916 KB Output is correct
73 Correct 463 ms 89304 KB Output is correct
74 Correct 462 ms 89176 KB Output is correct
75 Correct 461 ms 89172 KB Output is correct
76 Correct 452 ms 89168 KB Output is correct
77 Correct 489 ms 89172 KB Output is correct
78 Correct 473 ms 89168 KB Output is correct
79 Correct 397 ms 87724 KB Output is correct
80 Correct 425 ms 89172 KB Output is correct
81 Correct 386 ms 89168 KB Output is correct
82 Correct 970 ms 30548 KB Output is correct
83 Correct 700 ms 28752 KB Output is correct
84 Correct 553 ms 28428 KB Output is correct
85 Correct 763 ms 30280 KB Output is correct
86 Correct 830 ms 32516 KB Output is correct
87 Execution timed out 1028 ms 32320 KB Time limit exceeded
88 Halted 0 ms 0 KB -