Submission #885738

#TimeUsernameProblemLanguageResultExecution timeMemory
885738fanwenStreet Lamps (APIO19_street_lamps)C++17
20 / 100
5069 ms524288 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define ll long long #define file(name) \ if(fopen(name".inp", "r")) \ freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); \ void you_make_it(void) { int n, q; cin >> n >> q; vector <vector <int>> a(q, vector <int> (n)); vector <vector <int>> pref(q, vector <int> (n)); for (int i = 0; i < n; ++i) { char x; cin >> x; a[0][i] = x - '0'; } for (int i = 0; i < q; ++i) { string s; cin >> s; if(i > 0) a[i] = a[i - 1]; for (int j = 0; j < n; ++j) { pref[i][j] = (j == 0 ? 0 : pref[i][j - 1]) + a[i][j]; } if(s == "toggle") { int p; cin >> p; p--; a[i][p] ^= 1; } if(s == "query") { int l, r; cin >> l >> r; l--, r--; int ans = 0; for (int t = 0; t <= i; t++) { if(pref[t][r - 1] - (l == 0 ? 0 : pref[t][l - 1]) == r - l) ans++; } cout << ans << '\n'; } } // for (int i = 0; i < q; ++i) { // for (int j = 0; j < n; ++j) cout << a[i][j] << " \n"[j == n - 1]; // } } signed main() { #ifdef LOCAL freopen("TASK.inp", "r", stdin); freopen("TASK.out", "w", stdout); #endif file("street_lamps"); auto start_time = chrono::steady_clock::now(); cin.tie(0), cout.tie(0) -> sync_with_stdio(0); you_make_it(); auto end_time = chrono::steady_clock::now(); cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl; return (0 ^ 0); } // Dream it. Wish it. Do it.

Compilation message (stderr)

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); \
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:53:5: note: in expansion of macro 'file'
   53 |     file("street_lamps");
      |     ^~~~
street_lamps.cpp:10:49: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); \
      |                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:53:5: note: in expansion of macro 'file'
   53 |     file("street_lamps");
      |     ^~~~
#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...