답안 #721259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
721259 2023-04-10T14:54:57 Z groshi Addk (eJOI21_addk) C++17
100 / 100
156 ms 11808 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
int drzewo[3][2000000];
int t[2000000];
int a[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;
}
void ustaw(int x,int co,int ile)
{
    x+=pot;
    drzewo[co][x]=ile;
    x/=2;
    while(x>0)
    {
        drzewo[co][x]=drzewo[co][x*2]+drzewo[co][x*2+1];
        x/=2;
    }
}
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{
            for(int i=1;i<=k;i++)
                cin>>a[i];
            for(int i=1;i<k;i++)
            {
                ustaw(a[i],0,a[i]*t[a[i+1]]);
                ustaw(a[i],1,(n-a[i]+1)*t[a[i+1]]);
                ustaw(a[i],2,t[a[i+1]]);
            }
            ustaw(a[k],0,a[k]*t[a[1]]);
            ustaw(a[k],1,(n-a[k]+1)*t[a[1]]);
            ustaw(a[k],2,t[a[1]]);
            int pom=t[a[1]];
            for(int i=1;i<=k;i++)
                t[a[i]]=t[a[i+1]];
            t[a[k]]=pom;
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 5 ms 628 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 5 ms 852 KB Output is correct
7 Correct 8 ms 852 KB Output is correct
8 Correct 8 ms 980 KB Output is correct
9 Correct 11 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1944 KB Output is correct
2 Correct 33 ms 2584 KB Output is correct
3 Correct 47 ms 3752 KB Output is correct
4 Correct 93 ms 6740 KB Output is correct
5 Correct 155 ms 8156 KB Output is correct
6 Correct 117 ms 8000 KB Output is correct
7 Correct 114 ms 8008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 4556 KB Output is correct
2 Correct 120 ms 9436 KB Output is correct
3 Correct 156 ms 11808 KB Output is correct
4 Correct 139 ms 10768 KB Output is correct