답안 #1043925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043925 2024-08-05T04:16:58 Z 사상 최고의 알고리즘(#11062) Measures (CEOI22_measures) C++17
100 / 100
311 ms 25712 KB
#include <bits/stdc++.h>
using namespace std;

const int sz=262144;
const long long INF=1e15;

struct Seg {
    int type;
    long long seg[sz*2];
    long long lazy[sz*2];
    void init(int t) {
        type=t;
        for(int i=1;i<sz*2;i++) {
            if (type==0) {
                seg[i]=INF;
            }
            else {
                seg[i]=-INF;
            }
        }
    }
    long long merge(long long a,long long b) {
        return type==0?min(a,b):max(a,b);
    }
    void prop(int node) {
        if (lazy[node]!=0) {
            seg[node]+=lazy[node];
            if (node<sz) {
                lazy[node*2]+=lazy[node];
                lazy[node*2+1]+=lazy[node];
            }
            lazy[node]=0;
        }
    }
    long long sum(int l,int r,int node=1,int nodel=0,int noder=sz-1) {
        prop(node);
        if (r<nodel||l>noder) {
            return INF*(1-type*2);
        }
        if (l<=nodel&&noder<=r) {
            return seg[node];
        }
        int mid=(nodel+noder)/2;
        return merge(sum(l,r,node*2,nodel,mid),sum(l,r,node*2+1,mid+1,noder));
    }
    void update(int l,int r,long long val,int node=1,int nodel=0,int noder=sz-1) {
        prop(node);
        if (r<nodel||l>noder) {
            return;
        }
        if (l<=nodel&&noder<=r) {
            lazy[node]+=val;
            prop(node);
            return;
        }
        int mid=(nodel+noder)/2;
        update(l,r,val,node*2,nodel,mid);
        update(l,r,val,node*2+1,mid+1,noder);
        seg[node]=merge(seg[node*2],seg[node*2+1]);
    }
};

Seg seg1;
Seg seg2;
int n,m;
long long d;
typedef pair<long long,int> P;
vector<P> v;
long long arr[200010];

int main(void) {
    scanf("%d %d %lld",&n,&m,&d);
    for(int i=0;i<n;i++) {
        scanf("%lld",&arr[i]);
        v.push_back(P(arr[i],i));
    }
    for(int i=0;i<m;i++) {
        scanf("%lld",&arr[n+i]);
        v.push_back(P(arr[n+i],n+i));
    }
    sort(v.begin(),v.end());
    seg1.init(0);
    seg2.init(1);
    long long ret=0;
    for(int i=0;i<n+m;i++) {
        int ind=lower_bound(v.begin(),v.end(),P(arr[i],i))-v.begin();
        seg1.update(ind+1,sz-1,-d);
        seg2.update(ind+1,sz-1,-d);
        long long lmx=seg2.sum(0,ind-1);
        long long rmn=seg1.sum(ind+1,sz-1);
        long long now=seg1.sum(ind,ind);
        int idx=(INF-now)/d;
        long long val=arr[i]-d*idx;
        ret=max(ret,val-rmn);
        ret=max(ret,lmx-val);
        ret=max(ret,lmx-rmn);
        seg1.update(ind,ind,INF-now-INF+val);
        seg2.update(ind,ind,INF-now+INF+val);
        if (i>=n) {
            if (ret%2==0) {
                printf("%lld ",ret/2);
            }
            else {
                printf("%lld.5 ",ret/2);
            }
        }
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     scanf("%d %d %lld",&n,&m,&d);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         scanf("%lld",&arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         scanf("%lld",&arr[n+i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12892 KB Output is correct
2 Correct 5 ms 12892 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 4 ms 12748 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12892 KB Output is correct
2 Correct 5 ms 12892 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 4 ms 12748 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
9 Correct 276 ms 22200 KB Output is correct
10 Correct 291 ms 22728 KB Output is correct
11 Correct 186 ms 22456 KB Output is correct
12 Correct 219 ms 22268 KB Output is correct
13 Correct 183 ms 21944 KB Output is correct
14 Correct 196 ms 22200 KB Output is correct
15 Correct 275 ms 22472 KB Output is correct
16 Correct 193 ms 22456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 194 ms 23468 KB Output is correct
2 Correct 208 ms 25272 KB Output is correct
3 Correct 196 ms 25564 KB Output is correct
4 Correct 189 ms 23224 KB Output is correct
5 Correct 191 ms 24328 KB Output is correct
6 Correct 202 ms 23736 KB Output is correct
7 Correct 200 ms 24296 KB Output is correct
8 Correct 224 ms 23316 KB Output is correct
9 Correct 194 ms 23640 KB Output is correct
10 Correct 198 ms 25596 KB Output is correct
11 Correct 199 ms 24120 KB Output is correct
12 Correct 199 ms 24760 KB Output is correct
13 Correct 186 ms 23476 KB Output is correct
14 Correct 220 ms 25060 KB Output is correct
15 Correct 191 ms 24760 KB Output is correct
16 Correct 187 ms 22552 KB Output is correct
17 Correct 206 ms 24364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 194 ms 23468 KB Output is correct
2 Correct 208 ms 25272 KB Output is correct
3 Correct 196 ms 25564 KB Output is correct
4 Correct 189 ms 23224 KB Output is correct
5 Correct 191 ms 24328 KB Output is correct
6 Correct 202 ms 23736 KB Output is correct
7 Correct 200 ms 24296 KB Output is correct
8 Correct 224 ms 23316 KB Output is correct
9 Correct 194 ms 23640 KB Output is correct
10 Correct 198 ms 25596 KB Output is correct
11 Correct 199 ms 24120 KB Output is correct
12 Correct 199 ms 24760 KB Output is correct
13 Correct 186 ms 23476 KB Output is correct
14 Correct 220 ms 25060 KB Output is correct
15 Correct 191 ms 24760 KB Output is correct
16 Correct 187 ms 22552 KB Output is correct
17 Correct 206 ms 24364 KB Output is correct
18 Correct 303 ms 24248 KB Output is correct
19 Correct 311 ms 25016 KB Output is correct
20 Correct 202 ms 25336 KB Output is correct
21 Correct 233 ms 23224 KB Output is correct
22 Correct 249 ms 23500 KB Output is correct
23 Correct 204 ms 23484 KB Output is correct
24 Correct 303 ms 24248 KB Output is correct
25 Correct 193 ms 23224 KB Output is correct
26 Correct 300 ms 22972 KB Output is correct
27 Correct 293 ms 25712 KB Output is correct
28 Correct 234 ms 23520 KB Output is correct
29 Correct 251 ms 25564 KB Output is correct
30 Correct 229 ms 22964 KB Output is correct
31 Correct 243 ms 25372 KB Output is correct
32 Correct 217 ms 24736 KB Output is correct
33 Correct 305 ms 22544 KB Output is correct
34 Correct 233 ms 24320 KB Output is correct