제출 #1270789

#제출 시각아이디문제언어결과실행 시간메모리
1270789KickingKunSterilizing Spray (JOI15_sterilizing)C++20
15 / 100
317 ms2376 KiB
// PHK
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define bigint __int128
#define emb emplace_back
#define pb push_back
#define pii pair <int, int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define Task ""

#define MASK(k) (1ull << k)
#define bitcnt(k) __builtin_popcount(k)
#define testBit(n, k) ((n >> k) & 1)
#define flipBit(n, k) (n ^ (1ll << k))
#define offBit(n, k) (n & ~MASK(k))
#define onBit(n, k) (n | (1ll << k))

template <class T> bool minimize(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool maximize(T &a, T b) {if (a < b) {a = b; return true;} return false;}

const int N = 1e5 + 5, SQR = 3001, mod = 1e9 + 7;
const ll INF = 1e18;

int n, q, k, a[N];
int blockID[N];

namespace sub1 {
	struct FenwickTree {
		vector <ll> bit;
		FenwickTree (int sz) {
			bit.assign(sz + 1, 0);
		}
		void update(int p, int val) {
			for (; p < bit.size(); p += p & -p) bit[p] += val;
		}
		ll get(int p) {
			ll res = 0; for (; p > 0; p -= p & -p) res += bit[p];
			return res;
		}
	};
	
	void solve() {
		FenwickTree fen(n);
		for (int i = 1; i <= n; i++) {
			fen.update(i, a[i - 1]);
		}
		
		while (q--) {
			int t, u, v; cin >> t >> u >> v;
			if (t == 1) {
				fen.update(u, -a[u - 1] + v);
				a[u - 1] = v;
			}
			else if (t == 3) {
				cout << fen.get(v) - fen.get(u - 1) << '\n';
			}
		}
	}
}

int first(int block) {
	return (block - 1) * SQR;
}

int last(int block) {
	return min(n, block * SQR) - 1;
}

int cnt_div[N / SQR + 5];
vector <ll> ans[N / SQR + 5];
ll pw[40];

int L;

int get_sum(int block) {
	return ans[block].back();
}

int real_val(int p) {
	return a[p] / pw[cnt_div[blockID[p]]];
}

void apply(int block) {
	int l = first(block), r = last(block);
	for (int i = l, d = pw[cnt_div[block]]; i <= r; i++) a[i] /= d;
	cnt_div[block] = 0;
}

void set_ans(int block) {
	int l = first(block), r = last(block);
	ans[block].assign(30, 0);
	for (int i = l; i <= r; i++) {
		for (int times = 0, cur = a[i]; cur > 0; cur /= k, ++times)
			ans[block][times] += cur;
	}
	
	while (ans[block].size() > 1 && ans[block][ans[block].size() - 2] == 0)
		ans[block].pop_back();
	reverse(all(ans[block]));
}

void update_block(int block) {
	if (ans[block].size() > 1) ans[block].pop_back();
	cnt_div[block] = min(L, cnt_div[block] + 1);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	if (fopen(Task".inp", "r")) {
		freopen(Task".inp", "r", stdin);
		freopen(Task".out", "w", stdout);
	}
	
	cin >> n >> q >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		blockID[i] = i / SQR + 1;
	}
	
	if (k == 1) {
		sub1::solve();
		return 0;
	}
	
	pw[0] = 1;
	for (int i = 1; pw[i - 1] * k <= 1e10; i++)
		pw[i] = pw[i - 1] * k, L = i;
	
	for (int block = 1; block <= blockID[n - 1]; block++)
		set_ans(block);
	
	while (q--) {
		int t, u, v; cin >> t >> u >> v;
		if (t == 1) {
			--u;
			apply(blockID[u]);
			a[u] = v;
			set_ans(blockID[u]);
		}
		else if (t == 2) {
			--u; --v;
			int blockL = blockID[u], blockR = blockID[v];
			if (blockL == blockR) {
				apply(blockL);
				for (int i = u; i <= v; i++) a[i] /= k;
				set_ans(blockL);
			}
			else {
				// blockL
				apply(blockL);
				for (int i = u; i <= last(blockL); i++) a[i] /= k;
				set_ans(blockL);
				
				// blockR
				apply(blockR);
				for (int i = first(blockR); i <= v; i++) a[i] /= k;
				set_ans(blockR);
				
				// mid block
				for (int bl = blockL + 1; bl < blockR; bl++)
					update_block(bl);
			}
		}
		else {
			--u; --v;
			int blockL = blockID[u], blockR = blockID[v];
			if (blockL == blockR) {
				ll res = 0;
				for (int i = u; i <= v; i++) res += real_val(i);
				cout << res << '\n';
			}
			else {
				ll res = 0;
				for (int i = u; i <= last(blockL); i++) res += real_val(i);
				for (int i = first(blockR); i <= v; i++) res += real_val(i);
				for (int bl = blockL + 1; bl < blockR; bl++)
					res += get_sum(bl);
				cout << res << '\n';
			}
		}
	}
}
 

컴파일 시 표준 에러 (stderr) 메시지

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:117:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |                 freopen(Task".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:118:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |                 freopen(Task".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...