답안 #264704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
264704 2020-08-14T08:28:35 Z Atalasion Sterilizing Spray (JOI15_sterilizing) C++14
100 / 100
334 ms 4984 KB
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 100000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;
const int SQ = 320;

vector<int> buc[N / SQ + 10];
int n, k, q, a[N];
ll sm[N];

inline void relax(int id){
	int l = id * SQ, r = min(n, (id + 1) * SQ);
	sm[id] = 0;
	buc[id].clear();
	for (int i = l; i < r; i++){
		if (a[i]) sm[id] += a[i], buc[id].pb(i);
	}
	return;
}

inline void Ch(int l, int r){
	int ll = l;
	if (k == 1) return;
	while (l < r){
		if (l % SQ == 0 && l + SQ <= r){
			vi qq;
			for (auto u:buc[l / SQ]){
				sm[l / SQ] -= a[u];
				a[u] = a[u] / k;
				sm[l / SQ] += a[u];
				if (a[u]) qq.pb(u);
			}
			buc[l / SQ].clear();
			buc[l / SQ].swap(qq);
			l += SQ;	
		}else{
			a[l] /= k;
			l++;
		}
	}
	relax(ll / SQ);
	relax((r - 1) / SQ);
	return;
}

ll Sum(int l, int r){
	ll res = 0;
	while (l < r){
		if (l % SQ == 0 && l + SQ <= r){
			res += sm[l / SQ];
			l += SQ;
		}else res += a[l], l++;
	}
	return res;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q >> k;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++){
		if (a[i]) buc[i / SQ].pb(i);
		sm[i / SQ] += a[i];
	}
	for (int i = 1; i <= q; i++){
		int x, l, r;
		cin >> x >> l >> r;
		l--;
		if (x == 1){
			a[l] = r;
			relax(l / SQ);
		}else if(x == 2){
			Ch(l, r);
		}else cout << Sum(l, r) << '\n';
	}









	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 360 KB Output is correct
4 Correct 5 ms 360 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 5 ms 480 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 1764 KB Output is correct
2 Correct 73 ms 1476 KB Output is correct
3 Correct 62 ms 2296 KB Output is correct
4 Correct 91 ms 2808 KB Output is correct
5 Correct 102 ms 2880 KB Output is correct
6 Correct 123 ms 2812 KB Output is correct
7 Correct 134 ms 2940 KB Output is correct
8 Correct 104 ms 2808 KB Output is correct
9 Correct 139 ms 2936 KB Output is correct
10 Correct 111 ms 3004 KB Output is correct
11 Correct 117 ms 2876 KB Output is correct
12 Correct 151 ms 2896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 512 KB Output is correct
2 Correct 29 ms 1024 KB Output is correct
3 Correct 39 ms 1024 KB Output is correct
4 Correct 144 ms 748 KB Output is correct
5 Correct 181 ms 1692 KB Output is correct
6 Correct 174 ms 1792 KB Output is correct
7 Correct 140 ms 2116 KB Output is correct
8 Correct 161 ms 1920 KB Output is correct
9 Correct 246 ms 1848 KB Output is correct
10 Correct 252 ms 2728 KB Output is correct
11 Correct 236 ms 2564 KB Output is correct
12 Correct 243 ms 2592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 1408 KB Output is correct
2 Correct 140 ms 1660 KB Output is correct
3 Correct 118 ms 1484 KB Output is correct
4 Correct 172 ms 1400 KB Output is correct
5 Correct 202 ms 2704 KB Output is correct
6 Correct 245 ms 2504 KB Output is correct
7 Correct 211 ms 2780 KB Output is correct
8 Correct 268 ms 2672 KB Output is correct
9 Correct 300 ms 2432 KB Output is correct
10 Correct 325 ms 4984 KB Output is correct
11 Correct 280 ms 4136 KB Output is correct
12 Correct 334 ms 3976 KB Output is correct