답안 #410675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410675 2021-05-23T10:31:45 Z dynam1c 가로등 (APIO19_street_lamps) C++17
20 / 100
223 ms 12144 KB
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define endl "\n"
#define all(c) (c).begin(),(c).end()

// when you ponder, divide and conquer

struct RMQ {
	int n;
	vector<int> seg;
	RMQ(vector<int> arr) : n(arr.size()), seg(2*n) {
		for (int i = 0; i < n; i++)
			seg[i+n] = arr[i];
		for (int i = n-1; i > 0; i--)
			seg[i] = max(seg[i<<1], seg[i<<1|1]);
	}
	int query(int l, int r) {
		int acc = INT_MIN;
		for (l += n, r += n; l != r; l >>= 1, r >>= 1) {
			if (l&1) acc = max(acc, seg[l++]);
			if (r&1) acc = max(acc, seg[--r]);
		}
		return acc;
	}
	void update(int i, int x) {
		for (seg[i += n] = x; i > 1; i >>= 1)
			seg[i>>1] = max(seg[i], seg[i^1]);
	}
};

signed main() {
	// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> time(n);
	for (int i = 0; i < n; i++)
		time[i] = s[i] == '1' ? 0 : 1e6;
	RMQ rmq(time);
	for (int qq = 0; qq < q; qq++) {
		string t;
		cin >> t;
		if (t == "query") {
			int l, r;
			cin >> l >> r;
			l--, r--;
			cout << max(qq+1 - rmq.query(l, r), 0) << endl;
		}
		if (t == "toggle") {
			int i;
			cin >> i;
			i--;
			rmq.update(i, qq+1);
		}
	}
}
/* --- PSolving ---
 * Simplifying (getting rid of variables, conditions, code logic, etc.)
 * Reframing
 * Solving a subtask (subgoal, aux. problem, removing a condition or fixing a parameter, etc.)
 * Inducing
 * Divide and conquer
 * Working backwards
 * Visual intuition
 * !! Reductions don't have to be specializations, they can be generalizations
 */
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 120 ms 5472 KB Output is correct
6 Correct 124 ms 9152 KB Output is correct
7 Correct 146 ms 9784 KB Output is correct
8 Correct 223 ms 12092 KB Output is correct
9 Correct 99 ms 3928 KB Output is correct
10 Correct 106 ms 4272 KB Output is correct
11 Correct 108 ms 4436 KB Output is correct
12 Correct 182 ms 10696 KB Output is correct
13 Correct 186 ms 12144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -