Submission #721257

# Submission time Handle Problem Language Result Execution time Memory
721257 2023-04-10T14:50:12 Z groshi Addk (eJOI21_addk) C++17
92 / 100
147 ms 10480 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
int drzewo[3][2000000];
int t[2000000];
int pot=1;
int zap(int x,int y,int co)
{
    if(y<x)
        return 0;
    int wynik=0;
    x+=pot;
    y+=pot;
    wynik=drzewo[co][x];
    if(x!=y)
        wynik+=drzewo[co][y];
    while(x/2!=y/2)
    {
        if(x%2==0)
            wynik+=drzewo[co][x+1];
        if(y%2==1)
            wynik+=drzewo[co][y-1];
        x/=2;
        y/=2;
    }
    return wynik;
}
int32_t main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n,k;
    cin>>n>>k;
    while(pot<=n)
        pot*=2;
    pot--;
    for(int i=1;i<=n;i++)
        cin>>t[i];
    for(int i=1;i<=n;i++)
        drzewo[0][i+pot]=i*t[i];
    for(int i=n;i>=1;i--)
        drzewo[1][i+pot]=(n-i+1)*t[i];
    for(int i=1;i<=n;i++)
        drzewo[2][i+pot]=t[i];
    for(int i=pot;i>=1;i--)
        for(int j=0;j<=2;j++)
            drzewo[j][i]=drzewo[j][i*2]+drzewo[j][i*2+1];
    int zapp;
    cin>>zapp;
    while(zapp--)
    {
        int co,x,y,m;
        cin>>co;
        if(co==2)
        {
            cin>>x>>y>>m;
            int wyn1=0,wyn2=0,wyn3=0;
            int dl=y-x+1;
            if(m>dl/2)
                m=dl-m+1;
            wyn3=zap(x+m-1,y-m+1,2)*m;
            wyn1=zap(x,x+m-2,0)-zap(x,x+m-2,2)*(x-1);
            wyn2=zap(y-m+2,y,1)-zap(y-m+2,y,2)*(n-y);
            cout<<wyn1+wyn2+wyn3<<"\n";
        }
        else{
            cin>>x;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 4 ms 592 KB Output is correct
6 Correct 7 ms 852 KB Output is correct
7 Correct 6 ms 852 KB Output is correct
8 Correct 8 ms 980 KB Output is correct
9 Correct 11 ms 1296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2004 KB Output is correct
2 Correct 37 ms 3096 KB Output is correct
3 Correct 44 ms 4616 KB Output is correct
4 Correct 84 ms 8308 KB Output is correct
5 Correct 147 ms 10480 KB Output is correct
6 Correct 122 ms 10244 KB Output is correct
7 Correct 114 ms 10244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 3544 KB Output isn't correct
2 Halted 0 ms 0 KB -