#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100'010;
vector<ll> fen1(MAXN, 0);
vector<ll> fen2(MAXN, 0);
void update(vector<ll> &bit, ll in, ll val)
{
while(in < MAXN)
{
bit[in]+=val;
in+=in&(-in);
}
}
long long query(vector<ll> &bit, ll in)
{
ll sum = 0;
while(in > 0)
{
sum+=bit[in];
in-=in&(-in);
}
return sum;
}
int main () {
int n, k;
cin >> n >> k;
long long arr[n+1];
//, prefix1[n+1] = {0}, prefix2[n+1] = {0};
for(int i = 1;i<=n;i++) {
cin >> arr[i];
update(fen1, i, arr[i]);
update(fen2, i, arr[i]*i);
//prefix1[i] = prefix1[i-1] + arr[i];
//prefix2[i] = prefix2[i-1] + arr[i]*i;
}
int q;
cin >> q;
while(q--) {
int type;
cin >> type;
if(type == 1) {
ll change[k];
ll change2[k];
for(int i= 0;i<k;i++)
{
cin >> change[i];
update(fen1, change[i], -arr[change[i]]);
update(fen2, change[i], -change[i]*arr[change[i]]);
}
change2[k-1] = change[0];
for(int i = 0;i<k-1;i++)
{
change2[i] = change[i+1];
}
for(int i = 0;i<k-1;i++)
{
swap(arr[change2[i]], arr[change[i]]);
}
for(int i = 0;i<k-1;i++)
{
update(fen1, change[i], arr[change[i]]);
update(fen2, change[i], change[i]*arr[change[i]]);
}
}
else {
int ans = 0;
int l, r, m;
cin >> l >> r >> m;
m = min(r-l-m + 2, m);
long long a = (query(fen2, l+m-1) - query(fen2, l-1))-(query(fen1,l+m-1) - query(fen1, l-1))*(l-1);
long long b = (query(fen1, r-m) - query(fen1, l+m-1))*m;
long long c = (query(fen1, r) - query(fen1, r-m))*(r+1) - (query(fen2, r) - query(fen2, r-m));
cout<<a+b+c<<endl;
}
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:67:8: warning: unused variable 'ans' [-Wunused-variable]
67 | int ans = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
2676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
160 ms |
4712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |