# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
582511 |
2022-06-24T02:30:06 Z |
talant117408 |
Addk (eJOI21_addk) |
C++17 |
|
283 ms |
9992 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define long unsigned long
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define PI 2*acos(0.0)
const int N = 1e5+7, mod = 1e9+7;
ll tree[3][N*4];
// 0 - sum = A1 + A2 ... + An, 1 - pref = 1*A1 + 2*A2 ... + n*An, 2 - suff = n*A1 + (n-1)*A2 ... + 1*an
ll add(ll a, ll b) {
return ((a + b) % mod + mod) % mod;
}
ll subt(ll a, ll b) {
return ((a - b) % mod + mod) % mod;
}
ll mult(ll a, ll b) {
return ((a * b) % mod + mod) % mod;
}
ll binpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b&1) res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
ll divi(ll a, ll b) {
return mult(a, binpow(b, mod-2));
}
void update(int i, int v, int l, int r, int pos, ll val) {
if (l == r) {
tree[i][v] = val;
return;
}
int mid = (l+r) >> 1;
if (pos <= mid) update(i, v*2, l, mid, pos, val);
else update(i, v*2+1, mid+1, r, pos, val);
tree[i][v] = add(tree[i][v*2], tree[i][v*2+1]);
}
ll get(int i, int v, int l, int r, int ql, int qr) {
if (ql > r || l > qr) return 0;
if (ql <= l && r <= qr) return tree[i][v];
int mid = (l+r) >> 1;
return add(get(i, v*2, l, mid, ql, qr), get(i, v*2+1, mid+1, r, ql, qr));
}
struct query {
int type;
vector <int> inds;
query() {}
};
void solve() {
int n, k;
cin >> n >> k;
vector <ll> v(n+2);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
int q;
cin >> q;
vector <query> queries(q);
for (int i = 0; i < q; i++) {
int type;
cin >> type;
queries[i].type = type;
if (type == 1) {
for (int j = 0; j < k; j++) {
int x;
cin >> x;
queries[i].inds.pb(x);
}
}
else {
int l, r, m;
cin >> l >> r >> m;
queries[i].inds.pb(l);
queries[i].inds.pb(r);
queries[i].inds.pb(m);
}
}
for (int i = 1; i <= n; i++) {
update(0, 1, 1, n, i, v[i]);
update(1, 1, 1, n, i, mult(v[i], i));
update(2, 1, 1, n, i, mult(v[i], n-i+1));
}
for (auto to : queries) {
auto type = to.type;
auto ind = to.inds;
if (type == 1) {
for (int j = 1; j < k; j++) {
update(0, 1, 1, n, ind[j-1], v[ind[j]]);
update(1, 1, 1, n, ind[j-1], mult(v[ind[j]], ind[j-1]));
update(2, 1, 1, n, ind[j-1], mult(v[ind[j]], n-ind[j-1]+1));
}
update(0, 1, 1, n, ind[k-1], v[ind[0]]);
update(1, 1, 1, n, ind[k-1], mult(v[ind[0]], ind[k-1]));
update(2, 1, 1, n, ind[k-1], mult(v[ind[0]], n-ind[k-1]+1));
auto tmp = v[ind[0]];
for (int j = 1; j < k; j++) {
v[ind[j-1]] = v[ind[j]];
}
v[ind[k-1]] = tmp;
}
else {
ll l = ind[0], r = ind[1], m = ind[2];
ll intervals = (r-l+1)-m+1;
ll ans = 0;
if (intervals > 1) {
ans = add(ans, get(1, 1, 1, n, l, l+intervals-2));
if (l > 1) {
ans = subt(ans, mult(get(0, 1, 1, n, l, l+intervals-2), l-1));
}
}
ans = add(ans, mult(get(0, 1, 1, n, l+intervals-1, r-intervals+1), intervals));
if (intervals > 1) {
ans = add(ans, get(2, 1, 1, n, r-intervals+2, r));
if (r < n) {
ans = subt(ans, mult(get(0, 1, 1, n, r-intervals+2, r), n-r));
}
}
cout << ans << endl;
}
}
}
int main() {
do_not_disturb
int t = 1;
//~ cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
3920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
283 ms |
9992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |