답안 #798439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798439 2023-07-30T17:31:02 Z YassirSalama 사탕 분배 (IOI21_candies) C++17
0 / 100
5000 ms 32444 KB
// #include "candies.h"
#include<bits/stdc++.h>
#include <vector>
#define ll long long
#define all(v) v.begin(),v.end()
using namespace std;
const int MAXN=2e5;
long long tree[4*MAXN+1][2];
long long lazy[4*MAXN+1];
vector<int> ans;
void push(int node,int l,int r){
    if(lazy[node]!=0){
        tree[node][0]+=lazy[node];
        tree[node][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 x){
    int mid=(l+r)/2;
    push(node,l,r);
    if(l!=r){
        push(node<<1,l,mid);
        push(node<<1|1,mid+1,r);
    }
    if(ql<=l&&r<=qr) {
        lazy[node]+=x;
        push(node,l,r);
        return;
    }
    if(ql<=mid) update(node<<1,l,mid,ql,qr,x);
    if(qr>mid) update(node<<1|1,mid+1,r,ql,qr,x);
    tree[node][0]=min(tree[node<<1][0],tree[node<<1|1][0]);
    tree[node][1]=max(tree[node<<1][1],tree[node<<1|1][1]);
}
void set_zero(int node,int l,int r){
    push(node,l,r);
    if(tree[node][1]<0){
        update(node,l,r,l,r,-tree[node][1]);
    }
    if(tree[node][0]>=0) return;
    set_zero(node<<1,l,(l+r)/2);
    set_zero(node<<1|1,(l+r)/2+1,r);
}
void res(int node,int l,int r,int x){
    push(node,l,r);
    int mid=(l+r)/2;
    if(l!=r){
        push(node<<1,l,mid);
        push(node<<1|1,mid+1,r);
    }
    if(tree[node][0]>x){
        update(node,l,r,l,r,x-tree[node][0]);
    }
    if(tree[node][1]<=x) return;
    res(node<<1,l,mid,x);
    res(node<<1|1,mid+1,r,x);
}
int query(int node,int l,int r,int ql){
    push(node,l,r);
    int mid=(l+r)/2;
    if(l!=r){
        push(node<<1,l,mid);
        push(node<<1|1,mid+1,r);
    }    
    if(l==r) return tree[node][1];
    if(ql<=mid) return query(node<<1,l,mid,ql);
    else return query(node<<1|1,mid+1,r,ql);
}
vector<int> distribute_candies(vector<int> c, vector<int> ql,
                                    vector<int> qr, vector<int> v) {
    int n=c.size();
    int q=v.size();
    memset(tree,0,sizeof(tree));
    memset(lazy,0,sizeof(lazy));
    vector<int> ans(n,0);
    for(int i=0;i<q;i++){
        update(1,0,n-1,ql[i],qr[i],v[i]);
        if(v[i]<0) set_zero(1,0,n-1);
        else res(1,0,n-1,c[0]);
    }
    for(int i=0;i<n;i++){
        int x;
        x=query(1,0,n-1,i);
        ans[i]=min(c[0],x);
    }
    return ans;
}


#ifdef IOI
int main() {
    int n;
    assert(1 == scanf("%d", &n));
    std::vector<int> c(n);
    for(int i = 0; i < n; ++i) {
        assert(scanf("%d", &c[i]) == 1);
    }

    int q;
    assert(1 == scanf("%d", &q));
    std::vector<int> l(q), r(q), v(q);
    for(int i = 0; i < q; ++i) {
        assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
    }

    std::vector<int> ans = distribute_candies(c, l, r, v);

    for(int i = 0; i < n; ++i) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", ans[i]);
    }
    printf("\n");
    fclose(stdout);
    return 0;}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 19028 KB Output is correct
2 Incorrect 9 ms 19020 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5044 ms 30960 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 19028 KB Output is correct
2 Correct 181 ms 26720 KB Output is correct
3 Correct 86 ms 24748 KB Output is correct
4 Correct 3748 ms 32080 KB Output is correct
5 Execution timed out 5041 ms 32444 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 19028 KB Output is correct
2 Incorrect 9 ms 19020 KB Output isn't correct
3 Halted 0 ms 0 KB -