Submission #1044589

#TimeUsernameProblemLanguageResultExecution timeMemory
1044589vjudge1Street Lamps (APIO19_street_lamps)C++17
20 / 100
134 ms10980 KiB
#include <bits/stdc++.h> using i64 = long long; #ifdef DEBUG #include "debug.h" #else #define debug(...) void(23) #endif #define def int mid = (l + r) >> 1, rv = v + ((mid - l + 1) << 1) struct segtree { int n; std::vector<int> tree; segtree(int _n) : n(_n), tree(n << 1) {} void modify(int v, int l, int r, int p, int x) { if(l == r) { tree[v] = x; return; } def; if(p <= mid) { modify(v + 1, l, mid, p, x); } else { modify(rv, mid + 1, r, p, x); } tree[v] = std::max(tree[v + 1], tree[rv]); } void modify(int p, int x) { assert(0 <= p && p < n); modify(0, 0, n - 1, p, x); } int query(int v, int l, int r, int ql, int qr) { if(ql <= l && r <= qr) { return tree[v]; } def; if(qr <= mid) { return query(v + 1, l, mid, ql, qr); } else if(mid + 1 <= ql) { return query(rv, mid + 1, r, ql, qr); } return std::max(query(v + 1, l, mid, ql, qr), query(rv, mid + 1, r, ql, qr)); } int query(int l, int r) { assert(0 <= l && l <= r && r < n); return query(0, 0, n - 1, l, r); } }; constexpr int INF = 1E9; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N, Q; std::cin >> N >> Q; std::string S; std::cin >> S; segtree seg(N); for(int i = 0; i < N; ++i) { if(S[i] == '1') { seg.modify(i, 0); } else { seg.modify(i, INF); } } for(int timer = 1; timer <= Q; ++timer) { std::string T; std::cin >> T; if(T[0] == 't') { int i; std::cin >> i; --i; if(S[i] == '1') { seg.modify(i, INF); S[i] = '0'; } else { seg.modify(i, timer); S[i] = '1'; } } else { int A, B; std::cin >> A >> B; --A, --B; int get = seg.query(A, B - 1); if(get == INF) { std::cout << 0 << '\n'; } else { std::cout << timer - get << '\n'; } } #ifdef DEBUG for(int i = 0; i < N; ++i) { std::cerr << seg.query(i, i) << " \n"[i == N - 1]; } #endif } return 0; }
#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...