제출 #1345535

#제출 시각아이디문제언어결과실행 시간메모리
1345535jellybeanSnowball (JOI21_ho_t2)C++20
100 / 100
185 ms23924 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define dd(x) cout<<#x<<" is "<<x<<endl;
#define dd2(x,y) cout<<#x<<" is "<<x<<" "<<#y<<" is "<<y<<endl;
typedef pair<int,int> pii;

const int N = 200005, Q = 200005;
set<pii> gaps;
int tr[Q], tl[Q], rstop[N], lstop[N], partial[N];
int r,l,c;

signed main(){
	
	int n,q; cin>>n>>q;
	int a[n];
	for(int i=0; i<n; i++) {
		cin>>a[i];
		rstop[i] = q, lstop[i] = q;
	}
	for(int i=1; i<n; i++) gaps.insert({a[i]-a[i-1], i-1}); //check if input is in incr order
	for(int t=1; t<=q; t++){
		int k; cin>>k;
		c += k;
		int nl = min(l,c), nr = max(r,c);
		tr[t] = nr, tl[t] = nl;
		if(nl == l and nr == r) continue;
		
		while(gaps.size() and gaps.begin()->first <= nr-nl){
			auto[gap,i] = *gaps.begin();
			gaps.erase(gaps.begin());
			
			rstop[i] = t-1, lstop[i+1] = t-1;
			int p = gap-(r-l);
			if(k>0) partial[i] += p;
			else partial[i+1] += p;
		}
		
		r = nr, l = nl;
	}
	
	for(int i=0; i<n; i++) cout<<tr[rstop[i]] - tl[lstop[i]] + partial[i] << '\n';
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...