# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1072108 |
2024-08-23T14:24:01 Z |
vjudge1 |
Addk (eJOI21_addk) |
C++17 |
|
1246 ms |
8528 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sz(x) x.size()
#define nl '\n'
#define F first
#define S second
const int N = 1e5 + 1;
int t[4 * N], a[N];
void upd( int v, int tl, int tr, int pos )
{
if( tl == tr )
{
t[v] = a[tl];
return;
}
int m = (tl + tr) / 2;
if( pos <= m )
upd(v + v, tl, m, pos);
else
upd(v + v + 1, m + 1, tr, pos);
t[v] = t[v + v] + t[v + v + 1];
}
int get( int v, int tl, int tr, int l, int r )
{
if( l > tr || tl > r )
return 0;
if( l <= tl && tr <= r )
return t[v];
int m = (tl + tr) / 2;
return get(v + v, tl, m, l, r) + get(v + v + 1, m + 1, tr, l, r);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k, q;
cin >>n >>k;
for( int i = 1; i <= n; ++i )
{
cin >>a[i];
upd(1, 1, n, i);
}
cin >>q;
while( q-- )
{
int type, l, r, m;
cin >>type;
if( type == 1 )
{
vector< int >v, vv;
v.pb( 0 );
vv.pb( 0 );
for( int i = 1, x; i <= k; ++i )
{
cin >>x;
v.pb( x );
vv.pb( a[x] );
}
for( int i = 1; i <= k; ++i )
{
if( i == k )
a[v[i]] = vv[1];
else
a[v[i]] = vv[i + 1];
upd(1, 1, n, v[i]);
}
}
else
{
cin >>l >>r >>m;
int ans = get(1, 1, n, l, r) * m;
for( int i = l, x = m - 1; x > 0; ++i, --x )
ans -= a[i] * x;
for( int i = r, x = m - 1; x > 0; --i, --x )
ans -= a[i] * x;
cout <<ans <<nl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2564 KB |
Output is correct |
5 |
Correct |
7 ms |
2392 KB |
Output is correct |
6 |
Correct |
9 ms |
2396 KB |
Output is correct |
7 |
Correct |
23 ms |
2396 KB |
Output is correct |
8 |
Correct |
17 ms |
2652 KB |
Output is correct |
9 |
Correct |
33 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
2832 KB |
Output is correct |
2 |
Correct |
249 ms |
2996 KB |
Output is correct |
3 |
Correct |
503 ms |
3156 KB |
Output is correct |
4 |
Correct |
879 ms |
4264 KB |
Output is correct |
5 |
Correct |
1246 ms |
7216 KB |
Output is correct |
6 |
Correct |
1129 ms |
6992 KB |
Output is correct |
7 |
Correct |
1000 ms |
6992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
276 ms |
4432 KB |
Output is correct |
2 |
Correct |
811 ms |
6792 KB |
Output is correct |
3 |
Correct |
178 ms |
8528 KB |
Output is correct |
4 |
Correct |
1185 ms |
7508 KB |
Output is correct |