Submission #1234293

#TimeUsernameProblemLanguageResultExecution timeMemory
1234293badge881Street Lamps (APIO19_street_lamps)C++20
20 / 100
177 ms6968 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; class SegTree { int n; vector<int> s; void update(int pos, int val, int node, int low, int high) { if (low == high - 1) { s[node] = val; return; } int m = (low + high) / 2; if (pos < m) update(pos, val, 2 * node, low, m); else update(pos, val, 2 * node + 1, m, high); s[node] = max(s[2 * node], s[2 * node + 1]); } int query(int l, int r, int node, int low, int high) { if (r <= low || high <= l) return 0; if (l <= low && high <= r) return s[node]; int m = (low + high) / 2; return max(query(l, r, 2 * node, low, m), query(l, r, 2 * node + 1, m, high)); } public: SegTree(int n) : n(n), s(4 * n, 0) {} void update(int pos, int val) { update(pos, val, 1, 0, n); } int query(int deb, int fin) { // [deb, fin) if (deb >= fin) return 0; return query(deb, fin, 1, 0, n); } }; signed main() { int n, q; scanf("%d%d\n", &n, &q); SegTree seg(n); for (int i = 0; i < n; i++) { char chr; scanf("\n%c\n", &chr); seg.update(i, chr == '1' ? 0 : INF); } int time = 1; for (int i = 0; i < q; i++) { char str[10]; scanf("\n%s ", str); if (str[0] == 't') { int i; scanf("%d\n", &i); i--; seg.update(i, time); } else { int l, r; scanf("%d%d\n", &l, &r); int last = seg.query(l - 1, r - 1); if (last == INF) printf("0\n"); else printf("%d\n", time - last); } time++; } return 0; }

Compilation message (stderr)

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     scanf("%d%d\n", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
street_lamps.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         scanf("\n%c\n", &chr);
      |         ~~~~~^~~~~~~~~~~~~~~~
street_lamps.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         scanf("\n%s ", str);
      |         ~~~~~^~~~~~~~~~~~~~
street_lamps.cpp:71:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |             scanf("%d\n", &i);
      |             ~~~~~^~~~~~~~~~~~
street_lamps.cpp:78:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |             scanf("%d%d\n", &l, &r);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
#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...