QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#520948#1140. Distributing Candieskimmoqt0 2262ms66624kbC++204.2kb2024-08-15 18:01:162024-08-15 18:01:17

Judging History

你现在查看的是最新测评结果

  • [2024-08-15 18:01:17]
  • 评测
  • 测评结果:0
  • 用时:2262ms
  • 内存:66624kb
  • [2024-08-15 18:01:16]
  • 提交

answer

#include "candies.h"

#include <bits/stdc++.h>
using namespace std;

const int MX=2e5+5;

typedef long long ll;

struct node {
        ll sum, res[2], pref[2], suff[2];

        node() {
                sum=0;
                res[0]=1e18;
                res[1]=-1e18;

                pref[0]=1e18;
                pref[1]=-1e18;

                suff[0]=1e18;
                suff[1]=-1e18;
        }
};

node merge(node a, node b) {
        node c;
        c.sum=a.sum+b.sum;
        c.res[0]=min(a.res[0],b.res[0]);
        c.res[1]=max(a.res[1],b.res[1]);

        c.pref[0]=min(a.pref[0],a.sum+b.pref[0]);
        c.suff[0]=min(b.suff[0],b.sum+a.suff[0]);
        c.pref[1]=max(a.pref[1],a.sum+b.pref[1]);
        c.suff[1]=max(b.suff[1],b.sum+a.suff[1]);

        c.res[0]=min(c.res[0],c.pref[0]);
        c.res[0]=min(c.res[0],c.suff[0]);
        c.res[1]=max(c.res[1],c.pref[1]);
        c.res[1]=max(c.res[1],c.suff[1]);

        return c;
}

struct segtree {
        node t[4*MX];

        void upd(int v, int l, int r, int pos, int x) {
                if(pos<l||r<pos) return;
                if(l==r) {
                        node c;
                        c.sum=x;
                        c.res[0]=c.res[1]=x;
                        c.pref[0]=c.pref[1]=x;
                        c.suff[0]=c.suff[1]=x;
                        t[v]=c;
                        return;
                }
                int m=(l+r)/2;
                upd(v*2,l,m,pos,x);
                upd(v*2+1,m+1,r,pos,x);
                t[v]=merge(t[v*2],t[v*2+1]);
        }

        node que(int v, int l, int r, int ql, int qr) {
                if(qr<l || r<ql) return node();
                if(ql<=l && qr>=r) return t[v];
                int m=(l+r)/2;
                return merge(que(v*2,l,m,ql,qr),que(v*2+1,m+1,r,ql,qr));
        }
} st;

int N,Q;
vector<int> ans;
vector<pair<int,int>> line[MX];

std::vector<int> distribute_candies(std::vector<int> C, std::vector<int> L,
                                    std::vector<int> R, std::vector<int> V) {   

        N=C.size();
        Q=L.size();
        ans.resize(N);

        for(int i=0;i<Q;i++) {
                line[L[i]].push_back({V[i],i});
                line[R[i]+1].push_back({0,i});
        }

        for(int i=0;i<N;i++) {
                for(auto [v,j]:line[i]) {
                        st.upd(1,0,Q-1,j,v);
                }
                
                int l=0,r=Q-1,x=-1,y=-1;
                while(l<=r) {
                        int m=(l+r)/2;
                        if(st.que(1,0,Q-1,m,Q-1).res[0]<=-C[i]) {
                                x=m,l=m+1;
                        } else {
                                r=m-1;
                        }
                }
                l=0,r=Q-1;
                while(l<=r) {
                        int m=(l+r)/2;
                        if(st.que(1,0,Q-1,m,Q-1).res[1]>=C[i]) {
                                y=m,l=m+1;
                        } else {
                                r=m-1;
                        }
                }

                if(x<y) {
                        int l=y,r=Q-1,p=0;
                        while(l<=r) {
                                int m=(l+r)/2;
                                if(st.que(1,0,Q-1,y,m).res[1]>=C[i]) {
                                        p=m,r=m-1; 
                                } else{
                                        l=m+1;
                                }
                        }
                        ll s=st.que(1,0,Q-1,p+1,Q-1).sum;
                        ans[i]=C[i]+s;
                } else {
                        int l=x,r=Q-1,p=0;
                        while(l<=r) {
                                int m=(l+r)/2;
                                if(st.que(1,0,Q-1,x,m).res[0]<=-C[i]) {
                                        p=m,r=m-1; 
                                } else{
                                        l=m+1;
                                }
                        }
                        ll s=st.que(1,0,Q-1,p+1,Q-1).sum;
                        ans[i]=s;
                }
        }

        return ans;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 3ms
memory: 49416kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
8
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
8
0 7 1
0 7 1
0 7 300000000
0 7 994967293
0 7 1
0 7 1000000000
0 7 1000000000
0 7 1000000000

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

result:

ok 3 lines

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 49476kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
10
283 43634 101056 10340 6009 5133 30 2 3677888 210
10
1 8 26416
2 7 -51219
2 4 17793
3 7 75426
3 7 22307
1 1 60258
3 7 -29824
0 8 24839
2 8 -60304
0 1 -26411

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
0 42062 -68891 0 0 0 0 0 -35465 0

result:

wrong answer 3rd lines differ - expected: '0 17223 0 0 0 0 0 0 0 0', found: '0 42062 -68891 0 0 0 0 0 -35465 0'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 2262ms
memory: 66624kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
200000
11408901 370732653 37843 28 53693 15782410 103 297546 1112427 170319071 26 1 6172 11614171 431 884673599 1 3 50085 154 57 28200 145886 898969 74758 72 845768 6 69787 11 31012465 55362 253 2363145 47186217 1103 19622 594 7867 1 4299 28130 48 4689582 12 ...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
87153 87153 37843 28 53693 406667 103 301387 766665 971468 26 1 10013 1257294 431 1536484 1 3 67864 154 57 28200 145886 898969 74758 72 845768 6 69787 11 3043755 55362 253 2363145 3459533 1103 19622 594 7867 1 4299 28130 48 4317336 12 431 123 4531465 4806 ...

result:

wrong answer 3rd lines differ - expected: '87153 87153 37843 28 53693 406...46468 9 1756 429030 247071 1629', found: '87153 87153 37843 28 53693 406...46468 9 1756 429030 247071 1629'

Subtask #3:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 47948kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
1000
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -251 -2...

result:

wrong answer 3rd lines differ - expected: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 4ms
memory: 49452kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
10
11 440 51 41 11 1 3 108 148 14
10
0 9 60
0 9 -9
0 9 -30
0 9 41
0 9 82
0 9 69
0 9 -79
0 9 -39
0 9 72
0 9 41

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
11 148 92 41 11 1 3 108 143 14

result:

wrong answer 3rd lines differ - expected: '11 208 51 41 11 1 3 108 143 14', found: '11 148 92 41 11 1 3 108 143 14'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%