Submission #967299

# Submission time Handle Problem Language Result Execution time Memory
967299 2024-04-21T18:23:24 Z Fikrat_Asadzadeh Addk (eJOI21_addk) C++14
0 / 100
934 ms 4948 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FORI(i, n) for(int i = 0; i < n; i++)
#define FOR(i, n) for(int i = 1; i <= n; i++)
typedef vector < ll > vl; 
typedef set < ll > setl;
#define ff first
#define ss second    
#define all(v) v.begin(), v.end() 
#define pll pair < ll , ll > 
#define db  double
#define nll cout << "\n"
#define nl "\n"
#define sync                          \
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) ;
// #define int ll
const ll INF = 1e9;
const int MAX = 1e5 + 5; 
ll n, m, k;
ll t[4 * MAX], a[MAX], b[11];
void build(ll v, ll l, ll r){
    if(l == r){
        t[v] = a[l];
        return;
    }
    ll mid = (l + r) / 2;
    build(v * 2 + 1, l, mid);
    build(v * 2 + 2, mid + 1, r);
    t[v] = t[v * 2 + 1] + t[v * 2 + 2];
}
ll query(ll v, ll L, ll R, ll l, ll r){
    if(L > r || R < l)return 0;
    if(L >= l && R <= r)return t[v];
    ll mid = L + R >> 1;
    return query(v * 2 + 1, L, mid, l, r) + query(v * 2 + 2, mid + 1, R, l, r);
}
void update(ll v, ll l, ll r, ll x, ll y){
    if(l == r){
        a[x] = y;
        return;
    }
    ll mid = l + r >> 1;
    if(x >= mid)update(v * 2 + 1, l, mid, x, y);
    else update(v * 2 + 2, mid +  1, r, x, y);
    t[v] = t[v * 2 + 1] + t[v * 2 + 2];
}
void solve(){
    cin >> n >> k;
    FOR(i, n){
        cin >> a[i];
    }
    ll q, c;
    cin >> q;
    ll l, r, x;
    while(q--){
        cin >> c;
        if(c == 2){
            cin >> l >> r >> x;
            ll res = 0;
            for(ll i = l; i <= r; i++){
                if(i >= l + x - 1){
                    if(i <= r - x + 1){
                        res += a[i] * x;
                    }
                    else{
                        res += a[i] * (r - i + 1);
                    }
                }
                else{
                    res += a[i] * (i - l + 1);
                }
            }
            cout << res << nl;
        }   
        else{
            FOR(i, k){
                cin >> b[i];
            }
            x = a[b[1]];
            for(ll i = 1; i <= k - 1; i++)a[b[i]] = a[b[i + 1]];
            a[b[k]] = x;
        }
    }
}
signed main(){
    sync;
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}   

Compilation message

Main.cpp: In function 'long long int query(long long int, long long int, long long int, long long int, long long int)':
Main.cpp:35:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |     ll mid = L + R >> 1;
      |              ~~^~~
Main.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
Main.cpp:43:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |     ll mid = l + r >> 1;
      |              ~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 219 ms 1360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 934 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -