답안 #718189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718189 2023-04-03T15:10:15 Z baojiaopisu 사탕 분배 (IOI21_candies) C++17
3 / 100
123 ms 13668 KB
#include "candies.h"
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;

#define fi first
#define se second
#define left BAO
#define right ANH
#define pb push_back
#define pf push_front
#define mp make_pair
#define ins insert
#define btpc __builtin_popcount
#define btclz __builtin_clz

#define sz(x) (int)(x.size());
#define all(x) x.begin(), x.end()
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        if (x > y)
        {
            x = y;
            return true;
        }
        return false;
    }
template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        if (x < y)
        {
            x = y;
            return true;
        }
        return false;
    }

const int MOD = 1e9 + 7; //998244353

template<class X, class Y>
	void add(X &x, const Y &y) {
		x = (x + y);
		if(x >= MOD) x -= MOD;
	}

template<class X, class Y> 
	void sub(X &x, const Y &y) {
		x = (x - y);
		if(x < 0) x += MOD;
	}

/* Author : Le Ngoc Bao Anh, 12A5, LQD High School for Gifted Student*/

const ll INF = 1e9;
const int N = 1e5 + 10;

template <class T> struct FenwickTree {
	int n;
	vector<T> bit;

	FenwickTree(int _n = 0) {
		n = _n;
		bit.resize(n + 5);
		for(int i = 1; i <= n; i++) bit[i] = 0;
	}

	void update(int pos, T x) {
		for(int i = pos; i <= n; i += i & (-i)) bit[i] += x;
	}

	T get(int pos) {
		T ans = 0;
		for(int i = pos; i > 0; i -= i & (-i)) ans += bit[i];
		return ans;
	}
};

vector<int> distribute_candies(vector<int> c, vector<int> left, vector<int> right, vector<int> val) {
	int n = c.size();
	int q = left.size();

	if(n <= 2000 && q <= 2000) {
		vector<int> ans(n, 0);
		for(int i = 0; i < q; i++) {
			for(int j = left[i]; j <= right[i]; j++) {
				ans[j] = min(c[j], ans[j] + val[i]);
				ans[j] = max(0, ans[j]);
			}
		}

		return ans;
	}

	bool isSub1 = true;
	for(int i = 0; i < q; i++) isSub1 &= (val[i] > 0);

	if(isSub1) {
		FenwickTree<ll> BIT = FenwickTree<ll>(n);
		for(int i = 0; i < q; i++) {
			int l = left[i] + 1, r = right[i] + 1;
			BIT.update(l, val[i]);
			BIT.update(r + 1, -val[i]);
		}

		vector<int> ans(n);
		for(int i = 0; i < n; i++) {
			ans[i] = BIT.get(i + 1);
			minimize(ans[i], c[i]);
		}

		return ans;
	}

	return {};
};
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 123 ms 13668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 53 ms 8024 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 51 ms 7640 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Incorrect 123 ms 13668 KB Output isn't correct
7 Halted 0 ms 0 KB -