Submission #2998924
Source Code Expand
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10;
ll n,k;
ll sum[N*4];
void update(int now)
{
sum[now]=sum[now*2]+sum[now*2+1];
}
void build(int now,int l,int r)
{
if(l==r)
{
cin>>sum[now];
// cout<<sum[now]<<endl;
return;
}
int mid=(l+r)>>1;
build(now*2,l,mid);
build(now*2+1,mid+1,r);
update(now);
}
ll query(int now,int l,int r,int cl,int cr)
{
//cout<<now<<" "<<l<<" "<<r<<" "<<cl<<" "<<cr<<endl;
//cout<<"*****"<<endl;
ll ans=0;
if(l>cr||r<cl)return 0;
if(cl<=l&&r<=cr)
{
return sum[now];
}
int mid=(l+r)>>1;
ans+=query(now*2,l,mid,cl,cr);
ans+=query(now*2+1,mid+1,r,cl,cr);
return ans;
}
ll ans;
int main()
{
cin>>n>>k;
build(1,1,n);
for(int i=1;i<=n-k+1;i++)
{
ans+=query(1,1,n,i,i+k-1);
//cout<<ans<<endl;
}
cout<<ans<<endl;
}
Submission Info
Submission Time |
|
Task |
C - 総和 |
User |
CN_FSMX |
Language |
C++ (GCC 5.4.1) |
Score |
100 |
Code Size |
806 Byte |
Status |
AC |
Exec Time |
53 ms |
Memory |
2304 KB |
Judge Result
Set Name |
sample |
subtask1 |
subtask2 |
Score / Max Score |
0 / 0 |
50 / 50 |
50 / 50 |
Status |
|
|
|
Set Name |
Test Cases |
sample |
sample01.txt, sample02.txt |
subtask1 |
00.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, sample01.txt, sample02.txt |
subtask2 |
00.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, sample01.txt, sample02.txt, sample01.txt, sample02.txt |
Case Name |
Status |
Exec Time |
Memory |
00.txt |
AC |
1 ms |
256 KB |
01.txt |
AC |
1 ms |
256 KB |
02.txt |
AC |
1 ms |
256 KB |
03.txt |
AC |
2 ms |
256 KB |
04.txt |
AC |
2 ms |
256 KB |
05.txt |
AC |
2 ms |
256 KB |
06.txt |
AC |
2 ms |
256 KB |
07.txt |
AC |
2 ms |
256 KB |
08.txt |
AC |
2 ms |
256 KB |
09.txt |
AC |
2 ms |
256 KB |
10.txt |
AC |
2 ms |
256 KB |
11.txt |
AC |
49 ms |
2304 KB |
12.txt |
AC |
53 ms |
2304 KB |
13.txt |
AC |
48 ms |
2304 KB |
14.txt |
AC |
43 ms |
2304 KB |
15.txt |
AC |
39 ms |
2304 KB |
16.txt |
AC |
38 ms |
2304 KB |
17.txt |
AC |
50 ms |
2304 KB |
18.txt |
AC |
35 ms |
2304 KB |
19.txt |
AC |
47 ms |
2304 KB |
sample01.txt |
AC |
1 ms |
256 KB |
sample02.txt |
AC |
1 ms |
256 KB |