Submission #721172

# Submission time Handle Problem Language Result Execution time Memory
721172 2023-04-10T12:40:49 Z groshi Addk (eJOI21_addk) C++17
0 / 100
26 ms 3500 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>>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{
                wyn1=zap(x,y-m,0)-zap(x,y-m,2)*(x-1);
                wyn2=zap(x+m,y,1)-zap(x+m,y,2)*(n-y);
                wyn3=zap(y-m+1,x+m-1,2)*(y-m+1-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 1876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 3500 KB Output isn't correct
2 Halted 0 ms 0 KB -