답안 #834773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834773 2023-08-22T19:07:43 Z Baytoro 사탕 분배 (IOI21_candies) C++17
3 / 100
91 ms 8828 KB
#include "candies.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()

long long tree[1000005];
void add(int r, int v){
	r++;
	for(;r<400005;r+=r&-r)
		tree[r]+=v;
}
void add(int l, int r, int v){
	add(r,v);
	if(l-1>=0)
		add(l-1,v);
}
int get(int x){
	x++;
	int sum=0;
	for(;x>0;x-=x&-x)
		sum+=tree[x];
	return sum;
}
int get(int r, int val){
	return get(r)-get(r-1);
}
vector<int> distribute_candies(vector<int> c, vector<int> l,
                                    vector<int> r, vector<int> v) {
    int n=c.size(),q=v.size();
    vector<int> a(n);
    if(n<=2000 && q<=2000){
		for(int t=0;t<q;t++){
			for(int i=l[t];i<=r[t];i++){
				a[i]+=v[t];
				a[i]=min(c[i],a[i]);
				a[i]=max(a[i],0);
			}
		}
	}
	else{
		for(int t=0;t<q;t++){
			add(l[t],r[t],v[t]);
		}
		for(int i=0;i<n;i++)
			a[i]=max(c[i],get(i,0));
	}
	return a;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 91 ms 8828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 52 ms 5076 KB Output isn't correct
3 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 Incorrect 43 ms 4964 KB Output isn't correct
4 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 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 91 ms 8828 KB Output isn't correct
7 Halted 0 ms 0 KB -