Submission #721170

# Submission time Handle Problem Language Result Execution time Memory
721170 2023-04-10T12:30:24 Z groshi Addk (eJOI21_addk) C++17
0 / 100
24 ms 5048 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)
{
    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>>x>>y>>m;
        if(co==2)
        {
            int wyn1=0,wyn2=0,wyn3=0;
            int dl=y-x+1;
            if((dl+1)/2>=m)
            {
                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);
            }
            else{
                if(dl%2==0)
                {
                    int mid=(x+y)/2;
                    wyn1=zap(x,mid,0)-zap(x,mid,2)*(x-1);
                    wyn2=zap(mid+1,y,1)-zap(mid+1,y,2)*(n-y);
                }
                else{
                    int mid=(x+y)/2;
                    wyn1=zap(x,mid-1,0)-zap(x,mid,2)*(x-1);
                    wyn2=zap(mid+1,y,1)-zap(mid+1,y,2)*(n-y);
                    wyn3=zap(mid,mid,2)*(mid-x+1);
                }
            }
            cout<<wyn1+wyn2+wyn3<<"\n";
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 2280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 5048 KB Output isn't correct
2 Halted 0 ms 0 KB -