# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
774948 |
2023-07-06T06:11:00 Z |
tpd2k |
Addk (eJOI21_addk) |
C++14 |
|
1251 ms |
7140 KB |
// teddybear's code
// the one who loves NBP
// noe the second
// goal: 0 / 8
// get medal in APIO (like TKN)
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
// prob:
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define FOR(i,n) for (int i = 0; i<n; i++)
using ll = long long;
using ull = unsigned long long;
ll n,m,t;
ll cnt = 0;
const int maxn = 1e5;
const ll mod = 1e9 + 7;
#define Y "YES"
#define N "NO"
bool visited[1005][1005];
int dist[1005][1005];
int w,h;
int fx[4] = {-1, 1, 0, 0};
int fy[4] = {0, 0, -1, 1};
queue <pair<int,int>> q;
ll st[4 * maxn + 5];
ll a[maxn + 5];
void build(int id, int l, int r)
{
if (l == r)
{
st[id] = a[l];
return;
}
int m = (l + r) / 2;
build(id*2,l,m);
build(id*2+1,m+1,r);
st[id] = st[id*2] + st[id*2+1];
}
void update(int id, int l, int r, int lq, int rq, ll val)
{
if (l > rq || r < lq)
{
return;
}
if (l >= lq && r <= rq)
{
st[id] = val;
return;
}
int m = (l + r) / 2;
update(id*2,l,m,lq,rq,val);
update(id*2+1,m+1,r,lq,rq,val);
st[id] = st[id*2] + st[id*2+1];
}
ll get(int id, int l, int r, int lq, int rq)
{
if (l > rq || r < lq)
{
return 0;
}
if (l >= lq && r <= rq)
{
return st[id];
}
int m = (l + r) / 2;
return get(id*2,l,m,lq,rq) + get(id*2+1,m+1,r,lq,rq);
}
void solve()
{
cin >> n >> m;
for (int i = 1; i<=n; i++)
{
cin >> a[i];
}
build(1,1,n);
cin >> t;
while (t--)
{
int num;
cin >> num;
if (num == 1)
{
ll change[11];
for (int i = 0; i<m; i++)
{
cin >> change[i];
}
if (m == 1)
{
continue;
}
ll z = change[0];
for (int i = 0; i<m-1; i++)
{
a[change[i]] = a[change[i+1]];
update(1,1,n,change[i],change[i],a[change[i]]);
}
a[change[m-1]] = a[z];
update(1,1,n,change[m-1],change[m-1],a[change[m-1]]);
}
else
{
ll x,y,dis;
cin >> x >> y >> dis;
ll total = get(1,1,n,x,y);
ll x1 = x, y1 = y;
ll sum = 0;
ll dem = 0;
while (x1 <= y1 && y1 >= x + dis - 1 && dem < dis)
{
sum += total;
total -= a[x1];
total -= a[y1];
y1--;
x1++;
dem++;
//cout << "! " << sum << '\n';
}
cout << sum << '\n';
}
}
}
/*
8 3
7 2 5 1 9 3 4 6
3
2 2 7 4
1 2 5 8
2 2 7 3
8 3
7 2 5 1 9 3 4 6
1
2 2 7 4
*/
void init()
{
int te = 1; //cin >> te;
while (te--)
{
solve();
}
}
void preprocess()
{
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cin.tie(0); cout.tie(0);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
init();
preprocess();
//solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
388 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
7 ms |
608 KB |
Output is correct |
7 |
Correct |
9 ms |
732 KB |
Output is correct |
8 |
Correct |
11 ms |
724 KB |
Output is correct |
9 |
Correct |
23 ms |
996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
1640 KB |
Output is correct |
2 |
Correct |
137 ms |
2228 KB |
Output is correct |
3 |
Correct |
251 ms |
3232 KB |
Output is correct |
4 |
Correct |
800 ms |
5704 KB |
Output is correct |
5 |
Correct |
1251 ms |
7140 KB |
Output is correct |
6 |
Correct |
1208 ms |
6864 KB |
Output is correct |
7 |
Correct |
985 ms |
6876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
201 ms |
3428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |