Submission #1034786

# Submission time Handle Problem Language Result Execution time Memory
1034786 2024-07-25T18:16:17 Z vuh Addk (eJOI21_addk) C++14
92 / 100
2000 ms 6300 KB
#include <bits/stdc++.h>
//       www      //
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define ll long long
#define pb push_back
#define pqi priority_queue <pair<int,int>,greater<int>>
#define vi vector <int>
#define vll vector<ll>
#define fori for(int i=0 ;i<n ;i++)
#define forj for(int j=0 ;j<n ;j++)
#define rep(i,a,b) for (int i=a; i<=b; ++i)
#define rev(i,a,b) for (int i=a; i>=b; --i)
#define cina fori{cin>>a[i];}
#define all(v) v.begin(), v.end()
#define endl "\n"
//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
vi dx = {0, 0, -1, 1}, dy = {-1, 1, 0, 0};
vi dx2 = {1, 1, 0, -1, -1, -1, 0, 1}, dy2 = {0, 1, 1, 1, 0, -1, -1, -1};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 10; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return mod_add(arr[0], 0, b);} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m
ll combination(ll n, ll r, ll m, ll *fact, ll *ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
ll getRandomNumber(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);} 
/*--------------------------------------------------------------------------------------------------------------------------*/
const int inf = INT_MAX;
const ll mod = 1e9 + 7;
const int sz = 1e5+5;
const int b = 41;
//      vuh      //
vi parent,checkcycle;
vector <pair <int,int>> variants;
vector <vector <int>> g;
vector <bool> check;
int a[sz];
ll st[4 * sz],lz[4 * sz];
bool bo = 0;
int sa[sz], pos[sz], tmp[sz], lcp[sz];
void build(int l,int r,int v){
    if(l == r){
        st[v] = a[l];
        return;
    }
    int mid = (l + r) / 2;
    build(l,mid,v * 2);
    build(mid + 1,r,v * 2 + 1);
    st[v] = st[v * 2] + st[v * 2 + 1];
}
void uptade(ll l,ll r,ll v,ll x,ll w){
    if(x < l || x > r)
        return;
    if(l == r){
        st[v] = w;
        return;
    }
    ll mid = (l + r) / 2;
    uptade(l,mid,v * 2,x,w);
    uptade(mid + 1,r,v * 2 + 1,x,w);
    st[v] = st[v * 2] + st[v * 2 + 1];
}
ll getans(ll ql,ll qr,ll l,ll r,ll v){
    if(ql > r || qr < l)
        return 0;
    if(ql <= l && qr >= r)
        return st[v];
    ll mid = (l + r) / 2;
    ll q1 = getans(ql,qr,l,mid,v * 2);
    ll q2 = getans(ql,qr,mid + 1,r,v * 2 + 1);
    return q1 + q2;
}
bool f() {
    //off
}
//const int dx[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void solve() {
	int n, k;
    cin  >> n >> k;
    vector<int> a(n + 1);
    vector<ll> pref (n + 1);
    vector<ll> ppref (n + 1);
    for (int i = 1; i <= n; ++i) cin >> a[i], pref[i] = pref[i - 1] + a[i];
    for (int i = 1; i <= n; ++i) ppref[i] = ppref[i - 1] + pref[i];
    int q;
    cin >> q;
    while (q--) {
        int type;
        cin >> type;
        if (type == 2) {
            int l, r, x;
            cin >> l >> r >> x;
            ll ans = 0;
            if (l == 1) {
                ans -= ppref[r - x];
            }
            else {
                ans -= ppref[r - x] - ppref[l - 2];
            }
            ans += ppref[r] - ppref[l + x - 2];
            cout << ans << "\n";
        }
        else {
            vector<int> ve(k);
            for (int i = 0; i < k; ++i) cin >> ve[i];
            int last = a[ve[0]];
            for (int i = 0; i < k - 1; ++i) a[ve[ i]] = a[ve[i + 1]];
            a[ve.back()] = last;
            for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i];
            for (int i = 1; i <= n; ++i) ppref[i] = ppref[i - 1] + pref[i];
        }
    }

    //cout<<endl;
}
signed main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int t = 1;
	//cin>>t;
	while(t--)
        solve();

    return 0;
}

Compilation message

Main.cpp: In function 'bool f()':
Main.cpp:86:1: warning: no return statement in function returning non-void [-Wreturn-type]
   86 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 6 ms 600 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 9 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1116 KB Output is correct
2 Correct 65 ms 2108 KB Output is correct
3 Correct 105 ms 2640 KB Output is correct
4 Correct 311 ms 4436 KB Output is correct
5 Correct 638 ms 6300 KB Output is correct
6 Correct 1664 ms 5992 KB Output is correct
7 Correct 1820 ms 5912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 937 ms 1880 KB Output is correct
2 Correct 848 ms 5364 KB Output is correct
3 Execution timed out 2053 ms 4896 KB Time limit exceeded
4 Halted 0 ms 0 KB -