Submission #415563

# Submission time Handle Problem Language Result Execution time Memory
415563 2021-06-01T08:40:34 Z 조영욱(#7635) Road Construction (JOI21_road_construction) C++17
0 / 100
8619 ms 178316 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<long long,long long> P;
P arr[250000];
const int sz=262144;

struct Node {
    vector<long long> v;
};

Node merge(Node l,Node r) {
    Node ret;
    int lind=0;
    int rind=0;
    for(int i=0;i<10;i++) {
        if (l.v[lind]<r.v[rind]) {
            ret.v.push_back(l.v[lind++]);
        }
        else {
            ret.v.push_back(r.v[rind++]);
        }
    }
    return ret;
}

Node emp;

struct SegmentTree {
    Node seg[sz*2];
    Node sum(int l,int r,int node=1,int nodel=0,int noder=sz-1) {
        if (r<nodel||l>noder) {
            return emp;
        }
        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 i,long long val) {
        i+=sz;
        Node cpy=emp;
        cpy.v[0]=val;
        seg[i]=merge(seg[i],cpy);
        while (i>1) {
            i/=2;
            seg[i]=merge(seg[i*2],seg[i*2+1]);
        }
    }
};

Node pl(Node a,long long x) {
    for(int i=0;i<10;i++) {
        a.v[i]+=x;
    }
    return a;
}

SegmentTree st1;
SegmentTree st2;

int main(void) {
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<1;i++) {
        emp.v.push_back(1e12);
    }
    vector<int> press;
    for(int i=0;i<n;i++) {
        scanf("%lld %lld",&arr[i].first,&arr[i].second);
        press.push_back(arr[i].second);
    }
    sort(press.begin(),press.end());
    press.erase(unique(press.begin(),press.end()),press.end());
    sort(arr,arr+n);
    for(int i=0;i<sz*2;i++) {
        st1.seg[i]=emp;
        st2.seg[i]=emp;
    }
    Node ret=emp;
    for(int i=0;i<n;i++) {
        int y=lower_bound(press.begin(),press.end(),arr[i].second)-press.begin();
        if (y!=0) {
            ret=merge(ret,pl(st1.sum(0,y-1),arr[i].first+arr[i].second));
        }
        ret=merge(ret,pl(st2.sum(y,sz-1),arr[i].first-arr[i].second));
        st1.update(y,-arr[i].first-arr[i].second);
        st2.update(y,-arr[i].first+arr[i].second);
    }
    for(int i=0;i<k;i++) {
        printf("%lld\n",ret.v[i]);
    }
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
road_construction.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         scanf("%lld %lld",&arr[i].first,&arr[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 166 ms 117948 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 240 ms 126840 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8619 ms 178064 KB Output is correct
2 Correct 8118 ms 178316 KB Output is correct
3 Correct 102 ms 57796 KB Output is correct
4 Runtime error 236 ms 126944 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8619 ms 178064 KB Output is correct
2 Correct 8118 ms 178316 KB Output is correct
3 Correct 102 ms 57796 KB Output is correct
4 Runtime error 236 ms 126944 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 166 ms 117948 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 166 ms 117948 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -