# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
845587 |
2023-09-06T14:19:45 Z |
elotelo966 |
Addk (eJOI21_addk) |
C++17 |
|
277 ms |
12788 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY 10000000
#define mod 100000000
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mid (start+end)/2
int pre[100005],tree[400005],lazy[400005];
vector<int> v;
inline void push(int node,int start,int end){
if(lazy[node]==0)return ;
tree[node]+=lazy[node]*(end-start+1);
if(start!=end){
lazy[node*2]+=lazy[node];
lazy[node*2+1]+=lazy[node];
}
lazy[node]=0;
}
inline void build(int node,int start,int end){
lazy[node]=0;
if(start>end)return ;
if(start==end){tree[node]=pre[start];return;}
build(node*2,start,mid),build(node*2+1,mid+1,end);
tree[node]=tree[node*2]+tree[node*2+1];
}
inline int query(int node,int start,int end,int l,int r){
if(start>end || start>r || end<l)return 0;
push(node,start,end);
if(start>=l && end<=r)return tree[node];
return query(node*2,start,mid,l,r)+query(node*2+1,mid+1,end,l,r);
}
inline void update(int node,int start,int end,int l,int r,int val){
push(node,start,end);
if(start>end || start>r || end<l)return ;
if(start>=l && end<=r){
lazy[node]+=val;
push(node,start,end);
return ;
}
update(node*2,start,mid,l,r,val),update(node*2+1,mid+1,end,l,r,val);
tree[node]=tree[node*2]+tree[node*2+1];
}
int32_t main(){
faster
int n,k,deg;cin>>n>>k;
int dizi[n+1];
dizi[0]=0;
for(int i=1;i<=n;i++){
cin>>dizi[i];
}
for(int i=1;i<=n;i++){
pre[i]=pre[i-1]+dizi[i];
}
build(1,1,n);
int q;cin>>q;
while(q--){
int ty;cin>>ty;
if(ty==1){
for(int i=0;i<k;i++){
cin>>deg;
v.push_back(deg);
}
update(1,1,n,v[0],v[k-1]-1,-dizi[v[0]]);
int gec=dizi[v[0]];
for(int i=1;i<v.size();i++){
update(1,1,n,v[i-1],v[i]-1,dizi[v[i]]);
dizi[v[i-1]]=dizi[v[i]];
}
dizi[v[k-1]]=gec;
v.clear();
}
else{
int l,r,m;cin>>l>>r>>m;
int cev=query(1,1,n,1,r)-query(1,1,n,1,l+m-2);
if(l-2>0)deg=query(1,1,n,1,l-2);
else deg=0;
cev-=query(1,1,n,1,r-m)-deg;
cout<<cev<<'\n';
}
}
return 0;
}
Compilation message
Main.cpp: In function 'int32_t main()':
Main.cpp:70:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i=1;i<v.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
3 ms |
2652 KB |
Output is correct |
5 |
Correct |
5 ms |
2648 KB |
Output is correct |
6 |
Correct |
4 ms |
2904 KB |
Output is correct |
7 |
Correct |
5 ms |
2908 KB |
Output is correct |
8 |
Correct |
6 ms |
3152 KB |
Output is correct |
9 |
Correct |
9 ms |
5080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
5720 KB |
Output is correct |
2 |
Correct |
29 ms |
6368 KB |
Output is correct |
3 |
Correct |
37 ms |
6820 KB |
Output is correct |
4 |
Correct |
65 ms |
9300 KB |
Output is correct |
5 |
Correct |
95 ms |
11144 KB |
Output is correct |
6 |
Correct |
91 ms |
10872 KB |
Output is correct |
7 |
Correct |
92 ms |
10856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
7768 KB |
Output is correct |
2 |
Correct |
131 ms |
10320 KB |
Output is correct |
3 |
Correct |
277 ms |
12788 KB |
Output is correct |
4 |
Correct |
126 ms |
11344 KB |
Output is correct |