답안 #769589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
769589 2023-06-29T20:04:59 Z YassirSalama 사탕 분배 (IOI21_candies) C++17
3 / 100
208 ms 23024 KB
#include "candies.h"
#include<bits/stdc++.h>
#include <vector>
using namespace std;
#define ll long long
const int MAXN=2e5;
ll tree[4*MAXN];
ll lazy[4*MAXN];
vector<int> cc;
int n;
int q;
void push(int node,int l,int r){
    if(lazy[node]){
        tree[node]+=(r-l+1)*lazy[node];
        if(l!=r) lazy[node<<1]+=lazy[node],
                 lazy[node<<1|1]+=lazy[node];
        lazy[node]=0;
    }
}
void update(int node,int l,int r,int ql,int qr,int v){
    push(node,l,r);
    if(ql<=l&&r<=qr){
        lazy[node]+=v;
        push(node,l,r);
        return;
    }
    int mid=(l+r)/2;
    if(ql<=mid) update(node<<1,l,mid,ql,qr,v);
    if(qr>mid) update(node<<1|1,mid+1,r,ql,qr,v);
    tree[node]=tree[node<<1]+tree[node<<1|1];
}
int query(int node,int l,int r,int ql){
    push(node,l,r);
    if(l==r) return tree[node];
    int mid=(l+r)/2;
    if(ql<=mid) return query(node<<1,l,mid,ql);
    return query(node<<1|1,mid+1,r,ql);
}
vector<int> distribute_candies(vector<int> c, vector<int> l,
                                    vector<int> r, vector<int> v) {
    memset(lazy,0LL,sizeof lazy);
    memset(tree,0LL,sizeof tree);
    n = c.size();
    q = v.size();
    vector<ll> s(n);
    cc=c;
    if(n<=2000&&q<=2000){
        for(int j=0;j<q;j++){
            int lrr=l[j],rr=r[j],cc=v[j];
            for(int i=lrr;i<=rr;i++){
                s[i]=max(0LL,min((long long)c[i],s[i]+cc));
            }
        }
    }else{
        for(int j=0;j<q;j++){
            int lrr=l[j],rr=r[j],cc=v[j];
            update(1,0,n-1,lrr,rr,cc);
        }
        for(int i=0;i<n;i++){
            ll x=query(1,0,n-1,i);
            s[i]=min(x,(long long)c[i]);
        }
    }
    vector<int> ans;
    for(auto x:s) ans.push_back(x);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12756 KB Output is correct
2 Correct 5 ms 12756 KB Output is correct
3 Correct 5 ms 12864 KB Output is correct
4 Correct 6 ms 12864 KB Output is correct
5 Correct 7 ms 12864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 208 ms 23024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12884 KB Output is correct
2 Incorrect 99 ms 18080 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12756 KB Output is correct
2 Correct 5 ms 12852 KB Output is correct
3 Incorrect 48 ms 18088 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12756 KB Output is correct
2 Correct 5 ms 12756 KB Output is correct
3 Correct 5 ms 12864 KB Output is correct
4 Correct 6 ms 12864 KB Output is correct
5 Correct 7 ms 12864 KB Output is correct
6 Incorrect 208 ms 23024 KB Output isn't correct
7 Halted 0 ms 0 KB -