Submission #1264417

#TimeUsernameProblemLanguageResultExecution timeMemory
1264417tminhAddk (eJOI21_addk)C++20
100 / 100
160 ms8904 KiB
#include "bits/stdc++.h" using namespace std; #define task "" #define ll long long #define endl '\n' #define fi first #define se second #define vall(a) (a).begin(), (a).end() #define sze(a) (int)a.size() #define pii pair<int, int> #define pll pair<ll, ll> #define ep emplace_back #define pb push_back #define pf push_front const ll mod = 1e9 + 7; const int N = 1e5 + 5; const ll oo = 1e18; bool START; int n, k, q; ll a[N], b[N]; struct ST { struct node { ll hs1, hs2; node() { hs1 = hs2 = 0; } node operator+(const node &other) const{ node res; res.hs1 = hs1 + other.hs1; res.hs2 = hs2 + other.hs2; return res; } } st[N << 2]; void update(int id, int l, int r, int i, ll val) { if (l > i || r < i) return; if (l == r) { st[id].hs1 = val; st[id].hs2 = (val * i); return; } int mid = (l + r) >> 1; update(id << 1, l, mid, i, val); update(id << 1 | 1, mid + 1, r, i, val); st[id] = st[id << 1] + st[id << 1 | 1]; } node get(int id, int l, int r, int u, int v) { if (l > v || r < u) return node(); if (l >= u && r <= v) return st[id]; int mid = (l + r) >> 1; return get(id << 1, l, mid, u, v) + get(id << 1 | 1, mid + 1, r, u, v); } } st; inline void solve() { while(q--) { int type; cin >> type; if (type == 1) { for (int i = 1; i <= k; ++i) cin >> b[i]; int tmp = a[b[k]], pretmp = a[b[k]]; for (int i = k - 1; i >= 1; --i) { tmp = a[b[i]]; a[b[i]] = pretmp; st.update(1, 1, n, b[i], a[b[i]]); pretmp = tmp; } a[b[k]] = pretmp; st.update(1, 1, n, b[k], a[b[k]]); } // for (int i = 1; i <= n; ++i) cout << a[i] << " "; // cout << endl; if (type == 2) { ll l, r, m; cin >> l >> r >> m; int lim = r - m + 1; ll hs = st.get(1, 1, n, l, lim).hs2; ll ans = hs; hs = st.get(1, 1, n, lim + 1, r).hs1; ans += hs * (r - m + 1); lim = l + m - 1; hs = st.get(1, 1, n, l, lim).hs1; ans -= hs * l; auto[hs1, hs2] = st.get(1, 1, n, lim + 1, r); ans -= hs2 - hs1 * (m - 1); hs = st.get(1, 1, n, l, r).hs1; ans += hs; cout << ans << endl; } } } inline void input() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; st.update(1, 1, n, i, a[i]); } cin >> q; return solve(); } bool END; int main() { if(fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); input(); cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl; cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n"; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:119:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:120:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...