이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define repp(i,x,n) for(int i=x;i<=n;i++)
#define repo(i,x,n) for(int i=x;i>=n;i--)
#define cy cout<<"Yes"<<endl
#define cn cout<<"No"<<endl
#define r0 return 0
#define fi first
#define se second
#define mp make_pair
#define liow ios_base::sync_with_stdio(false);cin.tie(NULL)
#define jelek cout<<"jelek"<<endl
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define pi pair<pair<int,int>,pair<int,int>>
#define p3 pair<int,pair<int,int>>
#define p4 pair<pii,pii>
#define fl fflush(stdout)
#define lb long double
using namespace std;
const int mod=1e9+7,maxn=1e5+5,N=(1<<17),INF=1e18;
int arr[maxn];
int pre[maxn],pre2[maxn],suf[maxn],suf2[maxn];
void solve(){
int n,k;cin>>n>>k;
repp(i,1,n) {
cin>>arr[i];
pre[i]=pre[i-1]+arr[i];
pre2[i]=pre2[i-1]+i*arr[i];
}
for(int i=n;i>=1;i--){
suf[i]=suf[i+1]+arr[i];
suf2[i]=suf2[i+1]+(n-i+1)*arr[i];
}
int q;cin>>q;
while(q--){
int ans=0;
int t,g;cin>>t;
if(t==1) repp(i,1,k) cin>>g;
else {
int l,r,m;cin>>l>>r>>m;
int ah=min(m,r-l+1-m+1);
int midl=l+ah,midr=r-ah;
int a=l,b=l+ah-1,c=(r-ah+1),d=r;
int ans=(ah*(pre[c]-pre[b-1])+(pre2[b-1]-pre2[l-1]-(l-1)*(pre[b-1]-pre[l-1])) + suf2[c+1]-suf2[r+1]-(n-r)*(pre[r]-pre[c]));
cout<<ans<<endl;
// if(midl>midr) swap(midl,midr);
// int bnyk=midl-l+1;
// ans+=(pre[midr]-pre[midl-1])*(bnyk);
// ans+=pre2[b]-pre2[a-1]-(pre[b]-pre[a-1])*(b-ah);
// ans+=suf2[c]-suf2[d+1]-(suf[c]-suf[d+1])*(b-ah);
// cout<<ans<<endl;
}
}
}
signed main(){
liow;
int t=1;
// cin>>t;
while(t--){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void solve()':
Main.cpp:44:11: warning: unused variable 'midl' [-Wunused-variable]
44 | int midl=l+ah,midr=r-ah;
| ^~~~
Main.cpp:44:21: warning: unused variable 'midr' [-Wunused-variable]
44 | int midl=l+ah,midr=r-ah;
| ^~~~
Main.cpp:45:11: warning: unused variable 'a' [-Wunused-variable]
45 | int a=l,b=l+ah-1,c=(r-ah+1),d=r;
| ^
Main.cpp:45:35: warning: unused variable 'd' [-Wunused-variable]
45 | int a=l,b=l+ah-1,c=(r-ah+1),d=r;
| ^
Main.cpp:38:9: warning: unused variable 'ans' [-Wunused-variable]
38 | int ans=0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |