Submission #154729

#TimeUsernameProblemLanguageResultExecution timeMemory
154729Pro_ktmrStreet Lamps (APIO19_street_lamps)C++14
20 / 100
1434 ms28468 KiB
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define MP make_pair

int N,Q;
string def;
int t[300000],a[300000],b[300000];
vector<int> toggle[300000];
int ans[300000] = {};
int idx[300000] = {};

int main(){
	cin >> N >> Q;
	cin >> def;
	for(int i=0; i<N; i++){
		if(def[i] == '1') toggle[i].push_back(0);
	}
	for(int i=0; i<Q; i++){
		string type;
		cin >> type;
		if(type == "toggle"){
			t[i] = 0;
			cin >> a[i];
			a[i]--;
			toggle[a[i]].push_back(i+1);
		}
		else{
			t[i] = 1;
			cin >> a[i] >> b[i];
			a[i]--; b[i]--;
			while(toggle[a[i]].size() > idx[a[i]] + 1){
				ans[a[i]] += toggle[a[i]][idx[a[i]]+1] - toggle[a[i]][idx[a[i]]];
				idx[a[i]] += 2;
			}
			int tmp = ans[a[i]];
			if(toggle[a[i]].size()%2 == 1){
				tmp += i+1 - toggle[a[i]].back();
			}
			cout << tmp << endl;
		}
	}
	
	return 0;
}

Compilation message (stderr)

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:32:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(toggle[a[i]].size() > idx[a[i]] + 1){
          ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
#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...