제출 #683166

#제출 시각아이디문제언어결과실행 시간메모리
683166arnold518Measures (CEOI22_measures)C++17
100 / 100
314 ms32212 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e5+10; const ll INF = 1e18; int N, M, D; pll A[MAXN+10]; struct SEG { pll tree[MAXN*4+10]; ll tree2[MAXN*4+10]; ll lazy[MAXN*4+10]; SEG() { fill(tree, tree+MAXN*4+10, pll(-INF, INF)); fill(tree2, tree2+MAXN*4+10, -INF); } void busy(int node, int tl, int tr) { if(!lazy[node]) return; tree[node].first+=lazy[node]; tree[node].second+=lazy[node]; if(tl!=tr) { lazy[node*2]+=lazy[node]; lazy[node*2+1]+=lazy[node]; } lazy[node]=0; } void update(int node, int tl, int tr, int l, int r, ll k, bool n) { busy(node, tl, tr); if(r<tl || tr<l) return; if(l<=tl && tr<=r) { if(n) { tree[node].first+=INF; tree[node].second-=INF; tree2[node]=0; } lazy[node]+=k; busy(node, tl, tr); return; } int mid=tl+tr>>1; update(node*2, tl, mid, l, r, k, n); update(node*2+1, mid+1, tr, l, r, k, n); tree[node].first=max(tree[node*2].first, tree[node*2+1].first); tree[node].second=min(tree[node*2].second, tree[node*2+1].second); tree2[node]=max({tree2[node*2], tree2[node*2+1], tree[node*2].first-tree[node*2+1].second}); } ll query() { return tree2[1]; } }seg; int pos[MAXN+10]; int main() { scanf("%d%d%d", &N, &M, &D); for(int i=1; i<=N; i++) scanf("%lld", &A[i].first), A[i].second=i; for(int i=1; i<=M; i++) scanf("%lld", &A[N+i].first), A[N+i].second=N+i; M+=N; sort(A+1, A+M+1); for(int i=1; i<=M; i++) pos[A[i].second]=i; for(int i=1; i<=M; i++) { seg.update(1, 1, M, pos[i], M, -D, 0); seg.update(1, 1, M, pos[i], pos[i], A[pos[i]].first, 1); if(i>N) { ll t=seg.query(); if(t%2==0) printf("%lld ", t/2); else printf("%lld.5 ", t/2); } } }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In member function 'void SEG::update(int, int, int, int, int, ll, bool)':
Main.cpp:51:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |   int mid=tl+tr>>1;
      |           ~~^~~
Main.cpp: In function 'int main()':
Main.cpp:68:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |  scanf("%d%d%d", &N, &M, &D);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:69:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |  for(int i=1; i<=N; i++) scanf("%lld", &A[i].first), A[i].second=i;
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:70:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |  for(int i=1; i<=M; i++) scanf("%lld", &A[N+i].first), A[N+i].second=N+i;
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...