Submission #433620

#TimeUsernameProblemLanguageResultExecution timeMemory
433620oscar1fStreet Lamps (APIO19_street_lamps)C++17
20 / 100
733 ms11420 KiB
#include<bits/stdc++.h>
using namespace std;

const int INFINI=1000*1000*1000,DECA=(1<<19);
int nbLampe,nbReq,pos,nbTaxi,deb,fin,rep;
int arbreMax[2*DECA];
char carac;
string typeReq;

void maintien_max(int position) {
	if (position>0) {
		arbreMax[position]=max(arbreMax[2*position],arbreMax[2*position+1]);
		maintien_max(position/2);
	}
}

int calc_max(int debInter,int finInter) {
	if (debInter==finInter) {
		return arbreMax[debInter];
	}
	if (debInter%2==1) {
		return max(arbreMax[debInter],calc_max(debInter+1,finInter));
	}
	if (finInter%2==0) {
		return max(arbreMax[finInter],calc_max(debInter,finInter-1));
	}
	return calc_max(debInter/2,finInter/2);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin>>nbLampe>>nbReq;
	nbTaxi=nbLampe+1;
	for (int i=1;i<=nbLampe;i++) {
		cin>>carac;
		if (carac=='1') {
			arbreMax[DECA+i-1]=0;
		}
		else {
			arbreMax[DECA+i-1]=INFINI;
		}
	}
	for (int i=DECA-1;i>0;i--) {
		arbreMax[i]=max(arbreMax[2*i],arbreMax[2*i+1]);
	}
	for (int ireq=1;ireq<=nbReq;ireq++) {
		cin>>typeReq;
		if (typeReq=="toggle") {
			cin>>pos;
			arbreMax[DECA+pos-1]=ireq;
			maintien_max((DECA+pos-1)/2);
		}
		else {
			cin>>deb>>fin;
			rep=calc_max(DECA+deb-1,DECA+fin-2);
			if (rep==INFINI) {
				cout<<0<<endl;
			}
			else {
				cout<<ireq-rep<<endl;
			}
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...