#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void ngha();
const int mod2=1e9+7;
const int mod1=998244353;
struct ib
{
int a;
int b;
};
struct icd
{
int a,b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c, d,e;
};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
//#ifndef ONLINE_JUDGE
// fin(task),fou(task);
//#endif
NHP
//modwwe
// cin>>res;
ngha(),down
checktime
}
ib t[400001];
int a[100001];
int b[11];
void build(int node,int l,int r)
{
if(l==r)
{ t[node].a=a[l];
t[node].b=a[l]*l;
return;
}
int mid=l+r>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
t[node].a=t[node<<1].a+t[node<<1|1].a;
t[node].b=t[node<<1].b+t[node<<1|1].b;
}
void upd(int node,int l,int r,int l1,int r1,int k)
{
if(l>r1||r<l1) return;
if(l>=l1&&r<=r1)
{
t[node].a=k;
t[node].b=k*l;
return;
}
int mid=l+r>>1;
upd(node<<1,l,mid,l1,r1,k);
upd(node<<1|1,mid+1,r,l1,r1,k);
t[node].a=t[node<<1].a+t[node<<1|1].a;
t[node].b=t[node<<1].b+t[node<<1|1].b;
}
ib get(int node,int l,int r,int l1,int r1)
{ if(l1>r1) return {0,0};
if(l>r1||r<l1) return {0,0};
if(l>=l1&&r<=r1) return {t[node].a,t[node].b};
int mid=l+r>>1;
ib xa=get(node<<1,l,mid,l1,r1);
ib xb=get(node<<1|1,mid+1,r,l1,r1);
return {xa.a+xb.a,xa.b+xb.b};
}
void ngha()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i];
build(1,1,n);
cin>>m;
while(m--)
{
cin>>dem;
if(dem==1)
{
for(int i=1;i<=k;i++)
cin>>b[i];
for(int i=2;i<=k;i++)
{
upd(1,1,n,b[i-1],b[i-1],a[b[i]]);
a[b[i-1]]=a[b[i]];
}
upd(1,1,n,b[k],b[k],a[b[1]]);
a[b[k]]=a[b[1]];
}
else
{
cin>>s1>>s4>>mx;
s2=s1+mx-1;
s3=s4-mx+1;
if(s2>s3) swap(s2,s3);
s5=0;
ib sx=get(1,1,n,s1,s2-1);
s5=sx.b-sx.a*(s1-1);
sx=get(1,1,n,s2,s3);
s6=0;
s6+=sx.a*(s2-s1+1);
sx=get(1,1,n,s3+1,s4);
s7=0;
s7+=sx.a*(s4+1)-sx.b;
cout<<s5+s6+s7,down
}
}
}
Compilation message
Main.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main()
| ^~~~
Main.cpp: In function 'void build(long long int, long long int, long long int)':
Main.cpp:66:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
66 | int mid=l+r>>1;
| ~^~
Main.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int, long long int)':
Main.cpp:81:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
81 | int mid=l+r>>1;
| ~^~
Main.cpp: In function 'ib get(long long int, long long int, long long int, long long int, long long int)':
Main.cpp:91:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
91 | int mid=l+r>>1;
| ~^~
Main.cpp: In function 'void ngha()':
Main.cpp:99:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
99 | for(int i=1;i<=n;i++)
| ^~~
Main.cpp:101:10: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
101 | build(1,1,n);
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2532 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2616 KB |
Output is correct |
5 |
Correct |
6 ms |
2652 KB |
Output is correct |
6 |
Correct |
8 ms |
2640 KB |
Output is correct |
7 |
Correct |
9 ms |
2648 KB |
Output is correct |
8 |
Correct |
11 ms |
2648 KB |
Output is correct |
9 |
Correct |
15 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
3412 KB |
Output is correct |
2 |
Correct |
50 ms |
3700 KB |
Output is correct |
3 |
Correct |
72 ms |
6252 KB |
Output is correct |
4 |
Correct |
135 ms |
9556 KB |
Output is correct |
5 |
Correct |
187 ms |
10568 KB |
Output is correct |
6 |
Correct |
174 ms |
10472 KB |
Output is correct |
7 |
Correct |
176 ms |
10504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
92 ms |
7092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |