답안 #433737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433737 2021-06-20T10:10:09 Z Mounir 가로등 (APIO19_street_lamps) C++14
20 / 100
825 ms 9816 KB
#include <bits/stdc++.h>
#define chmax(x, v) x = max(x, v)
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define chmin(x, v) x = min(x, v)
#define sz(x) (int)x.size()
#define int long long
using namespace std;

const int N = (1 << 20), OO = 1e9;
int maxi[N * 2];

int getMax(int gauche, int droite){
	if (gauche > droite)
		return 0;
	if (gauche%2 == 1)
		return max(maxi[gauche], getMax(gauche + 1, droite));
	if (droite%2 == 0)
		return max(maxi[droite], getMax(gauche, droite - 1));
	return getMax(gauche/2, droite/2);
}

void upd(int noeud, int val){
	int n = N + noeud;
	maxi[n] = val;
	n /= 2;
	for (; n > 0; n /= 2)
		maxi[n] = max(maxi[n  * 2], maxi[n * 2 + 1]);
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int nVals, nReqs; cin >> nVals >> nReqs;
	vector<int> vals(nVals);
	string chaine; cin >> chaine;

	for (int iVal = 0; iVal < nVals; ++iVal){
		vals[iVal] = (chaine[iVal] - '0');
		if (vals[iVal] == 1)
			upd(iVal, 0);
		else
			upd(iVal, OO);
	}

	for (int iReq = 1; iReq <= nReqs; ++iReq){
		string typeReq; cin >> typeReq;
		if (typeReq == "toggle"){
			int iVal; cin >> iVal; --iVal;
			upd(iVal, iReq);
		}
		else {
			int a, b; cin >> a >> b;
			--a; --b;
			int  act = getMax(N + a, N + b - 1);
			cout << max(0ll, iReq - act) << endl;
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 336 ms 952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 144 ms 7828 KB Output is correct
6 Correct 318 ms 8020 KB Output is correct
7 Correct 560 ms 8140 KB Output is correct
8 Correct 825 ms 9816 KB Output is correct
9 Correct 529 ms 1192 KB Output is correct
10 Correct 568 ms 1184 KB Output is correct
11 Correct 620 ms 1320 KB Output is correct
12 Correct 811 ms 8400 KB Output is correct
13 Correct 782 ms 9792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 332 KB Output is correct
2 Incorrect 2 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -