Submission #475638

#TimeUsernameProblemLanguageResultExecution timeMemory
475638nickmet2004Addk (eJOI21_addk)C++11
100 / 100
244 ms8696 KiB
#include<bits/stdc++.h> #define f first #define s second #define int long long using namespace std; const int N = 1e6 + 5; int n , k , q,a[N] , Y[11] ,H[N]; pair<int, int> F[2*N]; void upd(int i , int d1 , int d2){ while(i <= n) { F[i].f += d1 , F[i].s += d2; i += i & -i; } } pair<int , int> get(int i){ pair<int , int> sum = {0,0}; while(i) { sum.f += F[i].f , sum.s += F[i].s; i -= i & -i; } return sum; } main (){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for(int i = 1; i <= n; ++i)cin >> a[i]; for(int i = 1; i<= n; ++i) upd(i , a[i] , a[i]*i); cin >> q; while(q--){ int tp; cin >> tp; if(tp==1){ for(int i = 0; i < k; ++i)cin >> Y[i]; sort(Y , Y + k); for(int i = 0; i < k; ++i) H[Y[i]] = a[Y[i]]; for(int i = 1; i < k; ++i) swap(a[Y[i]] , a[Y[i - 1]]); for(int i = 0; i < k; ++i) upd(Y[i] , a[Y[i]] - H[Y[i]] , (a[Y[i]] - H[Y[i]])*Y[i]); }else { int l , r , m; cin >> l >> r >> m; m = min(m , r - l - m + 2); int ans = 0; pair<int,int> gR = get(l + m - 1); pair<int,int> gL = get(l - 1); ans += (gR.s - gL.s - (l - 1) * (gR.f - gL.f)); ans += (get(r - m).f - get(l + m - 1).f)*m; gL = get(r-m); gR = get(r); ans += (r+1)*(gR.f-gL.f)-(gR.s-gL.s); cout << ans << endl; } } }

Compilation message (stderr)

Main.cpp:25:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 |  main (){
      |  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...