Submission #569408

# Submission time Handle Problem Language Result Execution time Memory
569408 2022-05-27T11:31:29 Z inksamurai Food Court (JOI21_foodcourt) C++17
13 / 100
839 ms 53788 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);
	rep(i,q){
		int t;
		cin>>t;
		if(t==1){
			int l,r,k;
			cin>>l>>r>>bel[i]>>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);
		}else{
			int j,c;
			cin>>j>>c;
			j-=1;
			usd[i]=1;
			// print(laseg1.prod(j,j+1)-laseg.prod(j,j+1));
			qry[j].emplace_back(laseg1.prod(j,j+1)-laseg.prod(j,j+1)+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 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 155 ms 14568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 839 ms 53788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 159 ms 14944 KB Output is correct
2 Correct 197 ms 14984 KB Output is correct
3 Correct 171 ms 15592 KB Output is correct
4 Correct 130 ms 13972 KB Output is correct
5 Correct 156 ms 14808 KB Output is correct
6 Correct 249 ms 15512 KB Output is correct
7 Correct 58 ms 4600 KB Output is correct
8 Correct 46 ms 4388 KB Output is correct
9 Correct 113 ms 14288 KB Output is correct
10 Correct 119 ms 14108 KB Output is correct
11 Correct 182 ms 15600 KB Output is correct
12 Correct 179 ms 15660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -