제출 #1319331

#제출 시각아이디문제언어결과실행 시간메모리
1319331tomthuy123Room Temperature (JOI24_ho_t1)C++20
50 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double const ll MOD=1000000007; ll n; vector<ll> Tree; vector<ll> Lazy; vector<ll> lst; void Build(ll index, ll start, ll end){ if(start==end){ Tree[index]=lst[start]; } else{ ll mid=start+(end-start)/2; Build(index+1,start,mid); Build(index+2*(mid-start+1),mid+1,end); Tree[index]=Tree[index+1]+Tree[index+2*(mid-start+1)]; } } void Push(ll index, ll start, ll end){ if(Lazy[index]!=0){ Tree[index]+=Lazy[index]*(end-start+1); if(start!=end){ ll mid=start+(end-start)/2; Lazy[index+1]+=Lazy[index]; Lazy[index+2*(mid-start+1)]+=Lazy[index]; } } Lazy[index]=0; } void Update(ll index, ll start, ll end, ll L, ll R, ll Value){ Push(index, start, end); if(R<start or L>end){ return; } if(L<=start and end<=R){ Lazy[index]+=Value; Push(index, start, end); return; } ll mid=start+(end-start)/2; Update(index+1,start,mid,L,R,Value); Update(index+2*(mid-start+1),mid+1,end,L,R,Value); Tree[index]=Tree[index+1]+Tree[index+2*(mid-start+1)]; } ll Query(ll index, ll start, ll end, ll L, ll R){ Push(index,start,end); if(R<start or L>end){ return 0; } if(L<=start and end<=R){ return Tree[index]; } ll mid=start+(end-start)/2; ll Left=Query(index+1,start,mid,L,R); ll Right=Query(index+2*(mid-start+1),mid+1,end,L,R); return Left+Right; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); ll n,t; cin >> n >> t; deque<ll> lst(n); for(ll i=0;i<n;i++){ cin >> lst[i]; } sort(lst.begin(),lst.end()); lst.erase(unique(lst.begin()+1,lst.end()),lst.end()); n=lst.size(); ll SmallestValue=lst[0]; for(ll i=1;i<n;i++){ ll Diff=abs(lst[i]-SmallestValue); ll Multiplier=Diff/t; ll Remainder=Diff%t; lst[i]-=Multiplier*t; if(Remainder>=t-Remainder){ lst[i]-=t; } } sort(lst.begin(),lst.end()); ll mid=lst[0]+(lst[n-1]-lst[0])/2; cout << max(abs(lst[0]-mid),abs(lst[n-1]-mid)); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...