UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212629#3835. 数列变换18112606231100547ms12896kbC++111.7kb2024-10-19 15:35:532024-10-19 18:36:27

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = (x << 1) + (x << 3) + (ch ^ 48);
        ch = getchar();
    }
    return x * f;
}
int n,m,q,a[1000001],b[1000001],suma,l,r,w,st,ed,sumb[1000001],ansb[1000001],maxn,minn;
signed main()
{
    n = read();
    m = read();
    q=read();
    for (int i = 1; i <= n; i++)
    {
        a[i] = read();
        suma += a[i]*(i%2?1:-1);
    }
    for (int i = 1; i <= m; i++)
    {
        b[i] = read();
        sumb[i] = sumb[i-1]+b[i]*(i%2?-1:1);
    }
    //puts("");
    for(int i=0;i<=m-n;i++)
    {
        ansb[i]=(sumb[i+n]-sumb[i])*(i%2?-1:1);
        //cout<<sumb[i+n]<<' '<<sumb[i]<<endl;
    }
    //for(int i=0;i<=m-n;i++)
    //{
    //    cout<<ansb[i]<<' '<<suma<<endl;
    //}
    sort(ansb,ansb+m-n+1);
    int wz=lower_bound(ansb,ansb+m-n+1,-suma)-ansb;
    printf("%lld\n",min(abs(ansb[wz]+suma),abs(ansb[wz-1]+suma)));
    while (q--)
    {
        l=read();
        r=read();
        w=read();
        if (l>r)
            swap(l,r);
        if(l==r)
        {
            if (l%2)
                suma+=w;
            else
                suma-=w;
        }
        else if(l%2&&r%2)
        {
            suma+=w;
        }
        else if(l%2==0&&r%2==0)
        {
            suma-=w;
        }
        //cout<<suma<<endl;
        int wz=lower_bound(ansb,ansb+m-n+1,-suma)-ansb;
        printf("%lld\n",min(abs(ansb[wz]+suma),abs(ansb[wz-1]+suma)));
    }
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

60 100 100
-316328 -2972020 4147918 -2643712 5196821 -5222175 1264902 8662970 -2730531 -8400380 1752...

output:

455979
455979
455979
455979
455979
455979
455979
455978
455972
455965
455965
455966
455968
455968
45...

result:

ok 101 numbers

Test #2:

score: 10
Accepted
time: 0ms
memory: 1180kb

input:

60 100 100
-91495081 53528918 88188311 -74258245 -66799442 -49965187 -7645181 -44417344 -39124339 58...

output:

8190568
8190568
2233401
7193707
4795408
4795408
4795408
1179783
1179783
11716793
11716793
1174744
12...

result:

ok 101 numbers

Test #3:

score: 10
Accepted
time: 0ms
memory: 1240kb

input:

1000 2500 5000
-98154920 -53785940 -74265506 3679870 37683369 24917745 -92422231 8884275 -81169328 9...

output:

107041
107041
107041
107041
107041
797385
791567
791567
1392939
1392939
1392939
961800
819544
819544...

result:

ok 5001 numbers

Test #4:

score: 10
Accepted
time: 0ms
memory: 1272kb

input:

2500 4000 5000
-86828824 -50617376 6649487 69943467 -93306697 -6567886 -95650455 -85852213 -15523487...

output:

573304251
573304251
595203952
694987953
680315084
728371583
782122701
782122701
825849022
915038502
...

result:

ok 5001 numbers

Test #5:

score: 10
Accepted
time: 2ms
memory: 1292kb

input:

3000 5000 5000
-80381922 79980974 3347134 -52177075 -66392451 -488143 4131024 -16842638 -12729315 27...

output:

5066626
3060888
6135718
46352
94807
94807
165432
448427
448427
55386
627630
627630
594397
39417
2439...

result:

ok 5001 numbers

Test #6:

score: 10
Accepted
time: 71ms
memory: 4696kb

input:

50000 150000 150000
-89108065 59343099 -97978207 -67393513 -61842201 75668265 80917778 -98775029 -68...

output:

367594
148610
759512
244446
136839
83073
302547
215766
162990
40016
136848
422047
89049
98658
343712...

result:

ok 150001 numbers

Test #7:

score: 10
Accepted
time: 71ms
memory: 4696kb

input:

100000 150000 150000
-90110621 -17018593 7329896 -25804788 -19546767 -52028202 -97290926 -68550106 7...

output:

9264157442
9362400005
9287250254
9368053211
9411500623
9385277837
9435812025
9436874552
9380121876
9...

result:

ok 150001 numbers

Test #8:

score: 10
Accepted
time: 69ms
memory: 3520kb

input:

50000 100000 150000
-99258224 -12730699 -92233936 -33566265 -39312752 -10318733 -19880407 69141095 -...

output:

128989
103327
95283
173047
317772
307164
307164
9121
9121
69178
244
144419
144419
190182
190182
2618...

result:

ok 150001 numbers

Test #9:

score: 10
Accepted
time: 78ms
memory: 4692kb

input:

80000 150000 150000
-75009884 -81911105 -96479382 73988847 18413858 58416050 60800947 -59117071 -596...

output:

343226
343226
382382
236941
997
997
997
997
997
997
997
166301
506372
488607
506128
506128
117946
13...

result:

ok 150001 numbers

Test #10:

score: 10
Accepted
time: 256ms
memory: 12896kb

input:

263999 500000 500000
-7398172 -81831034 99536754 -91618991 31225194 -18967333 -15490068 31299796 -52...

output:

447372176
412567992
370536501
370536501
370536501
370536501
432667527
432667527
411201828
411201828
...

result:

ok 500001 numbers

Extra Test:

score: 0
Extra Test Passed