답안 #595658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
595658 2022-07-13T23:17:07 Z serize 사탕 분배 (IOI21_candies) C++17
3 / 100
107 ms 17192 KB
#include "candies.h"
#include <bits/stdc++.h>
#include <cassert>
#include <cstdio>
#include <vector>
#define lowbit(x) x&(-x)

using namespace std;
const int MAX = 4e5+5;

vector<int> ar(MAX), state(MAX), abi(MAX);

inline void add(int k, int value){
    while(k < MAX){
        abi[k] += value;
        k += lowbit(k);
    }
}

inline int read(int k){
    int ans = 0;
    while(k > 0){
        ans += abi[k];
        k -= lowbit(k);
    }
    return ans;
} 


std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v){
    int n; n = c.size();
    bool subtask2 = 1;
    for(int i = 1; i <= n; i++){
        ar[i] = c[i-1];
    }
    for(auto i: v){
        if(i < 0) subtask2 = 0;
    }
    int q = l.size();
    if(q <= 2000){
        for(int i = 0; i < q; i++){
            for(int j = l[i]+1; j <= r[i]+1; j++ ){
                if(v[i] < 0) state[j] = max(0,state[j]+v[i]);
                else state[j] = min(ar[j],state[j]+v[i]);
            }
        }
    }
    else{
        if(subtask2){
           for(int i = 0; i < q; i++){
               add( l[i]+1, v[i] );
               add( r[i]+2, -v[i] );
           }
           for(int i = 1; i <= n; i++){
               state[i] = min( ar[i], read(i) );
           }
        }
    }
    vector<int> s;
    for(int i = 1; i <= n; i++){
        s.push_back(state[i]);
    }
    return s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 5016 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 107 ms 17192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 51 ms 12724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 5020 KB Output is correct
3 Incorrect 49 ms 12436 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 5016 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Incorrect 107 ms 17192 KB Output isn't correct
7 Halted 0 ms 0 KB -