Submission #1329625

#TimeUsernameProblemLanguageResultExecution timeMemory
1329625mhn_neekFood Court (JOI21_foodcourt)C++20
14 / 100
1100 ms589824 KiB
//In the name of God
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;
typedef pair<lli,lli> pii;
typedef pair<pii,pii> piiii;
typedef vector<lli> ve;
typedef vector<pii> vp;
const lli N=3e5+100;
const lli mod=1e9+7;//998244353;//1e9+9
const lli INF=1e18;
lli power(lli x,lli y){lli res = 1;x = x % mod;while(y>0){if( y & 1 ){res = (res * x) % mod;}y = y >> 1;x = (x * x)%mod;}return res;}
lli modinv(lli x){return power(x,mod-2);}
lli divide(lli x,lli y){return ((x%mod) * modinv(y))%mod;}
#define all(v) v.begin(),v.end()
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define migmig ios_base::sync_with_stdio(false),cout.tie(0), cin.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define minheap priority_queue<pair<lli,pii>, std::vector<pair<lli,pii>>, std::greater<pair<lli,pii>>>
#define set_preci(x) cout << fixed << setprecision(x);
#define debug(x) cerr << (#x) << " " << (x) << endl
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define SUM(v) accumulate(v.begin(),v.end(), 0LL)
#define FOR(x,n) for(lli x = 0; x < n; x++)
#define FORS(x,n) for(lli x = 1; x <= n; x++)
#define TEST int TQPWIEJR; cin>>TQPWIEJR;while(TQPWIEJR--)
#define BN(l,a) while(l){a.PB(l%2);l/=2;}
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define sep " "
#define SZ(X) (lli)X.size()
lli tmp;
int main(){
    migmig;
    lli n,m,q;
    cin>>n>>m>>q;
    vector< deque<pair<lli,lli>> > sp(n+1);
    vector<lli> sz(n+1, 0);

    for(lli i=0;i<q;i++){
        int t;
        cin>>t;
        if(t==1){
            lli L,R,C,K;
            cin>>L>>R>>C>>K;
            for(lli s=L;s<=R;s++){
                if(K<=0) continue;
                if(!sp[s].empty() && sp[s].back().fi == C){
                    sp[s].back().se += K;
                } else {
                    sp[s].emplace_back(C, K);
                }
                sz[s] += K;
            }
        } else if(t==2){
            lli L,R,K;
            cin>>L>>R>>K;
            for(lli s=L;s<=R;s++){
                if(K<=0 || sz[s]==0) continue;
                if(K >= sz[s]){
                    sp[s].clear();
                    sz[s]=0;
                    continue;
                }
                lli rem = K;
                while(rem>0 && !sp[s].empty()){
                    auto &fr = sp[s].front();
                    if(fr.second <= rem){
                        rem -= fr.second;
                        sz[s] -= fr.second;
                        sp[s].pop_front();
                    } else {
                        fr.second -= rem;
                        sz[s] -= rem;
                        rem = 0;
                    }
                }
            }
        } else if(t==3){
            lli A,B;
            cin>>A>>B;
            if(B > sz[A]){
                cout << 0 << endl;
            } else {
                lli acc = 0;
                lli ans = 0;
                for(auto &p : sp[A]){
                    acc += p.second;
                    if(acc >= B){
                        ans = p.first;
                        break;
                    }
                }
                cout << ans << endl;
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...