Submission #476959

# Submission time Handle Problem Language Result Execution time Memory
476959 2021-09-29T11:56:08 Z David_M Addk (eJOI21_addk) C++14
0 / 100
96 ms 5060 KB
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define FF first.first
#define FS first.second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e18, P=998244353;

ll q=1, n, m, x, y, z, l, r, k, t, a[N], b[N], f[N], ans, o, u, Ans[N];
vector <pair<pii,int> > p;
pair<ll, ll> T[N];

void upd(int x, int val, int v=1, int L=1, int R=n){
    int M=L+R>>1;
    if(L==R){T[v]={val,val*x};return;}
    if(x<=M)upd(x, val, v<<1, L, M);
    else    upd(x, val, v<<1|1, M+1, R);
    T[v]={T[v<<1].F+T[v<<1|1].F, T[v<<1].S+T[v<<1|1].S};
}

ll get(int l, int r, int v=1, int L=1, int R=n){
    if(R<l || L>r)return 0;
    if(L>=l && R<=r)return T[v].S-T[v].F*(l-1);
    int M=L+R>>1;
    return get(l, r, v<<1, L, M)+get(l, r, v<<1|1, M+1, R);
}



main(){ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>n>>k;

	for (int i=1; i<=n; i++)cin>>a[i],upd(i,a[i]);
	

	cin>>q;

	while(q--){
        cin>>t;
        if(t==1){
            for (int i=0; i<k; i++)cin>>b[i];b[k]=b[0];
            for (int i=0; i<k; i++)a[b[i]]=a[b[i+1]],upd(b[i],a[b[i]]);
        }else{
            cin>>l>>r>>m;
            //cout<<l<<" "<<r<<'\n'<<min(r-m+2, l+m)<<" "<<r<<'\n'<<max(r-m+2, l+m)<<" "<<r<<'\n';
            cout<<get(l,r)-get(min(r-m+2, l+m),r)-get(max(r-m+2, l+m), r)<<'\n';
        }
	}


}

Compilation message

Main.cpp: In function 'void upd(int, int, int, int, int)':
Main.cpp:18:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |     int M=L+R>>1;
      |           ~^~
Main.cpp: In function 'long long int get(int, int, int, int, int)':
Main.cpp:28:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |     int M=L+R>>1;
      |           ~^~
Main.cpp: At global scope:
Main.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main(){ios_base::sync_with_stdio(false), cin.tie(0);
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:46:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   46 |             for (int i=0; i<k; i++)cin>>b[i];b[k]=b[0];
      |             ^~~
Main.cpp:46:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   46 |             for (int i=0; i<k; i++)cin>>b[i];b[k]=b[0];
      |                                              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Incorrect 4 ms 588 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 1996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 5060 KB Output isn't correct
2 Halted 0 ms 0 KB -