답안 #583743

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583743 2022-06-26T07:20:36 Z serkanrashid Addk (eJOI21_addk) C++14
0 / 100
2000 ms 1864 KB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const long long maxn=1e5+5;
long long n,k,q;
long long a[maxn],b[32];
long long tree[4*maxn];
long long ql,qr;

void make_tree(long long v, long long l, long long r)
{
    if(l==r)
    {
        tree[v]=a[r];
        return;
    }
    long long mid=(l+r)/2;
    make_tree(v*2,l,mid);
    make_tree(v*2+1,mid+1,r);
    tree[v]=tree[v*2]+tree[v*2+1];
}

long long query(long long v, long long l, long long r)
{
    if(r<ql||l>qr||l>r) return 0;
    if(l>=ql&&r<=qr) return tree[v];
    long long mid=(l+r)/2;
    return query(v*2,l,mid)+query(v*2+1,mid+1,r);
}
void read()
{
    cin >> n >> k;
    for(long long i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    cin >> q;
    make_tree(1,1,n);
    long long ty,l,r,m;
    for(long long i=1;i<=q;i++)
    {
        cin >> ty;
        if(ty==1)
        {
            cin >> b[1];
        }
        else
        {
            cin >> l >> r >> m;
            long long sum=0;
            long long ch=0;
            long long j=l;
            for(j;j<m+l;j++)
            {
                if(j>r-j+l) break;
                ql=j;
                qr=j;
                ch=query(1,1,n);
                //cout << i << " " << ch << endl;
                sum+=((j-l+1)*ch);
                ql=r-j+l;
                qr=r-j+l;
                ch=query(1,1,n);
                //cout << i << " " << ch << endl;
                sum+=((j-l+1)*ch);
            }
            //cout << i << endl;
            ql=l+m;
            qr=r-(l+m)+l+1;
            ch=0;
            if(ql<=qr) ch=query(1,1,n);
            //cout <<  ch << endl;
            //cout << "++++++++++++" << endl;
            sum+=(ch*m);
            cout << sum << endl;
        }
    }
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	read();
return 0;
}
/*
8 1
7 2 5 1 9 3 4 6
3
2 2 7 4
1 1
2 2 7 3
*/

Compilation message

Main.cpp: In function 'void read()':
Main.cpp:55:17: warning: statement has no effect [-Wunused-value]
   55 |             for(j;j<m+l;j++)
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2066 ms 1120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2056 ms 1864 KB Time limit exceeded
2 Halted 0 ms 0 KB -