Submission #1089113

# Submission time Handle Problem Language Result Execution time Memory
1089113 2024-09-16T05:15:54 Z coldbr3w Food Court (JOI21_foodcourt) C++17
9 / 100
1000 ms 71660 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<pair<int,ll>>t[N], ask[N];
int g[N], res[N];
bool add[N], ok[N];
struct segment_tree_min{
    ll n;
    pair<ll,int> st[4 * N];
	ll lz[4 * N];
    void init(int _n){
        n = _n;
		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;
	ll st[4 * N], lz[4 * N];
    void init(int _n){
        n = _n;
    }
    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; int 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;
			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 19 ms 33628 KB Output is correct
2 Correct 18 ms 33516 KB Output is correct
3 Correct 17 ms 33628 KB Output is correct
4 Correct 25 ms 33672 KB Output is correct
5 Correct 17 ms 33624 KB Output is correct
6 Correct 17 ms 33624 KB Output is correct
7 Correct 18 ms 33628 KB Output is correct
8 Correct 19 ms 33624 KB Output is correct
9 Correct 23 ms 33580 KB Output is correct
10 Correct 21 ms 33464 KB Output is correct
11 Correct 23 ms 33520 KB Output is correct
12 Correct 16 ms 33684 KB Output is correct
13 Correct 16 ms 33624 KB Output is correct
14 Correct 17 ms 33484 KB Output is correct
15 Correct 17 ms 33624 KB Output is correct
16 Correct 16 ms 33628 KB Output is correct
17 Correct 21 ms 33504 KB Output is correct
18 Correct 16 ms 33628 KB Output is correct
19 Correct 16 ms 33628 KB Output is correct
20 Correct 23 ms 33616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 33628 KB Output is correct
2 Correct 18 ms 33516 KB Output is correct
3 Correct 17 ms 33628 KB Output is correct
4 Correct 25 ms 33672 KB Output is correct
5 Correct 17 ms 33624 KB Output is correct
6 Correct 17 ms 33624 KB Output is correct
7 Correct 18 ms 33628 KB Output is correct
8 Correct 19 ms 33624 KB Output is correct
9 Correct 23 ms 33580 KB Output is correct
10 Correct 21 ms 33464 KB Output is correct
11 Correct 23 ms 33520 KB Output is correct
12 Correct 16 ms 33684 KB Output is correct
13 Correct 16 ms 33624 KB Output is correct
14 Correct 17 ms 33484 KB Output is correct
15 Correct 17 ms 33624 KB Output is correct
16 Correct 16 ms 33628 KB Output is correct
17 Correct 21 ms 33504 KB Output is correct
18 Correct 16 ms 33628 KB Output is correct
19 Correct 16 ms 33628 KB Output is correct
20 Correct 23 ms 33616 KB Output is correct
21 Incorrect 17 ms 33628 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 93 ms 42832 KB Output is correct
2 Correct 94 ms 42980 KB Output is correct
3 Correct 89 ms 42832 KB Output is correct
4 Correct 87 ms 42836 KB Output is correct
5 Correct 97 ms 43100 KB Output is correct
6 Correct 85 ms 43088 KB Output is correct
7 Correct 72 ms 41416 KB Output is correct
8 Correct 56 ms 41696 KB Output is correct
9 Correct 97 ms 42320 KB Output is correct
10 Correct 125 ms 43088 KB Output is correct
11 Correct 92 ms 42836 KB Output is correct
12 Correct 84 ms 43120 KB Output is correct
13 Correct 79 ms 42488 KB Output is correct
14 Correct 82 ms 43136 KB Output is correct
15 Correct 88 ms 43344 KB Output is correct
16 Correct 87 ms 43344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1053 ms 71660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 33628 KB Output is correct
2 Correct 18 ms 33516 KB Output is correct
3 Correct 17 ms 33628 KB Output is correct
4 Correct 25 ms 33672 KB Output is correct
5 Correct 17 ms 33624 KB Output is correct
6 Correct 17 ms 33624 KB Output is correct
7 Correct 18 ms 33628 KB Output is correct
8 Correct 19 ms 33624 KB Output is correct
9 Correct 23 ms 33580 KB Output is correct
10 Correct 21 ms 33464 KB Output is correct
11 Correct 23 ms 33520 KB Output is correct
12 Correct 16 ms 33684 KB Output is correct
13 Correct 16 ms 33624 KB Output is correct
14 Correct 17 ms 33484 KB Output is correct
15 Correct 17 ms 33624 KB Output is correct
16 Correct 16 ms 33628 KB Output is correct
17 Correct 21 ms 33504 KB Output is correct
18 Correct 16 ms 33628 KB Output is correct
19 Correct 16 ms 33628 KB Output is correct
20 Correct 23 ms 33616 KB Output is correct
21 Correct 93 ms 42832 KB Output is correct
22 Correct 94 ms 42980 KB Output is correct
23 Correct 89 ms 42832 KB Output is correct
24 Correct 87 ms 42836 KB Output is correct
25 Correct 97 ms 43100 KB Output is correct
26 Correct 85 ms 43088 KB Output is correct
27 Correct 72 ms 41416 KB Output is correct
28 Correct 56 ms 41696 KB Output is correct
29 Correct 97 ms 42320 KB Output is correct
30 Correct 125 ms 43088 KB Output is correct
31 Correct 92 ms 42836 KB Output is correct
32 Correct 84 ms 43120 KB Output is correct
33 Correct 79 ms 42488 KB Output is correct
34 Correct 82 ms 43136 KB Output is correct
35 Correct 88 ms 43344 KB Output is correct
36 Correct 87 ms 43344 KB Output is correct
37 Correct 960 ms 42568 KB Output is correct
38 Correct 716 ms 42320 KB Output is correct
39 Correct 530 ms 41216 KB Output is correct
40 Correct 763 ms 41552 KB Output is correct
41 Correct 825 ms 42332 KB Output is correct
42 Execution timed out 1091 ms 43068 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 123 ms 42836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 33628 KB Output is correct
2 Correct 18 ms 33516 KB Output is correct
3 Correct 17 ms 33628 KB Output is correct
4 Correct 25 ms 33672 KB Output is correct
5 Correct 17 ms 33624 KB Output is correct
6 Correct 17 ms 33624 KB Output is correct
7 Correct 18 ms 33628 KB Output is correct
8 Correct 19 ms 33624 KB Output is correct
9 Correct 23 ms 33580 KB Output is correct
10 Correct 21 ms 33464 KB Output is correct
11 Correct 23 ms 33520 KB Output is correct
12 Correct 16 ms 33684 KB Output is correct
13 Correct 16 ms 33624 KB Output is correct
14 Correct 17 ms 33484 KB Output is correct
15 Correct 17 ms 33624 KB Output is correct
16 Correct 16 ms 33628 KB Output is correct
17 Correct 21 ms 33504 KB Output is correct
18 Correct 16 ms 33628 KB Output is correct
19 Correct 16 ms 33628 KB Output is correct
20 Correct 23 ms 33616 KB Output is correct
21 Incorrect 17 ms 33628 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 33628 KB Output is correct
2 Correct 18 ms 33516 KB Output is correct
3 Correct 17 ms 33628 KB Output is correct
4 Correct 25 ms 33672 KB Output is correct
5 Correct 17 ms 33624 KB Output is correct
6 Correct 17 ms 33624 KB Output is correct
7 Correct 18 ms 33628 KB Output is correct
8 Correct 19 ms 33624 KB Output is correct
9 Correct 23 ms 33580 KB Output is correct
10 Correct 21 ms 33464 KB Output is correct
11 Correct 23 ms 33520 KB Output is correct
12 Correct 16 ms 33684 KB Output is correct
13 Correct 16 ms 33624 KB Output is correct
14 Correct 17 ms 33484 KB Output is correct
15 Correct 17 ms 33624 KB Output is correct
16 Correct 16 ms 33628 KB Output is correct
17 Correct 21 ms 33504 KB Output is correct
18 Correct 16 ms 33628 KB Output is correct
19 Correct 16 ms 33628 KB Output is correct
20 Correct 23 ms 33616 KB Output is correct
21 Incorrect 17 ms 33628 KB Output isn't correct
22 Halted 0 ms 0 KB -