Submission #1044916

#TimeUsernameProblemLanguageResultExecution timeMemory
1044916vjudge1Street Lamps (APIO19_street_lamps)C++17
20 / 100
5090 ms14796 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pb push_back const ll mod = 1e9 + 7; const ll N = 2e5 + 37; template<typename T, size_t N> std::ostream& operator<<(std::ostream& os, const std::array<T, N>& a); template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v); template<typename T1, typename T2> std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p); template<typename T> std::ostream& operator<<(std::ostream& os, const std::set<T>& s); template<typename T, typename cmp> std::ostream& operator<<(std::ostream& os, const std::set<T, cmp>& s); const ll inf = (ll)1e9 + 37; int n, Q; string s; void brute() { vector<string> a{s}; while(Q--) { string qt; cin >> qt; if(qt == "toggle") { int i; cin >> i; --i; s[i] ^= 1; } else if(qt == "query") { int l, r; cin >> l >> r; --l, --r; int ans = 0; for(const string& b : a) { if(count(b.begin() + l, b.begin() + r, 0) == 0) { ++ans; } } cout << ans << endl; } else assert(false); a.push_back(s); } } void solve() { cin >> n >> Q >> s; for(char& c : s) c -= '0'; if(n * n * Q <= 1e8) { brute(); return; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // signed t; cin >> t; while(t--) solve(); } template<typename T, size_t N> std::ostream& operator<<(std::ostream& os, const std::array<T, N>& a) { os << "["; for(size_t i = 0; i + 1 < N; ++i) { os << a[i] << ", "; } if(N > 0) os << a[N - 1]; os << "]"; return os; } template<typename T1, typename T2> std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) { os << "(" << p.first << ", " << p.second << ") "; return os; } template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) { os << '['; for(auto x : v) os << x << ", "; os << "] "; return os; } template<typename T> std::ostream& operator<<(std::ostream& os, const std::set<T>& s) { os << "{"; for(auto x : s) os << x << ", "; os << "} "; return os; } template<typename T, typename cmp> std::ostream& operator<<(std::ostream& os, const std::set<T, cmp>& s) { os << "{"; for(auto x : s) os << x << ", "; os << "} "; return os; }
#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...