답안 #754971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
754971 2023-06-09T07:28:55 Z ooscode Sterilizing Spray (JOI15_sterilizing) C++17
20 / 100
445 ms 87852 KB
// IN THE NAME OF ALLAH

#include<bits/stdc++.h>

using namespace std;

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define wall cerr << "------------------------------------" << endl
#define pb push_back
#define pob pop_back
#define F first
#define S second
#define all(x) x.begin() , x.end()
#define scan scanf
#define print printf
#define outs(x) print("%lld " , x)
#define out(x) print("%lld\n" , x)
#define in(x) scan("%lld" , &x)
#define gcd __gcd
#define endl '\n'
#define int ll

#pragma GCC optimize("Ofast")

typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll , ll> pll;
typedef pair<pii , int> piii;
typedef pair<pll , ll> plll;

const int N = 1e5+10;
const int K = 31 + 10;
const ll mod = 1e9+7;
const ll INF = 1e18+10;
const int P = 31;

int seg[4*N][K];
int la[4*N];

int n , q , k;

int a[N];

void build(int v , int tl , int tr) {
	if(tl == tr) {
		int x = a[tl];
		seg[v][0] = x;
		int o = 1;

		while(x && o < K) {
			x /= k;
			seg[v][o++] = x;
		}
	
		return;
	}

	int tm = (tl + tr)/2;

	build(2*v , tl , tm);
	build(2*v+1 , tm+1 , tr);

	for(int i = 0 ; i < K ; i++)
		seg[v][i] = seg[2*v][i] + seg[2*v+1][i];
}

void shift(int v , int tl , int tr) {
	for(int i = 0 ; i <= K - la[v] - 1 ; i++)
		seg[v][i] = seg[v][i+la[v]];
	for(int i = K-1 ; i > K-la[v]-1 && i >= 0 ; i--)
		seg[v][i] = 0;

	if(tl != tr) {
		la[2*v] += la[v];
		la[2*v+1] += la[v];
	}

	la[v] = 0;
}

void update(int v , int tl , int tr , int pos , int x) {
	shift(v , tl , tr);

	if(tl > pos || pos > tr)
		return;

	if(tl == tr) {
		int y = x;
		seg[v][0] = y;
		int o = 1;

		while(y && o < K) {
			y /= k;
			seg[v][o++] = y;
		}
	
		return;
	}

	int tm = (tl + tr)/2;

	update(2*v , tl , tm , pos , x);
	update(2*v+1 , tm+1 , tr , pos , x);

	for(int i = 0 ; i < K ; i++)
		seg[v][i] = seg[2*v][i] + seg[2*v+1][i];
}

void upd(int v , int tl , int tr , int l , int r) {
	shift(v , tl , tr);

	if(l > r)
		return;

	if(tl == l && tr == r) {
		la[v] = 1;
		shift(v , tl , tr);

		return;
	}

	int tm = (tl + tr)/2;

	upd(2*v , tl , tm , l , min(tm , r));
	upd(2*v+1 , tm+1 , tr , max(l , tm+1) , r);

	for(int i = 0 ; i < K ; i++)
		seg[v][i] = seg[2*v][i] + seg[2*v+1][i];
}

int ask(int v , int tl , int tr , int l , int r) {
	shift(v , tl , tr);

	if(l > r)
		return 0;

	if(tl == l && tr == r)
		return seg[v][0];

	int tm = (tl + tr)/2;

	return ask(2*v , tl , tm , l , min(tm , r)) + ask(2*v+1 , tm+1 , tr , max(l , tm+1) , r);
}

signed main()
{
	fast;

	cin >> n >> q >> k;

	for(int i = 1 ; i <= n ; i++)
		cin >> a[i];

	build(1 , 1 , n);

	if(k == 1) {
		while(q--) {
			int t , l , r;
			cin >> t >> l >> r;

			if(t == 1) 
				update(1 , 1 , n , l , r);
			else if(t == 3)
				cout << ask(1 , 1 , n , l , r) << "\n";
		}
	}
	else {
		while(q--) {
			int t , l , r;
			cin >> t >> l >> r;

			if(t == 1) 
				update(1 , 1 , n , l , r);
			else if(t == 2) 
				upd(1 , 1 , n , l , r);
			else
				cout << ask(1 , 1 , n , l , r) << "\n";
		}
	}
}

// IT'S EASY TO SEE
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 1620 KB Output is correct
4 Incorrect 6 ms 1620 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 44304 KB Output is correct
2 Correct 205 ms 24992 KB Output is correct
3 Correct 184 ms 85324 KB Output is correct
4 Correct 262 ms 87632 KB Output is correct
5 Correct 275 ms 87724 KB Output is correct
6 Correct 328 ms 87752 KB Output is correct
7 Correct 275 ms 87744 KB Output is correct
8 Correct 285 ms 87652 KB Output is correct
9 Correct 233 ms 87796 KB Output is correct
10 Correct 241 ms 87760 KB Output is correct
11 Correct 243 ms 87852 KB Output is correct
12 Correct 285 ms 87780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 5768 KB Output is correct
2 Correct 82 ms 43768 KB Output is correct
3 Correct 104 ms 43696 KB Output is correct
4 Correct 306 ms 22072 KB Output is correct
5 Correct 416 ms 87452 KB Output is correct
6 Correct 416 ms 87344 KB Output is correct
7 Correct 237 ms 87520 KB Output is correct
8 Correct 445 ms 87332 KB Output is correct
9 Correct 327 ms 87320 KB Output is correct
10 Correct 320 ms 87324 KB Output is correct
11 Correct 325 ms 87388 KB Output is correct
12 Correct 313 ms 87344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 275 ms 43900 KB Output is correct
2 Correct 299 ms 44108 KB Output is correct
3 Incorrect 230 ms 43948 KB Output isn't correct
4 Halted 0 ms 0 KB -