답안 #1046323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046323 2024-08-06T12:57:51 Z Malix 사탕 분배 (IOI21_candies) C++17
11 / 100
264 ms 12964 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))

ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;

vector<ll> ft;
int n,q;

void update(int x,ll y){
    x++;
    while(x<n+1){
        ft[x]+=y;
        x+=LSOne(x);
    }
}

ll solve(int x){
    x++;
    ll ans=0;
    while(x){
        ans+=ft[x];
        x-=LSOne(x);
    }
    return ans;
}

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    n=c.size(),q=l.size();
if(n<=2000){
    vi ans(n,0);
    REP(i,0,q)REP(j,l[i],r[i]+1)ans[j]=max(0,min(c[j],ans[j]+v[i]));
    return ans;
}
    vi ans(n);
    ft.resize(n+1,0);
    REP(i,0,q){
        update(l[i],(ll)v[i]);
        update(r[i]+1,(ll)(-v[i]));
    }
    REP(i,0,n){
        ll x=solve(i);
        if(x>1e9)x=1e9;
        ans[i]=min(c[i],(int)x);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 8952 KB Output is correct
2 Correct 62 ms 12880 KB Output is correct
3 Correct 72 ms 12964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 113 ms 5104 KB Output is correct
3 Incorrect 27 ms 5708 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 264 ms 5108 KB Output is correct
4 Incorrect 25 ms 5188 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 63 ms 8952 KB Output is correct
7 Correct 62 ms 12880 KB Output is correct
8 Correct 72 ms 12964 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 113 ms 5104 KB Output is correct
11 Incorrect 27 ms 5708 KB Output isn't correct
12 Halted 0 ms 0 KB -