답안 #439291

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439291 2021-06-29T13:41:41 Z algorithm16 사탕 분배 (IOI21_candies) C++17
3 / 100
528 ms 7268 KB
#include "candies.h"
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int off=1,t[500005],t1[500005],p[500005],n,q;
void send(int x) {
	if(!p[x]) return;
	t[x]=max(0,t[x]-p[x]);
	if(x<off) {
		p[x*2]+=p[x];
		p[x*2+1]+=p[x];
	}
	p[x]=0;
}
void update(int x,int lo,int hi,int l,int r,int v1) {
	send(x);
	if(lo>r || hi<l) return;
	if(lo>=l && hi<=r) {
		p[x]+=v1;
		send(x);
		return;
	}
	update(x*2,lo,(lo+hi)/2,l,r,v1);
	update(x*2+1,(lo+hi)/2+1,hi,l,r,v1);
}
int query(int x,int lo,int hi,int l,int r) {
	send(x);
	if(lo>r || hi<l) return 0;
	if(lo>=l && hi<=r) return t[x];
	return max(query(x*2,lo,(lo+hi)/2,l,r),query(x*2+1,(lo+hi)/2+1,hi,l,r));
}
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();
    vector<int> s(n);
    while(off<n) off*=2;
    int mini=1e9;
    for(int i=0;i<q;i++) mini=min(mini,v[i]);
    /*if(mini>0) {
    	for(int i=0;i<n;i++) {
    		update(1,0,off-1,i,i,-c[i]);
		}
		for(int i=0;i<q;i++) {
			update(1,0,off-1,l[i],r[i],v[i]);
		}
		for(int i=0;i<n;i++) {
			s[i]=c[i]-query(1,0,off-1,i,i);
		}
	}*/
	/*else*/ if(n<=2000) {
		for(int i=0;i<n;i++) {
			s[i]=0;
		}
		for(int i=0;i<q;i++) {
			if(v[i]<0) {
				for(int j=l[i];j<=r[i];j++) {
					s[j]=max(0,s[j]+v[i]);
				}
			}
			else{
				for(int j=l[i];j<=r[i];j++) {
					s[j]=min(c[j],s[j]+v[i]);
				}
			}
		}
	}
    return s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 119 ms 7268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 229 ms 5024 KB Output is correct
3 Incorrect 54 ms 2624 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 528 ms 5024 KB Output is correct
4 Incorrect 53 ms 2636 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Incorrect 119 ms 7268 KB Output isn't correct
7 Halted 0 ms 0 KB -