//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("bmi,bmi2,lzcnt,popcnt")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
//#pragma expected_value
//#pragma isolated_call
//#pragma disjoint
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
//#define double long double
#define Fi first
#define Se second
#define Rep(i,a,b) for (int i=a;i<=b;++i)
#define Repu(i,b,a) for (int i=b;i>=a;--i)
#define pb push_back
#define ms(a,i) memset(a,i,sizeof(a))
#define sz size()
#define mp make_pair
#define endl '\n'
#define sef setprecision(6)<<fixed
#define cer cout<<"cak"<<endl;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<double> va;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<va> vva;
//const double EPS=1e-9;
const double PI=acos(-1);
const long long oo=1e18;
const int MN=1e6+5;
const int mod=1e9+7;
using cd=complex<double>;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> index_set;
int n,k,q;
int a[MN];
int pre[MN];
int sum[MN];
int doi[15];
int calc1(int l,int r) {
if(l>r) return 0;
return pre[r] - pre[l-1] - (l-1)*(sum[r]-sum[l-1]);
}
int calc2(int l,int r) {
if(l>r) return 0;
return (r+1)*(sum[r]-sum[l-1]) - (pre[r]-pre[l-1]);
}
int calc3(int l,int r) {
if(l>r) return 0;
return sum[r] - sum[l-1];
}
signed main() {
//freopen(".inp","r",stdin); freopen(".out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>k;
Rep(i,1,n) cin>>a[i];
Rep(i,1,n) {
pre[i] = pre[i-1] + i*a[i];
sum[i] = sum[i-1] + a[i];
}
cin>>q;
Rep(qu,1,q) {
int type;
cin>>type;
if(type==1) {
Rep(i,1,k) cin>>doi[i];
}
else {
int l,r,m; cin>>l>>r>>m;
int dr=min((l+r-1)/2,l+m-2);
int tl=max((l+r+1)/2+1,r-m+2);
if(dr>tl) swap(dr,tl);
if(dr==tl) tl++;
int ans = calc1(l,dr) + calc2(tl,r) + calc3(dr+1,tl-1)*(dr-m);
if(r-l+1==m) ans = sum[r] - sum[l-1];
cout<<ans<<endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
1492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
3992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |