답안 #265168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
265168 2020-08-14T13:36:18 Z hanagasumi 가로등 (APIO19_street_lamps) C++17
0 / 100
112 ms 9728 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>

#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
#define int ll
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;
typedef long double ld;

int inf = 1e9 + 100;
int N = (1 << 17);
vector<int> tree(2 * N, inf);

void upd(int v) {
	if(v == 0) 
		return;
	tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
	upd(v / 2);
}

int get(int v, int l, int r, int vl, int vr) {
	if(r <= vl || vr <= l) 
		return 0;
	if(vl <= l && r <= vr) 
		return tree[v];
	int mid = (l + r) / 2;
	return max(get(v * 2, l, mid, vl, vr), get(v * 2 + 1, mid, r, vl, vr));
}

signed main() {
	#ifdef PC
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, q;
	cin >> n >> q;
	vector<int> ans(n, 0);
	for (int i = 0; i < n; i++) {
		char c;
		cin >> c;
		if(c == '1') {
			tree[N + i] = 0;
			upd((N + i) / 2);
		}
	}
	for (int i = 0; i < q; i++) {
		string s;
		cin >> s;
		if(s == "toggle") {
			int id;
			cin >> id;
			id--;
			tree[N + id] = (i + 1);
			upd((N + id) / 2);
			continue;
		}
		int l, r;
		cin >> l >> r;
		l--, r--;
		int st = get(1, 0, N, l, r);
		if(st == inf) {
			cout << 0 << '\n';
			continue;
		}
		cout << (i + 1) - st << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 112 ms 2936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2432 KB Output is correct
2 Correct 2 ms 2432 KB Output is correct
3 Correct 2 ms 2432 KB Output is correct
4 Correct 2 ms 2432 KB Output is correct
5 Runtime error 12 ms 9728 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2432 KB Output is correct
2 Incorrect 2 ms 2432 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2432 KB Output isn't correct
2 Halted 0 ms 0 KB -