답안 #583726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583726 2022-06-26T07:03:32 Z n3rm1n Addk (eJOI21_addk) C++17
36 / 100
42 ms 724 KB
#include<bits/stdc++.h>

using namespace std;
long long n,k;
long long a[10001];
long long t[40001];
long long p[10001];
void read()
{
    cin>>n>>k;
    for(long long i=1;i<=n;i++)
        {cin>>a[i];p[i]=p[i-1]+a[i];}
}
void make_tree(long long i,long long l,long long r)
{
    if(l>r)return;
    if(l==r)
    {
        t[i]=a[l];
        return;
    }
    long long m=(l+r)/2;
    make_tree(i*2,l,m);
    make_tree(i*2+1,m+1,r);
    t[i]=t[i*2]+t[i*2+1];
}
long long query(long long i,long long l,long long r,long long ql,long long qr)
{
    if(l>r||r<ql||l>qr)return 0;
    if(l>=ql&&qr>=r)return t[i];
    long long m=(l+r)/2;
    return query(i*2,l,m,ql,m)+query(i*2+1,m+1,r,m+1,qr);
}
void test()
{
    for(long long i=1;i<=n*4;i++)
        cout<<t[i]<<" ";
    cout<<endl;
}
long long q;
void solve()
{
    cin>>q;
    for(long long i=1;i<=q;i++)
    {
        long long c;
        cin>>c;
        if(c==1)
        {
            long long help;
            cin>>help;
        }
        else
        {
            long long ql,qr,m;
            cin>>ql>>qr>>m;
            long long ans=0;
            for(long long j=ql;j<=qr-m+1;j++)
            {
                ans+=p[j+m-1]-p[j-1];
                //ans+=query(1,1,n,j,j+m-1);
                //cout<<j<<" "<<j+m-1<<" "<<query(1,1,n,j,j+m-1)<<"||";
            }
            cout<<ans<<endl;
        }
    }
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	read();
	//make_tree(1,1,n);
	//test();
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 260 KB Output is correct
3 Correct 5 ms 340 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 12 ms 340 KB Output is correct
6 Correct 15 ms 452 KB Output is correct
7 Correct 20 ms 444 KB Output is correct
8 Correct 25 ms 492 KB Output is correct
9 Correct 42 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -