답안 #439298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439298 2021-06-29T13:53:03 Z algorithm16 사탕 분배 (IOI21_candies) C++17
11 / 100
568 ms 13808 KB
#include "candies.h"
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int llint;
llint off=1,t[500005],t1[500005],p[500005],n,q;
void send(int x) {
	if(!p[x]) return;
	t[x]=max(0LL,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,llint 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);
    t[x]=max(t[x*2],t[x*2+1]);
}
llint 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 1 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 3 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 568 ms 13808 KB Output is correct
2 Correct 494 ms 13672 KB Output is correct
3 Correct 537 ms 13716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 263 ms 5028 KB Output is correct
3 Incorrect 64 ms 2604 KB Output isn't correct
4 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 555 ms 4968 KB Output is correct
4 Incorrect 67 ms 2616 KB Output isn't correct
5 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 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 568 ms 13808 KB Output is correct
7 Correct 494 ms 13672 KB Output is correct
8 Correct 537 ms 13716 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 263 ms 5028 KB Output is correct
11 Incorrect 64 ms 2604 KB Output isn't correct
12 Halted 0 ms 0 KB -