Submission #754970

# Submission time Handle Problem Language Result Execution time Memory
754970 2023-06-09T07:23:36 Z ooscode Sterilizing Spray (JOI15_sterilizing) C++17
20 / 100
358 ms 67308 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 = 21 + 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
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Incorrect 5 ms 1364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 156 ms 34156 KB Output is correct
2 Correct 127 ms 19780 KB Output is correct
3 Correct 169 ms 66824 KB Output is correct
4 Correct 193 ms 67164 KB Output is correct
5 Correct 237 ms 67308 KB Output is correct
6 Correct 207 ms 67216 KB Output is correct
7 Correct 222 ms 67188 KB Output is correct
8 Correct 228 ms 67176 KB Output is correct
9 Correct 201 ms 67148 KB Output is correct
10 Correct 202 ms 67188 KB Output is correct
11 Correct 189 ms 67148 KB Output is correct
12 Correct 175 ms 67228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 4484 KB Output is correct
2 Correct 55 ms 33492 KB Output is correct
3 Correct 97 ms 33496 KB Output is correct
4 Correct 255 ms 16964 KB Output is correct
5 Correct 358 ms 66900 KB Output is correct
6 Correct 334 ms 66772 KB Output is correct
7 Correct 207 ms 66980 KB Output is correct
8 Correct 343 ms 67028 KB Output is correct
9 Correct 256 ms 66812 KB Output is correct
10 Correct 248 ms 66800 KB Output is correct
11 Correct 272 ms 66752 KB Output is correct
12 Correct 291 ms 66808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 33700 KB Output is correct
2 Correct 231 ms 33688 KB Output is correct
3 Incorrect 148 ms 33636 KB Output isn't correct
4 Halted 0 ms 0 KB -