Submission #1221913

#TimeUsernameProblemLanguageResultExecution timeMemory
1221913hoa208Street Lamps (APIO19_street_lamps)C++20
40 / 100
60 ms10716 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--) #define pa pair<ll, ll> #define fi first #define se second #define bit(mask, j) ((mask >> j) & 1) #define t_test int t;cin >> t;while(t--) const ll mod = 1e9 + 7; const ll INF = 1e18; inline void adm(ll &x){if(x>=mod)x%=mod;else if(x<0)x+=mod;} //-------------------------------------------------------------------- const ll N = 3e5 + 10; pa qr[N]; ll n, q; string s; namespace sub1 { bool check() { return n <= 100 && q <= 100; } vector<string> vt; void slove() { FOR(i, 1, q) { vt.push_back(s); if(qr[i].fi == -1) { ll id = qr[i].se - 1; s[id] = (s[id] == '1' ? '0' : '1'); } else { ll a = qr[i].fi, b = qr[i].se; ll cnt = 0; for(auto e : vt) { bool ok = true; FOR(j, a - 1, b - 2) { if(e[j] == '0') { ok = false; break; } } if(ok == true) { cnt++; } } cout << cnt << '\n'; } } } } namespace sub2 { bool check() { FOR(i, 1, q) { if(qr[i].fi == -1) continue; if(qr[i].se - qr[i].fi != 1) return false; } return true; } ll sum[N], st[N]; void slove() { FOR(i, 0, n - 1) { if(s[i] == '1') st[i] = 1; } FOR(i, 1, q) { if(qr[i].fi == -1) { ll id = qr[i].se - 1; if(s[id] == '1') { sum[id] += i - st[id] + 1; st[id] = 0; } else { st[id] = i + 1; } s[id] = (s[id] == '1' ? '0' : '1'); } else { ll a = qr[i].fi, b = qr[i].se; ll cnt = sum[a - 1]; if(st[a - 1]) { cnt += i - st[a - 1] + 1; } cout << cnt << '\n'; } } } } void hbmt() { cin >> n >> q; cin >> s; FOR(i, 1, q) { string x; cin >> x; if(x == "toggle") { ll id; cin >> id; qr[i] = {-1, id}; } else { ll a, b; cin >> a >> b; qr[i] = {a, b}; } } if(sub1::check()) return sub1::slove(); if(sub2::check()) return sub2::slove(); } int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); if(fopen("hbmt.inp", "r")) { freopen("hbmt.inp", "r", stdin); freopen("hbmt.out", "w", stdout); } // t_test hbmt(); return 0; }

Compilation message (stderr)

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen("hbmt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen("hbmt.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...