QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#534774#5080. Folding StickPrimeszAC ✓36ms7676kbC++203.2kb2024-08-27 16:09:302024-08-27 16:09:30

Judging History

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

  • [2024-08-27 16:09:30]
  • 评测
  • 测评结果:AC
  • 用时:36ms
  • 内存:7676kb
  • [2024-08-27 16:09:30]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define fs first
#define sc second
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef priority_queue <ll, vector<ll>, greater<ll>> pqmin;
const double EPS = 1e-16;
const int INF = 2e9;
const int MOD = 1e9+7;

const int p=1e5+5;
int a[p];

struct SegtreeLazy {
    int n;
    int defval;
    vector<int>t;
    vector<int>lazy;
    vector<int>a;

    SegtreeLazy(int n,int defval) : n(n),defval(defval) {
        a.resize(n+5);
        t.resize(4*n+5);
        lazy.assign(4*n+5,0);
    }

    int merge(int x, int y) {
        return max(x, y);
    }

    void build(int v, int s, int e) {
        if (s == e) {
            t[v] = a[s];
            return;
        }
        int mid = (s + e) / 2;
        build(v * 2, s, mid);
        build(v * 2 + 1, mid + 1, e);
        t[v] = merge(t[v * 2], t[v * 2 + 1]);
    }

    void push(int v, int s, int e) {
        if (lazy[v] == 0 || s == e) return;
        t[v * 2] = merge(t[v*2],lazy[v]);
        lazy[v * 2] = merge(lazy[v * 2],lazy[v]);
        t[v * 2 + 1] = merge(t[v * 2 + 1],lazy[v]);
        lazy[v * 2 + 1] = merge(lazy[v * 2 + 1],lazy[v]);
        lazy[v] = 0;
    }

    void update(int v, int s, int e, int l, int r, int val) {
        if (l > r) return;
        if (s == l && e == r) {
            lazy[v] = merge(lazy[v],val);
            t[v] = merge(t[v],val);
            return;
        }
        push(v, s, e);
        int mid = (s + e) / 2;
        update(v * 2, s, mid, l, min(r, mid), val);
        update(v * 2 + 1, mid + 1, e, max(l, mid + 1), r, val);
        t[v] = merge(t[v * 2], t[v * 2 + 1]);
    }

    int get(int v, int s, int e, int l, int r) {
        if (l > r) return defval;
        if (l <= s && e <= r) return t[v];
        push(v, s, e);
        int mid = (s + e) / 2;
        int p1 = get(v * 2, s, mid, l, min(r, mid));
        int p2 = get(v * 2 + 1, mid + 1, e, max(l, mid + 1), r);
        return merge(p1, p2);
    }
};

void solve(){
    int n;
    cin>>n;
    vector<int>pref(n+1,0);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pref[i]=pref[i-1]+a[i];
    }
    SegtreeLazy sgtree=SegtreeLazy(n+1,0);
    for(int i=1;i<=n+1;i++){
        sgtree.a[i]=1;
    }
    int ans=INF;
    sgtree.build(1,1,n+1);
    for(int i=2;i<=n;i++){
        int previdx=sgtree.get(1,1,n+1,i,i);
        int sum=pref[i-1]-pref[previdx-1];
        int sumright=pref[n]-pref[i-1];
        ans=min(ans,max(sum,sumright));
        int nxtidx=lower_bound(pref.begin(),pref.end(),sum+pref[i-1])-pref.begin();
//        cout<<"! "<<i<<" "<<previdx<<" "<<sum<<" "<<sumright<<" "<<nxtidx<<" "<<ans<<endl;
        if(nxtidx==n+1)continue;
        sgtree.update(1,1,n+1,nxtidx+1,n+1,i);
    }
    int previdx=sgtree.get(1,1,n+1,n+1,n+1);
    int sum=pref[n]-pref[previdx-1];
    ans=min(ans,sum);
    cout<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t=1;

    while(t--){
        solve();
    }

    cin.get();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3824kb

input:

4
3 2 2 3

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

5
1 1 1 1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

7
1 3 2 3 4 2 2

output:

6

result:

ok single line: '6'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

9
5 6 3 4 8 8 2 2 5

output:

9

result:

ok single line: '9'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

10
5 6 3 4 8 6 2 1 8 5

output:

9

result:

ok single line: '9'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

10
5 8 1 2 6 8 4 3 6 5

output:

14

result:

ok single line: '14'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

3
4 2 1

output:

4

result:

ok single line: '4'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

14
7 2 2 2 2 3 4 1 3 5 4 3 1 6

output:

8

result:

ok single line: '8'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

35
46 93 64 27 72 55 77 11 17 17 79 83 74 26 32 101 54 112 92 111 77 60 51 19 105 11 68 7 100 49 88 54 106 80 57

output:

366

result:

ok single line: '366'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

150
87 121 113 120 23 32 107 92 107 40 61 29 100 120 30 62 61 53 103 40 110 56 16 38 12 55 11 71 109 26 60 72 19 121 74 97 11 87 117 32 58 40 104 91 101 118 19 59 79 21 40 111 100 36 105 58 122 61 33 75 66 11 65 97 84 28 90 18 76 68 70 58 112 100 95 28 61 25 24 110 93 117 80 119 105 52 66 66 101 77 ...

output:

765

result:

ok single line: '765'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

200
52 59 17 69 83 28 76 102 79 67 66 19 14 114 28 50 68 88 92 23 84 38 71 51 77 76 30 82 67 18 34 41 92 23 72 35 27 94 96 74 12 92 32 60 56 42 123 38 14 99 20 83 16 111 47 101 33 34 81 111 123 108 53 45 73 59 11 26 65 59 111 86 81 73 86 106 101 37 109 56 91 91 26 77 122 99 118 42 43 103 118 19 116 ...

output:

842

result:

ok single line: '842'

Test #12:

score: 0
Accepted
time: 3ms
memory: 3684kb

input:

9999
96 57 105 94 47 39 95 44 103 98 84 99 94 109 65 83 113 102 57 67 13 81 113 31 123 55 27 76 74 94 12 40 88 91 52 78 60 76 118 43 92 102 13 118 76 47 64 99 80 83 108 14 120 16 12 105 82 24 102 99 52 121 81 72 14 74 108 58 117 24 72 14 56 58 122 50 70 114 87 60 61 21 54 58 103 56 75 51 112 27 23 5...

output:

6191

result:

ok single line: '6191'

Test #13:

score: 0
Accepted
time: 3ms
memory: 4240kb

input:

19999
364 153 315 275 342 148 43 15 31 494 383 145 452 419 49 244 487 500 394 168 130 300 285 420 304 437 302 515 88 318 13 18 169 156 151 162 259 487 360 63 143 251 245 330 175 429 145 62 158 195 268 33 88 399 134 373 463 510 402 15 244 498 200 82 185 314 360 75 187 327 291 383 67 492 175 298 394 4...

output:

35836

result:

ok single line: '35836'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

10
72 16900 3273 13695 13698 18297 6723 3013 11727 1900

output:

28033

result:

ok single line: '28033'

Test #15:

score: 0
Accepted
time: 27ms
memory: 7676kb

input:

100000
1511 6583 419 6978 9102 9356 1176 4709 2333 5984 4834 4643 2167 7795 2260 8768 7907 6309 7623 6207 2867 8219 7096 3982 3431 8783 6193 220 6832 9494 9386 9407 607 4057 54 4566 10171 8780 8632 1031 6272 3391 3605 5147 3625 1180 9275 9111 4943 4997 9918 2845 9728 4924 990 338 7311 4335 3658 2454...

output:

1566426

result:

ok single line: '1566426'

Test #16:

score: 0
Accepted
time: 23ms
memory: 7348kb

input:

100000
20000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

36000

result:

ok single line: '36000'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

4
10 11 11 1

output:

11

result:

ok single line: '11'

Test #18:

score: 0
Accepted
time: 32ms
memory: 7260kb

input:

100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

36000

result:

ok single line: '36000'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

30
7 8 15 15 15 20 25 28 36 36 42 44 53 54 56 61 63 69 69 71 74 83 91 99 102 108 115 116 118 126

output:

126

result:

ok single line: '126'

Test #20:

score: 0
Accepted
time: 36ms
memory: 7620kb

input:

100000
3 5 6 15 23 30 38 44 51 59 64 73 78 82 89 97 97 103 110 115 121 126 135 140 149 151 151 160 163 167 176 180 182 187 191 196 199 202 205 210 214 223 227 232 239 244 245 254 260 263 267 268 276 285 293 296 301 310 318 327 331 335 343 343 344 347 350 356 359 364 370 378 384 386 390 392 396 396 4...

output:

3230521

result:

ok single line: '3230521'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

50
19799 18740 18718 17504 17208 16816 16668 15755 15006 14203 13902 13287 12522 11547 10358 9189 9018 8664 8118 7986 7296 6345 6167 6060 5564 5278 4684 4044 3509 3028 2636 2444 1839 1226 1106 346 18872 17974 17716 16674 16366 15548 15227 15187 14074 13671 13104 12354 11823 11572

output:

90073

result:

ok single line: '90073'

Test #22:

score: 0
Accepted
time: 35ms
memory: 7348kb

input:

100000
19989 19988 19986 19979 19975 19971 19959 19952 19949 19937 19931 19923 19918 19915 19914 19907 19903 19899 19891 19891 19888 19887 19879 19871 19863 19862 19860 19851 19840 19839 19828 19819 19817 19810 19805 19804 19799 19798 19798 19796 19793 19793 19785 19774 19769 19757 19752 19749 19743...

output:

3343362

result:

ok single line: '3343362'

Test #23:

score: 0
Accepted
time: 25ms
memory: 7348kb

input:

99999
1 1 3 1 2 3 1 3 2 2 1 1 1 2 2 3 3 2 3 3 3 3 1 1 2 3 1 2 3 1 1 2 3 2 2 2 2 2 2 1 1 1 3 3 2 2 1 1 3 1 2 3 3 3 1 2 1 2 3 3 2 2 2 1 1 3 1 2 1 3 2 2 2 2 2 3 1 2 1 1 1 3 1 2 2 2 3 1 3 3 2 3 2 3 3 2 1 3 1 2 3 3 2 3 2 2 2 2 1 2 1 2 3 1 3 3 2 1 2 3 2 3 3 2 3 3 1 1 2 3 2 3 2 2 2 1 1 3 2 2 2 2 3 2 1 2 1 ...

output:

38003

result:

ok single line: '38003'

Test #24:

score: 0
Accepted
time: 28ms
memory: 7340kb

input:

99998
1 1 3 1 3 1 1 2 2 2 2 2 2 2 1 3 1 3 2 2 3 3 2 3 1 1 2 2 1 3 1 1 1 2 2 1 1 1 1 3 1 2 3 2 2 3 3 3 1 2 3 1 1 1 2 3 3 1 2 1 3 1 1 2 2 2 3 2 3 2 2 3 1 2 1 3 2 2 1 3 3 2 1 3 1 2 1 2 3 2 1 2 2 1 2 1 1 3 1 1 3 1 1 1 1 3 1 3 2 3 2 1 3 2 2 2 3 3 2 2 3 2 2 3 2 1 1 1 2 3 3 3 2 3 1 2 2 3 1 2 3 2 3 3 2 3 1 ...

output:

37779

result:

ok single line: '37779'

Test #25:

score: 0
Accepted
time: 25ms
memory: 7632kb

input:

100000
1 1 3 1 3 3 1 2 3 2 3 3 3 1 1 2 1 1 3 3 2 2 2 1 3 3 2 2 1 1 2 3 3 1 3 2 1 2 1 2 2 2 2 1 3 1 1 3 3 3 1 3 1 2 1 1 2 1 3 2 2 1 1 3 3 2 1 1 1 1 1 2 1 1 2 3 3 3 1 2 1 1 2 3 1 1 2 1 3 3 3 2 2 3 1 1 3 2 1 3 3 1 2 2 1 1 2 1 2 2 3 2 3 2 3 1 1 2 3 1 1 3 2 3 1 1 2 1 2 3 2 3 2 2 3 1 1 2 2 2 1 3 3 1 2 2 2...

output:

36664

result:

ok single line: '36664'

Test #26:

score: 0
Accepted
time: 36ms
memory: 7340kb

input:

99889
11295 17088 17664 16236 15038 16260 17011 19396 10420 12902 14445 12290 14929 13624 12072 16414 11952 19340 19696 17710 15033 18276 12428 16782 14507 11881 17904 11155 13160 16208 10930 11772 13104 14506 17243 12858 18643 14235 15905 12866 15153 15133 19235 15809 12180 18949 15973 10528 14593 ...

output:

4144015

result:

ok single line: '4144015'

Test #27:

score: 0
Accepted
time: 36ms
memory: 7352kb

input:

99199
12958 15770 11023 19231 12276 16117 15616 13973 16212 16495 14697 11942 11425 14328 12922 16910 10822 16131 11260 18679 12821 10985 10031 15500 11852 14705 17747 18670 10538 14750 11082 12471 13344 18330 17886 16861 16442 11154 10096 10106 19008 15889 14177 14281 12936 19297 19780 17459 19327 ...

output:

4161319

result:

ok single line: '4161319'

Test #28:

score: 0
Accepted
time: 1ms
memory: 3692kb

input:

2901
10008 10001 10001 10010 10000 10001 10007 10005 10000 10004 10008 10007 10003 10010 10002 10004 10007 10001 10006 10007 10008 10007 10003 10001 10002 10001 10008 10002 10001 10006 10006 10008 10008 10004 10003 10001 10003 10006 10004 10008 10006 10004 10008 10000 10002 10004 10001 10001 10004 1...

output:

490229

result:

ok single line: '490229'

Test #29:

score: 0
Accepted
time: 1ms
memory: 3692kb

input:

3058
10004 10008 10006 10009 10003 10002 10010 10005 10003 10009 10003 10007 10008 10009 10010 10005 10001 10006 10000 10002 10004 10005 10000 10004 10006 10001 10002 10005 10004 10007 10000 10001 10009 10010 10004 10004 10001 10002 10001 10005 10007 10002 10003 10005 10008 10000 10005 10009 10000 1...

output:

500279

result:

ok single line: '500279'

Test #30:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

9
3 1 3 1 2 2 2 2 1

output:

4

result:

ok single line: '4'

Test #31:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

11
3 1 3 1 2 2 2 2 1 3 2

output:

4

result:

ok single line: '4'

Test #32:

score: 0
Accepted
time: 32ms
memory: 7284kb

input:

99999
2 2 3 3 3 1 4 2 2 4 3 1 3 1 1 3 2 3 3 3 3 4 1 1 1 3 3 1 1 4 4 4 3 3 4 4 2 2 3 2 2 2 2 3 1 4 2 2 3 4 2 3 3 1 2 1 1 2 2 3 2 4 3 2 4 2 4 2 2 2 3 1 3 1 2 4 2 4 1 3 3 3 1 4 4 2 3 3 2 2 2 1 4 3 1 3 4 4 4 1 1 2 4 1 2 4 4 4 1 2 3 3 2 1 4 3 4 3 1 4 4 3 3 2 1 3 1 1 4 4 3 1 1 2 1 1 1 4 4 4 2 2 3 4 3 2 2 ...

output:

38337

result:

ok single line: '38337'

Test #33:

score: 0
Accepted
time: 33ms
memory: 7300kb

input:

99998
4 4 3 3 4 3 1 2 1 4 3 1 3 2 2 2 4 1 2 4 2 4 4 2 3 4 4 4 1 3 3 3 2 4 1 2 3 2 2 3 3 3 1 3 3 3 2 1 3 1 4 1 3 1 2 4 3 3 4 1 4 3 4 4 4 2 2 2 4 4 3 4 4 2 1 1 2 1 3 1 3 3 2 3 2 1 1 1 2 3 1 3 2 4 4 1 3 1 3 1 3 4 1 4 3 3 1 3 2 3 3 1 3 2 4 4 3 4 4 1 4 1 3 4 1 2 2 3 3 2 3 2 3 3 3 2 2 1 3 2 1 2 1 3 4 3 4 ...

output:

38336

result:

ok single line: '38336'