Submission #1032804

# Submission time Handle Problem Language Result Execution time Memory
1032804 2024-07-24T09:00:58 Z Muhammet Street Lamps (APIO19_street_lamps) C++17
0 / 100
47 ms 28756 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second

const ll N = 300005;
const ll M = 1e9 + 7;

int T, n, q, ind1[N], a1[N], b1[N], x[N], y[N];

string s[N], s1[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0);

	cin >> n >> q >> s[0];

	for(int i = 1; i <= q; i++){
		cin >> s1[i];
		if(s1[i] == "toggle"){
			cin >> ind1[i];
		}
		else {
			cin >> a1[i] >> b1[i];
		}
	}
	if(n <= 100 and q <= 100){
		for(int i = 1; i <= q; i++){
			s[i] = s[i-1];
			if(s1[i] == "toggle"){
				int ind = (ind1[i]);
				ind--;
				if(s[0][ind] == '1'){
					s[i][ind] = '0';
				}
				else s[0][ind] = '1';
			}
			else {
				int a = a1[i], b = b1[i], ans = 0;
				for(int j = 0; j <= i-1; j++){
					bool tr = 0;
					for(int k = a-1; k < b-1; k++){
						if(s[j][k] == '0'){
							tr = 1;
							break;
						}
					}
					ans += (tr == 0);
				}
				cout << ans << '\n';
			}
		}
	}
	else {
		for(int i = 0; i < sz(s[0]); i++){
			if(s[0][i] == 1) x[i] = 0;
			else x[i] = -1;
		}
		for(int i = 1; i <= q; i++){
			if(s1[i] == "toggle"){
				int ind = (ind1[i]);
				ind--;
				if(s[0][ind] == '0'){
					x[ind] = i;
					s[0][ind] = '1';
				}
				else {
					y[i] += abs(i-x[i]);
					x[i] = -1;
					s[0][ind] = '0';
				}
			}
			else {
				int a = a1[i]-1, b = b1[i]-1, ans = y[a];
				if(x[a] != -1) ans += (abs(i-x[a])+1);
				cout << ans << "\n";
			}
		}
	}

	return 0;
}

Compilation message

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:77:22: warning: unused variable 'b' [-Wunused-variable]
   77 |     int a = a1[i]-1, b = b1[i]-1, ans = y[a];
      |                      ^
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 23128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 28756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 23208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 23128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 23128 KB Output isn't correct
2 Halted 0 ms 0 KB -