Submission #917113

#TimeUsernameProblemLanguageResultExecution timeMemory
917113duckindogStreet Lamps (APIO19_street_lamps)C++14
40 / 100
5084 ms20536 KiB
//from duckindog wth depression #include<bits/stdc++.h> using namespace std; const int N = 3e5 + 10; int n, q; bool a[N]; struct Query { int ty, x, y; Query() : ty(0), x(0), y(0) {} Query(int ty, int x, int y) : ty(ty), x(x), y(y) {} } Q[N]; int f[4 * N], cnt[N]; void build(int s, int l, int r) { if (l == r) { f[s] = (a[l] == 1 ? 0 : 1e8); return; } int mid = l + r >> 1; build(s * 2, l, mid); build(s * 2 + 1, mid + 1, r); f[s] = max(f[s * 2], f[s * 2 + 1]); } void update(int s, int l, int r, int x, int y) { if (y < l || y > r) return; if (l == r) { f[s] = x; return; } int mid = l + r >> 1; update(s * 2, l, mid, x, y); update(s * 2 + 1, mid + 1, r, x, y); f[s] = max(f[s * 2], f[s * 2 + 1]); } int query(int s, int l, int r, int u, int v) { if (v < l || u > r) return 0; if (u <= l && r <= v) return f[s]; int mid = l + r >> 1; return max(query(s * 2, l, mid, u, v), query(s * 2 + 1, mid + 1, r, u, v)); } int32_t main() { cin.tie(0)->sync_with_stdio(0); if (fopen("duck.inp", "r")) { freopen("duck.inp", "r", stdin); freopen("duck.out", "w", stdout); } cin >> n >> q; for (int i = 1; i <= n; ++i) { char x; cin >> x; a[i] = (x == '1'); } vector<pair<int, int>> querylist; for (int i = 1; i <= q; ++i) { string ty; cin >> ty; if (ty == "toggle") { int x; cin >> x; Q[i] = {0, x, 0}; } else { int x, y; cin >> x >> y; querylist.push_back({x, y - 1}); Q[i] = {1, x, y - 1}; } } sort(querylist.begin(), querylist.end()); querylist.resize(unique(querylist.begin(), querylist.end()) - querylist.begin()); build(1, 1, n); for (int i = 1; i <= q; ++i) { auto[ty, x, y] = Q[i]; if (!ty) { a[x] = 1 - a[x]; if (a[x]) { update(1, 1, n, i, x); } else { for (int j = 0; j < querylist.size(); ++j) { int l, r; tie(l, r) = querylist[j]; if (l <= x && x <= r) cnt[j] += max(0, i - query(1, 1, n, l, r)); } update(1, 1, n, 1e8, x); } } else { auto it = lower_bound(querylist.begin(), querylist.end(), make_pair(x, y)) - querylist.begin(); cout << cnt[it] + max(0, i - query(1, 1, n, x, y)) << '\n'; } } }

Compilation message (stderr)

street_lamps.cpp: In function 'void build(int, int, int)':
street_lamps.cpp:21:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |   int mid = l + r >> 1;
      |             ~~^~~
street_lamps.cpp: In function 'void update(int, int, int, int, int)':
street_lamps.cpp:31:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |   int mid = l + r >> 1;
      |             ~~^~~
street_lamps.cpp: In function 'int query(int, int, int, int, int)':
street_lamps.cpp:38:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |   int mid = l + r >> 1;
      |             ~~^~~
street_lamps.cpp: In function 'int32_t main()':
street_lamps.cpp:72:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   72 |     auto[ty, x, y] = Q[i];
      |         ^
street_lamps.cpp:79:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for (int j = 0; j < querylist.size(); ++j) {
      |                         ~~^~~~~~~~~~~~~~~~~~
street_lamps.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen("duck.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...