Submission #916863

#TimeUsernameProblemLanguageResultExecution timeMemory
916863duckindogStreet Lamps (APIO19_street_lamps)C++14
40 / 100
92 ms24752 KiB
//from duckindog wth depression #include<bits/stdc++.h> using namespace std; const int N = 3e5 + 10; int n, q; int 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]; string s[N]; void sub1() { cin >> s[1]; for (int i = 1; i <= q; ++i) { s[i + 1] = s[i]; string ty; cin >> ty; if (ty == "toggle") { int p; cin >> p; s[i + 1][p - 1] = (s[i + 1][p - 1] == '0' ? '1' : '0'); } else { int a, b; cin >> a >> b; int answer = 0; for (int j = 1; j <= i; ++j) { bool pass = 1; for (int t = a - 1; t < b - 1; ++t) if (s[j][t] == '0') pass = 0; answer += pass; } cout << answer << '\n'; } } } int cnt[N], t[N]; 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; if (n <= 100 && q <= 100) { sub1(); return 0; } for (int i = 1; i <= n; ++i) { char x; cin >> x; a[i] = (x == '1'); } bool s2 = 1; 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; Q[i] = {1, x, y}; s2 &= (y - x == 1); } } if (s2) { for (int i = 1; i <= n; ++i) { t[i] = (a[i] == 1); } for (int i = 1; i <= q; ++i) { int ty = Q[i].ty, x = Q[i].x, y = Q[i].y; if (!ty) { if (a[x] == 1) { cnt[x] += i - t[x] + 1; t[x] = i + 1; } else { t[x] = i + 1; } a[x] = 1 - a[x]; } else { int answer = 0; if (a[x]) { answer = cnt[x] + i - t[x] + 1; } else { answer = cnt[x]; } cout << answer << '\n'; } } } }

Compilation message (stderr)

street_lamps.cpp: In function 'int32_t main()':
street_lamps.cpp:80:37: warning: unused variable 'y' [-Wunused-variable]
   80 |       int ty = Q[i].ty, x = Q[i].x, y = Q[i].y;
      |                                     ^
street_lamps.cpp:49:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:50:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     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...