답안 #774958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774958 2023-07-06T06:17:19 Z tpd2k Addk (eJOI21_addk) C++14
100 / 100
1321 ms 8432 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;

#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 + 20];
ll a[maxn + 20];

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 = a[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]] = 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 4 ms 476 KB Output is correct
5 Correct 5 ms 560 KB Output is correct
6 Correct 7 ms 596 KB Output is correct
7 Correct 9 ms 724 KB Output is correct
8 Correct 11 ms 704 KB Output is correct
9 Correct 20 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 1728 KB Output is correct
2 Correct 156 ms 2088 KB Output is correct
3 Correct 251 ms 2888 KB Output is correct
4 Correct 817 ms 4768 KB Output is correct
5 Correct 1321 ms 5984 KB Output is correct
6 Correct 1124 ms 5712 KB Output is correct
7 Correct 1018 ms 5740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 211 ms 3004 KB Output is correct
2 Correct 796 ms 6520 KB Output is correct
3 Correct 198 ms 8432 KB Output is correct
4 Correct 1190 ms 7380 KB Output is correct