Submission #1031911

# Submission time Handle Problem Language Result Execution time Memory
1031911 2024-07-23T08:39:51 Z KasymK Street Lamps (APIO19_street_lamps) C++17
0 / 100
1 ms 348 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int MOD = 1e9+7;
const int N = 1e2+5;
int par[N], ans[N][N];

int main(){
	freopen("file.txt", "r", stdin);
	int n, q;
	scanf("%d%d", &n, &q);
	string s;
	cin >> s;
	for(int i = 0; i < n; ++i)
		par[i+1] = par[i]+(s[i]-'0');
	for(int i = 0; i < n; ++i)
		for(int j = i+1; j <= n; ++j)
			ans[i][j] = (par[j]-par[i] == j-i);
	while(q--){
		string t;
		cin >> t;
		if (t == "query"){
			int a, b;
			scanf("%d%d", &a, &b), a--, b--;
			printf("%d\n", ans[a][b]);
		}
		else{
			int i;
			scanf("%d", &i), i--;
			s[i] = (s[i] == '0' ? '1' : '0');
		}
		par[0] = 0;
		for(int i = 0; i < n; ++i)
			par[i+1] = par[i]+(s[i]-'0');
		for(int i = 0; i < n; ++i)
			for(int j = i+1; j <= n; ++j)
				ans[i][j] += (par[j]-par[i] == j-i);
	}	
	return 0;
}

Compilation message

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:16:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  freopen("file.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
street_lamps.cpp:31:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |    scanf("%d%d", &a, &b), a--, b--;
      |    ~~~~~^~~~~~~~~~~~~~~~
street_lamps.cpp:36:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |    scanf("%d", &i), i--;
      |    ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -