Submission #569413

# Submission time Handle Problem Language Result Execution time Memory
569413 2022-05-27T11:34:38 Z inksamurai Food Court (JOI21_foodcourt) C++17
7 / 100
1000 ms 18596 KB
#include <bits/stdc++.h>
// cut here
#ifdef _MSC_VER
#include <intrin.h>
#endif
 
namespace atcoder {
 
namespace internal {
 
int ceil_pow2(int n) {
    int x = 0;
    while ((1U << x) < (unsigned int)(n)) x++;
    return x;
}
 
int bsf(unsigned int n) {
#ifdef _MSC_VER
    unsigned long index;
    _BitScanForward(&index, n);
    return index;
#else
    return __builtin_ctz(n);
#endif
}
 
}  // namespace internal
 
}  // namespace atcoder
 
 
namespace atcoder {
 
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
  public:
    segtree() : segtree(0) {}
    segtree(int n) : segtree(std::vector<S>(n, e())) {}
    segtree(const std::vector<S>& v) : _n(int(v.size())) {
        log = internal::ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }
 
    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }
 
    S get(int p) {
        assert(0 <= p && p < _n);
        return d[p + size];
    }
 
    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;
 
        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }
 
    S all_prod() { return d[1]; }
 
    template <bool (*f)(S)> int max_right(int l) {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }
 
    template <bool (*f)(S)> int min_left(int r) {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }
 
  private:
    int _n, size, log;
    std::vector<S> d;
 
    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};
 
}  // namespace atcoder
// cut here 
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3z2QF2y ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

struct lazy_segtree{
	int n;
	vec(ll) seg,lazy,flag;
	lazy_segtree(int m){
		init(m);
	}
	void init(int m){
		n=1;
		while(n<m) n*=2;
		seg.clear();
		lazy.clear();
		flag.clear();
		seg.resize(2*n,0);
		lazy.resize(2*n,0);
		flag.resize(2*n,false);
	}
	void push(int l,int r,int node){
		if(flag[node]){
			seg[node]+=(ll)(r-l)*lazy[node];
			seg[node]=max(0ll,seg[node]);
			if(node<n){
				// lazy merge
				int m=(l+r)>>1;
				lazy[node*2]+=lazy[node];
				lazy[node*2+1]+=lazy[node];
				flag[node*2]=flag[node*2+1]=true;
			}
			flag[node]=false;
			lazy[node]=0;
		}
	}
	void set(int node,int l,int r,ll x,int _l,int _r){
		push(l,r,node);
		if(l>=_r or r<=_l) return;
		if(l>=_l and r<=_r){
			lazy[node]+=x;
			flag[node]=true;
			push(l,r,node);
			return;
		}
		int m=(l+r)>>1;
		set(node*2,l,m,x,_l,_r);
		set(node*2+1,m,r,x,_l,_r);
		// prod seg_node
		seg[node*2]=max(0ll,seg[node*2]);
		seg[node*2+1]=max(0ll,seg[node*2+1]);
		seg[node]=seg[node*2]+seg[node*2+1]; 
	}
	ll prod(int node,int l,int r,int _l,int _r){
		push(l,r,node);
		// _e() upper seg _
		if(l>=_r or r<=_l) return 0; 
		if(l>=_l and r<=_r) return seg[node];
		int m=(l+r)>>1;
		ll vl=prod(node*2,l,m,_l,_r);
		ll vr=prod(node*2+1,m,r,_l,_r);
		return vl+vr;
	}
	void set(int l,int r,int x){
		// [l,r)
		set(1,0,n,x,l,r);
	}
	ll prod(int l,int r){
		// [l,r)
		return prod(1,0,n,l,r);
	}
};

int op(int l,int r){return l+r;}
int e(){return 0;}

signed main(){
_3z2QF2y;
	int n,m,q;
	cin>>n>>m>>q;
	vi bel(q,-1),usd(q,0);
	vec(vec(tuple<int,int,int>)) adqry(n+1);
	vec(vec(pii)) qry(n+1);
	// lazy_segtree laseg(n),laseg1(n);
	vec(ll) laseg(n),laseg1(n);
	rep(i,q){
		int t;
		cin>>t;
		if(t==1){
			int l,r,k;
			cin>>l>>r>>bel[i]>>k;
			rng(j,l-1,r){
				laseg[j]+=k;
				laseg1[j]+=k;
			}
			// laseg.set(l-1,r,k);
			// laseg1.set(l-1,r,k);
			adqry[l-1].emplace_back(i,k,1);
			if(r<n) adqry[r].emplace_back(i,k,-1);
		}else if(t==2){
			int l,r,k;
			cin>>l>>r>>k;
			// laseg.set(l-1,r,-k);
			rng(j,l-1,r){
				laseg1[j]-=k;
				laseg1[j]=max(0ll,laseg1[j]);
			}
		}else{
			int j,c;
			cin>>j>>c;
			j-=1;
			usd[i]=1;
			// print(laseg[j]);
			// print(laseg1.prod(j,j+1)-laseg.prod(j,j+1));
			qry[j].emplace_back(laseg[j]-laseg1[j]+c,i);
		}
	}
	vi pns(q);
	atcoder::segtree<int,op,e> seg(q);
	rep(i,n){
		for(auto &[j,k,t]:adqry[i]){
			// if(i==0) print(i,j,k);
			if(t==1){
				seg.set(j,k);
			}else{
				seg.set(j,0);
			}
		}
		// if(i==0) print(seg.prod(0,9));
		for(auto &[b,j]:qry[i]){
			int l=0,r=q-1;
			int c=-1;
			while(l<=r){
				int m=(l+r)>>1;
				if(seg.prod(0,m+1)>=b){
					c=m,r=m-1;
				}else{
					l=m+1;
				}
			}
			// if(i==0) print(c,b,j);
			if(c!=-1 and c<=j){
				pns[j]=bel[c];
			}
		}
	}
	rep(i,q){
		if(!usd[i]) continue;
		assert(pns[i]!=-1);
		cout<<pns[i]<<"\n";
	}
//
	return 0;
}

Compilation message

foodcourt.cpp: In member function 'void lazy_segtree::push(long long int, long long int, long long int)':
foodcourt.cpp:181:9: warning: unused variable 'm' [-Wunused-variable]
  181 |     int m=(l+r)>>1;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 4 ms 652 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 4 ms 584 KB Output is correct
8 Correct 4 ms 588 KB Output is correct
9 Correct 4 ms 588 KB Output is correct
10 Correct 4 ms 596 KB Output is correct
11 Correct 4 ms 644 KB Output is correct
12 Correct 5 ms 584 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 5 ms 596 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 4 ms 652 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 4 ms 584 KB Output is correct
8 Correct 4 ms 588 KB Output is correct
9 Correct 4 ms 588 KB Output is correct
10 Correct 4 ms 596 KB Output is correct
11 Correct 4 ms 644 KB Output is correct
12 Correct 5 ms 584 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 5 ms 596 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 3 ms 584 KB Output is correct
22 Correct 3 ms 584 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 4 ms 596 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 2 ms 396 KB Output is correct
27 Correct 5 ms 596 KB Output is correct
28 Correct 4 ms 596 KB Output is correct
29 Correct 4 ms 596 KB Output is correct
30 Correct 5 ms 596 KB Output is correct
31 Correct 4 ms 596 KB Output is correct
32 Correct 4 ms 596 KB Output is correct
33 Correct 4 ms 596 KB Output is correct
34 Correct 5 ms 596 KB Output is correct
35 Correct 4 ms 596 KB Output is correct
36 Correct 6 ms 596 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 695 ms 9396 KB Output is correct
2 Correct 519 ms 11356 KB Output is correct
3 Correct 729 ms 10612 KB Output is correct
4 Correct 717 ms 10628 KB Output is correct
5 Correct 541 ms 11184 KB Output is correct
6 Correct 517 ms 11312 KB Output is correct
7 Correct 33 ms 4780 KB Output is correct
8 Correct 33 ms 5132 KB Output is correct
9 Execution timed out 1090 ms 10716 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 18596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 4 ms 652 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 4 ms 584 KB Output is correct
8 Correct 4 ms 588 KB Output is correct
9 Correct 4 ms 588 KB Output is correct
10 Correct 4 ms 596 KB Output is correct
11 Correct 4 ms 644 KB Output is correct
12 Correct 5 ms 584 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 5 ms 596 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 695 ms 9396 KB Output is correct
22 Correct 519 ms 11356 KB Output is correct
23 Correct 729 ms 10612 KB Output is correct
24 Correct 717 ms 10628 KB Output is correct
25 Correct 541 ms 11184 KB Output is correct
26 Correct 517 ms 11312 KB Output is correct
27 Correct 33 ms 4780 KB Output is correct
28 Correct 33 ms 5132 KB Output is correct
29 Execution timed out 1090 ms 10716 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 820 ms 9832 KB Output is correct
2 Correct 749 ms 9712 KB Output is correct
3 Correct 913 ms 10400 KB Output is correct
4 Correct 849 ms 8824 KB Output is correct
5 Execution timed out 1056 ms 9676 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 4 ms 652 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 4 ms 584 KB Output is correct
8 Correct 4 ms 588 KB Output is correct
9 Correct 4 ms 588 KB Output is correct
10 Correct 4 ms 596 KB Output is correct
11 Correct 4 ms 644 KB Output is correct
12 Correct 5 ms 584 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 5 ms 596 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 3 ms 584 KB Output is correct
22 Correct 3 ms 584 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 4 ms 596 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 2 ms 396 KB Output is correct
27 Correct 5 ms 596 KB Output is correct
28 Correct 4 ms 596 KB Output is correct
29 Correct 4 ms 596 KB Output is correct
30 Correct 5 ms 596 KB Output is correct
31 Correct 4 ms 596 KB Output is correct
32 Correct 4 ms 596 KB Output is correct
33 Correct 4 ms 596 KB Output is correct
34 Correct 5 ms 596 KB Output is correct
35 Correct 4 ms 596 KB Output is correct
36 Correct 6 ms 596 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 684 KB Output is correct
39 Correct 695 ms 9396 KB Output is correct
40 Correct 519 ms 11356 KB Output is correct
41 Correct 729 ms 10612 KB Output is correct
42 Correct 717 ms 10628 KB Output is correct
43 Correct 541 ms 11184 KB Output is correct
44 Correct 517 ms 11312 KB Output is correct
45 Correct 33 ms 4780 KB Output is correct
46 Correct 33 ms 5132 KB Output is correct
47 Execution timed out 1090 ms 10716 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 4 ms 652 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 4 ms 584 KB Output is correct
8 Correct 4 ms 588 KB Output is correct
9 Correct 4 ms 588 KB Output is correct
10 Correct 4 ms 596 KB Output is correct
11 Correct 4 ms 644 KB Output is correct
12 Correct 5 ms 584 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 5 ms 596 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 3 ms 584 KB Output is correct
22 Correct 3 ms 584 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 4 ms 596 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 2 ms 396 KB Output is correct
27 Correct 5 ms 596 KB Output is correct
28 Correct 4 ms 596 KB Output is correct
29 Correct 4 ms 596 KB Output is correct
30 Correct 5 ms 596 KB Output is correct
31 Correct 4 ms 596 KB Output is correct
32 Correct 4 ms 596 KB Output is correct
33 Correct 4 ms 596 KB Output is correct
34 Correct 5 ms 596 KB Output is correct
35 Correct 4 ms 596 KB Output is correct
36 Correct 6 ms 596 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 684 KB Output is correct
39 Correct 695 ms 9396 KB Output is correct
40 Correct 519 ms 11356 KB Output is correct
41 Correct 729 ms 10612 KB Output is correct
42 Correct 717 ms 10628 KB Output is correct
43 Correct 541 ms 11184 KB Output is correct
44 Correct 517 ms 11312 KB Output is correct
45 Correct 33 ms 4780 KB Output is correct
46 Correct 33 ms 5132 KB Output is correct
47 Execution timed out 1090 ms 10716 KB Time limit exceeded
48 Halted 0 ms 0 KB -